123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- #ifndef CHANNEL_HEADER
- #define CHANNEL_HEADER
- #include <unistd.h>
- #include "../ether/ether.h"
- #include "../tools/types.h"
- #if defined (__linux__) || defined (__APPLE__) || defined (__OpenBSD__) || defined (__NetBSD__) || defined (__FreeBSD__)
- # ifdef WINPCAP
- # error "Don't enable winpcap on Linux. It won't work."
- # endif
- # ifdef LIBPCAP
- # error "Don't enable libpcap on Linux. You don't need it."
- # endif
- #elif defined (WIN32)
- # ifndef WINPCAP
- # error "Define preprocessor constant WINPCAP on Windows."
- # endif
- # ifdef LIBPCAP
- # error "Don't enable libpcap on Windows. It won't work."
- # endif
- #elif defined (__CYGWIN__)
- # error "cygwin is unsupported!"
- #else
- # error "unknown environment"
- #endif
- #define CHANNEL_VERBOSE (1 << 0)
- #define CHANNEL_SILENCE (1 << 1)
- #define CHANNEL_WARNING (1 << 2)
- #define CHANNEL_SUCCESS (1 << 3)
- #define CHANNEL_FAILURE (1 << 4)
- #define CHANNEL_MONITOR (1 << 5)
- #define CHANNEL_UPDATE_TARGET (1 << 5)
- #define CHANNEL_UPDATE_SOURCE (1 << 6)
- #define CHANNEL_LISTEN (1 << 7)
- #define CHANNEL_ETHNUMBER 2
- #if defined (__linux__)
- # define CHANNEL_ETHDEVICE "eth1"
- #elif defined (__APPLE__)
- # define CHANNEL_ETHDEVICE "en0"
- # define CHANNEL_BPFDEVICE "/dev/bpf%d"
- #elif defined (__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__)
- # define CHANNEL_ETHDEVICE "bce0"
- # define CHANNEL_BPFDEVICE "/dev/bpf%d"
- #else
- # define CHANNEL_ETHDEVICE "nic1"
- #endif
- #define CHANNEL_FOREVER (unsigned)(-1)
- #define CHANNEL_BAILOUT 0
- #define CHANNEL_FLAGS 0
- #if defined (WIN32)
- #define CHANNEL_CAPTURE 50
- #define CHANNEL_TIMEOUT 200
- #else
- #define CHANNEL_CAPTURE 15
- #define CHANNEL_TIMEOUT 50
- #endif
- #define CHANNEL_CANTSEND "%s: Send timeout or network error", __func__
- #define CHANNEL_CANTREAD "%s: Read timeout or network error", __func__
- #if !defined (__linux__)
- # define ETH_P_802_2 1
- #endif
- typedef struct channel
- {
- signed fd;
- signed ifstate;
- signed ifindex;
- char const * ifname;
- uint8_t peer [ETHER_ADDR_LEN];
- uint8_t host [ETHER_ADDR_LEN];
- uint16_t type;
- #if defined (__linux__)
- #elif defined (__APPLE__) || defined (__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__)
- struct bpf
- {
- unsigned bpf_length;
- uint8_t * bpf_buffer;
- uint8_t * bpf_bp;
- signed bpf_bufused;
- }
- * bpf;
- #elif defined (WINPCAP) || defined (LIBPCAP)
- pcap_t * socket;
- char errbuf [PCAP_ERRBUF_SIZE];
- #else
- #error "Unknown Environment"
- #endif
- signed capture;
- signed timeout;
- flag_t flags;
- }
- CHANNEL;
- signed openchannel (struct channel *);
- signed closechannel (struct channel const *);
- ssize_t sendpacket (struct channel const *, void * memory, ssize_t extent);
- ssize_t readpacket (struct channel const *, void * memory, ssize_t extent);
- #endif
|