55#include <sys/time.h>
66#include <sys/types.h>
77
8+ #include <sys/socket.h>
9+ #include <sys/ioctl.h>
10+ #include <netinet/in.h>
11+ #include <arpa/inet.h>
12+ #include <netdb.h>
13+
814#define INVALID_SOCKET (~0)
915#define SOCKET_ERROR (-1)
1016
4147#define SO_TYPE 0x1008 /* get socket type */
4248
4349
44-
45- /*
46- * Structure used for manipulating linger option.
47- */
48- struct linger {
49- int l_onoff ; /* option on/off */
50- int l_linger ; /* linger time */
51- };
52-
5350/*
5451 * Level number for (get/set)sockopt() to apply to socket itself.
5552 */
@@ -64,17 +61,11 @@ struct linger {
6461#define IPPROTO_TCP 6
6562#define IPPROTO_UDP 17
6663
67- #define INADDR_ANY 0
68- #define INADDR_BROADCAST 0xffffffff
69-
70- /* Flags we can use with send and recv. */
71- #define MSG_DONTWAIT 0x40 /* Nonblocking i/o for this operation only */
72-
7364/*
7465 * Options for level IPPROTO_IP
7566 */
76- #define IP_TOS 1
77- #define IP_TTL 2
67+ // #define IP_TOS 1
68+ // #define IP_TTL 2
7869
7970
8071#define IPTOS_TOS_MASK 0x1E
@@ -99,48 +90,6 @@ struct linger {
9990#define IPTOS_PREC_PRIORITY 0x20
10091#define IPTOS_PREC_ROUTINE 0x00
10192
102-
103- /*
104- * Commands for ioctlsocket(), taken from the BSD file fcntl.h.
105- *
106- *
107- * Ioctl's have the command encoded in the lower word,
108- * and the size of any in or out parameters in the upper
109- * word. The high 2 bits of the upper word are used
110- * to encode the in/out status of the parameter; for now
111- * we restrict parameters to at most 128 bytes.
112- */
113- #if !defined(FIONREAD ) || !defined(FIONBIO )
114- #define IOCPARM_MASK 0x7f /* parameters must be < 128 bytes */
115- #define IOC_VOID 0x20000000 /* no parameters */
116- #define IOC_OUT 0x40000000 /* copy out parameters */
117- #define IOC_IN 0x80000000 /* copy in parameters */
118- #define IOC_INOUT (IOC_IN|IOC_OUT)
119- /* 0x20000000 distinguishes new &
120- old ioctl's */
121- #define _IO (x ,y ) (IOC_VOID|((x)<<8)|(y))
122-
123- #define _IOR (x ,y ,t ) (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
124-
125- #define _IOW (x ,y ,t ) (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
126- #endif
127-
128- #ifndef FIONREAD
129- #define FIONREAD _IOR('f', 127, unsigned long) /* get # bytes to read */
130- #endif
131- #ifndef FIONBIO
132- #define FIONBIO _IOW('f', 126, unsigned long) /* set/clear non-blocking i/o */
133- #endif
134-
135- /* Socket I/O Controls */
136- #ifndef SIOCSHIWAT
137- #define SIOCSHIWAT _IOW('s', 0, unsigned long) /* set high watermark */
138- #define SIOCGHIWAT _IOR('s', 1, unsigned long) /* get high watermark */
139- #define SIOCSLOWAT _IOW('s', 2, unsigned long) /* set low watermark */
140- #define SIOCGLOWAT _IOR('s', 3, unsigned long) /* get low watermark */
141- #define SIOCATMARK _IOR('s', 7, unsigned long) /* at oob mark? */
142- #endif
143-
14493#ifndef O_NONBLOCK
14594#define O_NONBLOCK 04000U
14695#endif
@@ -195,59 +144,17 @@ struct linger {
195144#define ip4_addr4 (ipaddr ) ((u32)(ntohl((ipaddr)->s_addr)) & 0xff)
196145#endif
197146
198- #define POLLRDNORM 0x0001
199- #define POLLRDBAND 0x0002
200- #define POLLPRI 0x0004
201- #define POLLWRNORM 0x0008
202- #define POLLWRBAND 0x0010
203- #define POLLERR 0x0020
204- #define POLLHUP 0x0040
205- #define POLLNVAL 0x0080
206- #define POLLIN (POLLRDNORM|POLLRDBAND)
207- #define POLLOUT POLLWRNORM
208-
209147#ifdef __cplusplus
210148extern "C" {
211149#endif
212150
213- #ifndef HAVE_IN_ADDR
214- #define HAVE_IN_ADDR
215- struct in_addr {
216- u32 s_addr ;
217- };
218- #endif
219-
220- struct sockaddr_in {
221- u8 sin_len ;
222- u8 sin_family ;
223- u16 sin_port ;
224- struct in_addr sin_addr ;
225- s8 sin_zero [8 ];
226- };
227-
228- struct sockaddr {
229- u8 sa_len ;
230- u8 sa_family ;
231- s8 sa_data [14 ];
232- };
233-
234- struct hostent {
235- char * h_name ; /* official name of host */
236- char * * h_aliases ; /* alias list */
237- u16 h_addrtype ; /* host address type */
238- u16 h_length ; /* length of address */
239- char * * h_addr_list ; /* list of addresses from name server */
240- };
241-
242151struct pollsd {
243152 s32 socket ;
244153 u32 events ;
245154 u32 revents ;
246155};
247156
248157u32 inet_addr (const char * cp );
249- s8 inet_aton (const char * cp , struct in_addr * addr );
250- char * inet_ntoa (struct in_addr addr ); /* returns ptr to static buffer; not reentrant! */
251158
252159s32 if_config ( char * local_ip , char * netmask , char * gateway ,bool use_dhcp , int max_retries );
253160s32 if_configex (struct in_addr * local_ip , struct in_addr * netmask , struct in_addr * gateway , bool use_dhcp , int max_retries );
0 commit comments