1 /* $NetBSD: pcap-dos.h,v 1.1.1.3 2013/04/06 15:57:50 christos Exp $ */ 2 3 /* 4 * Internal details for libpcap on DOS. 5 * 32-bit targets: djgpp, Pharlap or DOS4GW. 6 * 7 * @(#) Header: /tcpdump/master/libpcap/pcap-dos.h,v 1.1 2004-12-18 08:52:10 guy Exp (LBL) 8 */ 9 10 #ifndef __PCAP_DOS_H 11 #define __PCAP_DOS_H 12 13 #ifdef __DJGPP__ 14 #include <pc.h> /* simple non-conio kbhit */ 15 #else 16 #include <conio.h> 17 #endif 18 19 typedef int BOOL; 20 typedef unsigned char BYTE; 21 typedef unsigned short WORD; 22 typedef unsigned long DWORD; 23 typedef BYTE ETHER[6]; 24 25 #define ETH_ALEN sizeof(ETHER) /* Ether address length */ 26 #define ETH_HLEN (2*ETH_ALEN+2) /* Ether header length */ 27 #define ETH_MTU 1500 28 #define ETH_MIN 60 29 #define ETH_MAX (ETH_MTU+ETH_HLEN) 30 31 #ifndef TRUE 32 #define TRUE 1 33 #define FALSE 0 34 #endif 35 36 #define PHARLAP 1 37 #define DJGPP 2 38 #define DOS4GW 4 39 40 #ifdef __DJGPP__ 41 #undef DOSX 42 #define DOSX DJGPP 43 #endif 44 45 #ifdef __WATCOMC__ 46 #undef DOSX 47 #define DOSX DOS4GW 48 #endif 49 50 #ifdef __HIGHC__ 51 #include <pharlap.h> 52 #undef DOSX 53 #define DOSX PHARLAP 54 #define inline 55 #else 56 typedef unsigned int UINT; 57 #endif 58 59 60 #if defined(__GNUC__) || defined(__HIGHC__) 61 typedef unsigned long long uint64; 62 typedef unsigned long long QWORD; 63 #endif 64 65 #if defined(__WATCOMC__) 66 typedef unsigned __int64 uint64; 67 typedef unsigned __int64 QWORD; 68 #endif 69 70 #define ARGSUSED(x) (void) x 71 72 #if defined (__SMALL__) || defined(__LARGE__) 73 #define DOSX 0 74 75 #elif !defined(DOSX) 76 #error DOSX not defined; 1 = PharLap, 2 = djgpp, 4 = DOS4GW 77 #endif 78 79 #ifdef __HIGHC__ 80 #define min(a,b) _min(a,b) 81 #define max(a,b) _max(a,b) 82 #endif 83 84 #ifndef min 85 #define min(a,b) ((a) < (b) ? (a) : (b)) 86 #endif 87 88 #ifndef max 89 #define max(a,b) ((a) < (b) ? (b) : (a)) 90 #endif 91 92 #if !defined(_U_) && defined(__GNUC__) 93 #define _U_ __attribute__((unused)) 94 #endif 95 96 #ifndef _U_ 97 #define _U_ 98 #endif 99 100 #if defined(USE_32BIT_DRIVERS) 101 #include "msdos/pm_drvr/lock.h" 102 103 #ifndef RECEIVE_QUEUE_SIZE 104 #define RECEIVE_QUEUE_SIZE 60 105 #endif 106 107 #ifndef RECEIVE_BUF_SIZE 108 #define RECEIVE_BUF_SIZE (ETH_MAX+20) 109 #endif 110 111 extern struct device el2_dev LOCKED_VAR; /* 3Com EtherLink II */ 112 extern struct device el3_dev LOCKED_VAR; /* EtherLink III */ 113 extern struct device tc59_dev LOCKED_VAR; /* 3Com Vortex Card (?) */ 114 extern struct device tc515_dev LOCKED_VAR; 115 extern struct device tc90x_dev LOCKED_VAR; 116 extern struct device tc90bcx_dev LOCKED_VAR; 117 extern struct device wd_dev LOCKED_VAR; 118 extern struct device ne_dev LOCKED_VAR; 119 extern struct device acct_dev LOCKED_VAR; 120 extern struct device cs89_dev LOCKED_VAR; 121 extern struct device rtl8139_dev LOCKED_VAR; 122 123 struct rx_ringbuf { 124 volatile int in_index; /* queue index head */ 125 int out_index; /* queue index tail */ 126 int elem_size; /* size of each element */ 127 int num_elem; /* number of elements */ 128 char *buf_start; /* start of buffer pool */ 129 }; 130 131 struct rx_elem { 132 DWORD size; /* size copied to this element */ 133 BYTE data[ETH_MAX+10]; /* add some margin. data[0] should be */ 134 }; /* dword aligned */ 135 136 extern BYTE *get_rxbuf (int len) LOCKED_FUNC; 137 extern int peek_rxbuf (BYTE **buf); 138 extern int release_rxbuf (BYTE *buf); 139 140 #else 141 #define LOCKED_VAR 142 #define LOCKED_FUNC 143 144 struct device { 145 const char *name; 146 const char *long_name; 147 DWORD base_addr; /* device I/O address */ 148 int irq; /* device IRQ number */ 149 int dma; /* DMA channel */ 150 DWORD mem_start; /* shared mem start */ 151 DWORD mem_end; /* shared mem end */ 152 DWORD rmem_start; /* shmem "recv" start */ 153 DWORD rmem_end; /* shared "recv" end */ 154 155 struct device *next; /* next device in list */ 156 157 /* interface service routines */ 158 int (*probe)(struct device *dev); 159 int (*open) (struct device *dev); 160 void (*close)(struct device *dev); 161 int (*xmit) (struct device *dev, const void *buf, int len); 162 void *(*get_stats)(struct device *dev); 163 void (*set_multicast_list)(struct device *dev); 164 165 /* driver-to-pcap receive buffer routines */ 166 int (*copy_rx_buf) (BYTE *buf, int max); /* rx-copy (pktdrvr only) */ 167 BYTE *(*get_rx_buf) (int len); /* rx-buf fetch/enqueue */ 168 int (*peek_rx_buf) (BYTE **buf); /* rx-non-copy at queue */ 169 int (*release_rx_buf) (BYTE *buf); /* release after peek */ 170 171 WORD flags; /* Low-level status flags. */ 172 void *priv; /* private data */ 173 }; 174 175 /* 176 * Network device statistics 177 */ 178 typedef struct net_device_stats { 179 DWORD rx_packets; /* total packets received */ 180 DWORD tx_packets; /* total packets transmitted */ 181 DWORD rx_bytes; /* total bytes received */ 182 DWORD tx_bytes; /* total bytes transmitted */ 183 DWORD rx_errors; /* bad packets received */ 184 DWORD tx_errors; /* packet transmit problems */ 185 DWORD rx_dropped; /* no space in Rx buffers */ 186 DWORD tx_dropped; /* no space available for Tx */ 187 DWORD multicast; /* multicast packets received */ 188 189 /* detailed rx_errors: */ 190 DWORD rx_length_errors; 191 DWORD rx_over_errors; /* recv'r overrun error */ 192 DWORD rx_osize_errors; /* recv'r over-size error */ 193 DWORD rx_crc_errors; /* recv'd pkt with crc error */ 194 DWORD rx_frame_errors; /* recv'd frame alignment error */ 195 DWORD rx_fifo_errors; /* recv'r fifo overrun */ 196 DWORD rx_missed_errors; /* recv'r missed packet */ 197 198 /* detailed tx_errors */ 199 DWORD tx_aborted_errors; 200 DWORD tx_carrier_errors; 201 DWORD tx_fifo_errors; 202 DWORD tx_heartbeat_errors; 203 DWORD tx_window_errors; 204 DWORD tx_collisions; 205 DWORD tx_jabbers; 206 } NET_STATS; 207 #endif 208 209 extern struct device *active_dev LOCKED_VAR; 210 extern const struct device *dev_base LOCKED_VAR; 211 extern struct device *probed_dev; 212 213 extern int pcap_pkt_debug; 214 215 extern void _w32_os_yield (void); /* Watt-32's misc.c */ 216 217 #ifdef NDEBUG 218 #define PCAP_ASSERT(x) ((void)0) 219 220 #else 221 void pcap_assert (const char *what, const char *file, unsigned line); 222 223 #define PCAP_ASSERT(x) do { \ 224 if (!(x)) \ 225 pcap_assert (#x, __FILE__, __LINE__); \ 226 } while (0) 227 #endif 228 229 #endif /* __PCAP_DOS_H */ 230