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