123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- /*====================================================================*
- *
- * Copyright (c) 2013 Qualcomm Atheros, Inc.
- *
- * All rights reserved.
- *
- *====================================================================*/
- /*====================================================================*
- *
- * channel.h - raw packet channel definitions and declarations;
- *
- * the channel structure contains information needed to perform
- * ISO Layer 2, raw packet I/O in a variety of environments;
- *
- * Contributor(s):
- * Charles Maier <cmaier@qca.qualcomm.com>
- * Nathaniel Houghton <nhoughto@qca.qualcomm.com>
- *
- *--------------------------------------------------------------------*/
- #ifndef CHANNEL_HEADER
- #define CHANNEL_HEADER
- /*====================================================================*
- * system header files;
- *--------------------------------------------------------------------*/
- #include <unistd.h>
- /*====================================================================*
- * custom header files;
- *--------------------------------------------------------------------*/
- #include "../ether/ether.h"
- #include "../tools/types.h"
- /*====================================================================*
- * sort out the raw socket mess;
- *--------------------------------------------------------------------*/
- #if defined (__linux__) || defined (__APPLE__) || defined (__OpenBSD__)
- # 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
- /*====================================================================*
- * channel flagword bitmasks;
- *--------------------------------------------------------------------*/
- #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) /* used by efsu only */
- #define CHANNEL_UPDATE_SOURCE (1 << 6) /* used by efsu only */
- #define CHANNEL_LISTEN (1 << 7) /* used by efsu only */
- #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__)
- #define CHANNEL_ETHDEVICE "bce0"
- #define CHANNEL_BPFDEVICE "/dev/bpf%d"
- #else
- #define CHANNEL_ETHDEVICE "nic1"
- #endif
- #define CHANNEL1_ETHNUMBER 3
- #if defined (__linux__)
- #define CHANNEL1_ETHDEVICE "eth2"
- #elif defined (__APPLE__)
- #define CHANNEL1_ETHDEVICE "en1"
- #define CHANNEL1_BPFDEVICE "/dev/bpf%d"
- #elif defined (__OpenBSD__)
- #define CHANNEL1_ETHDEVICE "bce1"
- #define CHANNEL1_BPFDEVICE "/dev/bpf%d"
- #else
- #define CHANNEL1_ETHDEVICE "nic2"
- #endif
- #define CHANNEL_FOREVER (unsigned)(-1)
- #if defined (WIN32)
- #define CHANNEL_CAPTURE 50
- #define CHANNEL_TIMEOUT 200
- #define CHANNEL_FLAGS 0
- #else
- #define CHANNEL_CAPTURE 15
- #define CHANNEL_TIMEOUT 50
- #define CHANNEL_FLAGS 0
- #endif
- /*====================================================================*
- * common channel error messages;
- *--------------------------------------------------------------------*/
- #define CHANNEL_CANTSEND "%s: Send timeout or network error", __func__
- #define CHANNEL_CANTREAD "%s: Read timeout or network error", __func__
- /*====================================================================*
- * communication channel structure;
- *--------------------------------------------------------------------*/
- 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__)
- struct bpf
- {
- signed 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;
- /*====================================================================*
- * channel functions;
- *--------------------------------------------------------------------*/
- 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
|