Index: trunk/src/emx/include/arpa/ftp.h
===================================================================
--- trunk/src/emx/include/arpa/ftp.h	(revision 182)
+++ trunk/src/emx/include/arpa/ftp.h	(revision 183)
@@ -1,3 +1,4 @@
-/*
+/* Modified for gcc by bird 2003
+ *
  * Copyright (c) 1983, 1989 Regents of the University of California.
  * All rights reserved.
@@ -36,4 +37,5 @@
 #ifndef _FTP_H_
 #define	_FTP_H_
+#define _ARPA_FTP_H_
 
 /* Definitions for FTP; see RFC-765. */
Index: trunk/src/emx/include/arpa/inet.h
===================================================================
--- trunk/src/emx/include/arpa/inet.h	(revision 182)
+++ trunk/src/emx/include/arpa/inet.h	(revision 183)
@@ -1,3 +1,4 @@
 /* Modified for emx by hv and em 1994
+ * Modified for gcc/os2 by bird 2003
  *
  * Copyright (c) 1983 Regents of the University of California.
@@ -44,10 +45,25 @@
 
 /* External definitions for functions in inet(3) */
-extern u_long		inet_addr(__const__ char*);
-extern u_long		inet_lnaof(struct in_addr);
-extern struct in_addr	inet_makeaddr(u_long, u_long);
-extern u_long		inet_netof(struct in_addr);
-extern u_long		inet_network(__const__ char*);
-extern char*		inet_ntoa(struct in_addr);
+
+#ifndef TCPV40HDRS
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/cdefs.h>
+int             _System inet_aton (const char *, struct in_addr *);
+char *          _System inet_neta (u_long, char *, size_t);
+char *          _System inet_net_ntop (int, const void *, int, char *, size_t);
+int             _System inet_net_pton (int, const char *, void *, size_t);
+int             _System inet_pton (int af, const char *src, void *dst);
+const char *    _System inet_ntop (int af, const void *src, char *dst, size_t s);
+u_int           _System inet_nsap_addr (const char *, u_char *, int maxlen);
+char *          _System inet_nsap_ntoa (int, const u_char *, char *ascii);
+#endif
+
+extern u_long   _System inet_addr(__const__ char*);
+extern u_long	_System inet_lnaof(struct in_addr);
+extern struct in_addr _System inet_makeaddr(u_long, u_long);
+extern u_long   _System inet_netof(struct in_addr);
+extern u_long   _System inet_network(__const__ char*);
+extern char*    _System inet_ntoa(struct in_addr);
 
 #if defined (__cplusplus)
Index: trunk/src/emx/include/arpa/nameser.h
===================================================================
--- trunk/src/emx/include/arpa/nameser.h	(revision 182)
+++ trunk/src/emx/include/arpa/nameser.h	(revision 183)
@@ -1,3 +1,4 @@
 /* Modified for emx by hv 1994,1996
+ * Modified for gcc/os2 by bird 2003
  *
  * Copyright (c) 1983, 1989 Regents of the University of California.
@@ -45,4 +46,8 @@
 #include <sys/param.h>          /* htons() etc. */
 #include <machine/endian.h>	/* BYTE ORDER etc. */
+#ifndef TCPV40HDRS
+#include <types.h>
+#include <sys/cdefs.h>
+#endif
 
 /*
@@ -50,5 +55,9 @@
  */
 #define PACKETSZ	512		/* maximum packet size */
+#ifdef TCPV40HDRS
 #define MAXDNAME	256		/* maximum domain name */
+#else
+#define MAXDNAME        1025            /* maximum presentation domain name */
+#endif
 #define MAXCDNAME	255		/* maximum compressed domain name */
 #define MAXLABEL	63		/* maximum length of domain label */
@@ -57,4 +66,12 @@
 	/* number of bytes of fixed size data in resource record */
 #define RRFIXEDSZ	10
+#ifndef TCPV40HDRS
+#define HFIXEDSZ        12              /* #/bytes of fixed data in header */
+#define RRFIXEDSZ       10              /* #/bytes of fixed data in r record */
+#define INT32SZ         4               /* for systems without 32-bit ints */
+#define INT16SZ         2               /* for systems without 16-bit ints */
+#define INADDRSZ        4               /* IPv4 T_A */
+#define IN6ADDRSZ       16              /* IPv6 T_AAAA */
+#endif
 
 /*
@@ -68,7 +85,12 @@
 #define QUERY		0x0		/* standard query */
 #define IQUERY		0x1		/* inverse query */
+#ifdef TCPV40HDRS
+#define CQUERYM         2               /* completion query (multiple) */
+#define CQUERYU         3               /* completion query (unique) */
+#endif
 #define STATUS		0x2		/* nameserver status query */
 /*#define xxx		0x3		   0x3 reserved */
 	/* non standard */
+#ifdef TCPV40HDRS
 /* IBM has changed these codes in TCP/IP for OS/2 */
 #define UPDATEA		100		/* add resource record */
@@ -77,4 +99,7 @@
 #define ZONEINIT	103		/* initial zone transfer */
 #define ZONEREF		104		/* incremental zone referesh */
+#else
+#define NS_NOTIFY_OP    0x4             /* notify secondary of SOA change */
+#endif
 
 /*
@@ -88,5 +113,7 @@
 #define REFUSED		5		/* query refused */
 	/* non standard */
+#ifdef TCPV40HDRS
 #define NOCHANGE	100		/* update failed to change db */
+#endif
 
 /*
@@ -108,11 +135,37 @@
 #define T_MINFO		14		/* mailbox information */
 #define T_MX		15		/* mail routing information */
+#ifndef TCPV40HDRS
 #define T_TXT		16		/* text strings */
+#define T_RP            17              /* responsible person */
+#define T_AFSDB         18              /* AFS cell database */
+#define T_X25           19              /* X_25 calling address */
+#define T_ISDN          20              /* ISDN calling address */
+#define T_RT            21              /* router */
+#define T_NSAP          22              /* NSAP address */
+#define T_NSAP_PTR      23              /* reverse NSAP lookup (deprecated) */
+#define T_SIG           24              /* security signature */
+#define T_KEY           25              /* security key */
+#define T_PX            26              /* X.400 mail mapping */
+#define T_GPOS          27              /* geographical position (withdrawn) */
+#define T_AAAA          28              /* IP6 Address */
+#define T_LOC           29              /* Location Information */
+#define T_NXT           30              /* Next Valid Name in Zone */
+#define T_EID           31              /* Endpoint identifier */
+#define T_NIMLOC        32              /* Nimrod locator */
+#define T_SRV           33              /* Server selection */
+#define T_ATMA          34              /* ATM Address */
+#define T_NAPTR         35              /* Naming Authority PoinTeR */
+#endif
 	/* non standard */
 #define T_UINFO		100		/* user (finger) information */
 #define T_UID		101		/* user ID */
 #define T_GID		102		/* group ID */
+#ifndef TCPV40HDRS
 #define T_UNSPEC	103		/* Unspecified format (binary data) */
+#endif
 	/* Query type values which do not appear in resource records */
+#ifndef TCPV40HDRS
+#define T_IXFR          251             /* incremental zone transfer */
+#endif
 #define T_AXFR		252		/* transfer zone of authority */
 #define T_MAILB		253		/* transfer mailbox records */
@@ -125,8 +178,53 @@
 #define C_IN		1		/* the arpa internet */
 #define C_CHAOS		3		/* for chaos net at MIT */
+#ifndef TCPV40HDRS
 #define C_HS		4		/* for Hesiod name server at MIT */
+#endif
 	/* Query class values which do not appear in resource records */
 #define C_ANY		255		/* wildcard match */
 
+/*
+ * Flags field of the KEY RR rdata
+ */
+#define KEYFLAG_TYPEMASK        0xC000  /* Mask for "type" bits */
+#define KEYFLAG_TYPE_AUTH_CONF  0x0000  /* Key usable for both */
+#define KEYFLAG_TYPE_CONF_ONLY  0x8000  /* Key usable for confidentiality */
+#define KEYFLAG_TYPE_AUTH_ONLY  0x4000  /* Key usable for authentication */
+#define KEYFLAG_TYPE_NO_KEY     0xC000  /* No key usable for either; no key */
+/* The type bits can also be interpreted independently, as single bits: */
+#define KEYFLAG_NO_AUTH         0x8000  /* Key not usable for authentication */
+#define KEYFLAG_NO_CONF         0x4000  /* Key not usable for confidentiality */
+
+#define KEYFLAG_EXPERIMENTAL    0x2000  /* Security is *mandatory* if bit=0 */
+#define KEYFLAG_RESERVED3       0x1000  /* reserved - must be zero */
+#define KEYFLAG_RESERVED4       0x0800  /* reserved - must be zero */
+#define KEYFLAG_USERACCOUNT     0x0400  /* key is assoc. with a user acct */
+#define KEYFLAG_ENTITY          0x0200  /* key is assoc. with entity eg host */
+#define KEYFLAG_ZONEKEY         0x0100  /* key is zone key for the zone named */
+#define KEYFLAG_IPSEC           0x0080  /* key is for IPSEC use (host or user)*/
+#define KEYFLAG_EMAIL           0x0040  /* key is for email (MIME security) */
+#define KEYFLAG_RESERVED10      0x0020  /* reserved - must be zero */
+#define KEYFLAG_RESERVED11      0x0010  /* reserved - must be zero */
+#define KEYFLAG_SIGNATORYMASK   0x000F  /* key can sign DNS RR's of same name */
+
+#define  KEYFLAG_RESERVED_BITMASK ( KEYFLAG_RESERVED3 | \
+                                    KEYFLAG_RESERVED4 | \
+                                    KEYFLAG_RESERVED10| KEYFLAG_RESERVED11)
+
+/* The Algorithm field of the KEY and SIG RR's is an integer, {1..254} */
+#define ALGORITHM_MD5RSA        1       /* MD5 with RSA */
+#define ALGORITHM_EXPIRE_ONLY   253     /* No alg, no security */
+#define ALGORITHM_PRIVATE_OID   254     /* Key begins with OID indicating alg */
+
+/* Signatures */
+                                        /* Size of a mod or exp in bits */
+#define MIN_MD5RSA_KEY_PART_BITS         512
+#define MAX_MD5RSA_KEY_PART_BITS        2552
+                                        /* Total of binary mod and exp, bytes */
+#define MAX_MD5RSA_KEY_BYTES            ((MAX_MD5RSA_KEY_PART_BITS+7/8)*2+3)
+                                        /* Max length of text sig block */
+#define MAX_KEY_BASE64                  (((MAX_MD5RSA_KEY_BYTES+2)/3)*4)
+
+#ifndef TCPV40HDRS
 /*
  * Status return codes for T_UNSPEC conversion routines
@@ -137,11 +235,15 @@
 #define CONV_BADCKSUM -3
 #define CONV_BADBUFLEN -4
+#endif
 
 /*
  * Structure for query header, the order of the fields is machine and
- * compiler dependent, in our case, the bits within a byte are assignd 
- * least significant first, while the order of transmition is most 
+ * compiler dependent, in our case, the bits within a byte are assignd
+ * least significant first, while the order of transmition is most
  * significant first.  This requires a somewhat confusing rearrangement.
  */
+#ifndef TCPV40HDRS
+#pragma pack(1)
+#endif
 typedef struct {
 	u_short	id;		/* query identification number */
@@ -155,6 +257,12 @@
 			/* fields in fourth byte */
 	u_char	ra:1;		/* recursion available */
+#ifdef TCPV40HDRS
 	u_char	pr:1;		/* primary server required (non standard) */
 	u_char	unused:2;	/* unused bits */
+#else
+        u_char  unused :1;      /* unused bits (MBZ as of 4.9.3a3) */
+        u_char  ad: 1;          /* authentic data from named */
+        u_char  cd: 1;          /* checking disabled by resolver */
+#endif
 	u_char	rcode:4;	/* response code */
 #endif
@@ -168,6 +276,12 @@
 			/* fields in fourth byte */
 	u_char	rcode:4;	/* response code */
+#ifdef TCPV40HDRS
 	u_char	unused:2;	/* unused bits */
 	u_char	pr:1;		/* primary server required (non standard) */
+#else
+        u_char  cd: 1;          /* checking disabled by resolver */
+        u_char  ad: 1;          /* authentic data from named */
+        u_char  unused :1;      /* unused bits (MBZ as of 4.9.3a3) */
+#endif
 	u_char	ra:1;		/* recursion available */
 #endif
@@ -178,4 +292,7 @@
 	u_short	arcount;	/* number of resource entries */
 } HEADER;
+#ifndef TCPV40HDRS
+#pragma pack()
+#endif
 
 /*
@@ -184,4 +301,5 @@
 #define INDIR_MASK	0xc0
 
+#ifdef TCPV40HDRS
 /*
  * Structure for passing resource records around.
@@ -197,57 +315,67 @@
 };
 #pragma pack()
-
-/*
- * Inline versions of get/put short/long.
- * Pointer is advanced; we assume that both arguments
- * are lvalues and will already be in registers.
- * cp MUST be u_char *.
+#endif
+
+#ifndef TCPV40HDRS
+/*
+ * Inline versions of get/put short/long.  Pointer is advanced.
+ *
+ * These macros demonstrate the property of C whereby it can be
+ * portable or it can be elegant but rarely both.
  */
 #define GETSHORT(s, cp) { \
-	(s) = *(cp)++ << 8; \
-	(s) |= *(cp)++; \
+        register u_char *t_cp = (u_char *)(cp); \
+        (s) = ((u_int16_t)t_cp[0] << 8) \
+            | ((u_int16_t)t_cp[1]) \
+            ; \
+        (cp) += INT16SZ; \
 }
 
 #define GETLONG(l, cp) { \
-	(l) = *(cp)++ << 8; \
-	(l) |= *(cp)++; (l) <<= 8; \
-	(l) |= *(cp)++; (l) <<= 8; \
-	(l) |= *(cp)++; \
-}
-
+        register u_char *t_cp = (u_char *)(cp); \
+        (l) = ((u_int32_t)t_cp[0] << 24) \
+            | ((u_int32_t)t_cp[1] << 16) \
+            | ((u_int32_t)t_cp[2] << 8) \
+            | ((u_int32_t)t_cp[3]) \
+            ; \
+        (cp) += INT32SZ; \
+}
 
 #define PUTSHORT(s, cp) { \
-	*(cp)++ = (s) >> 8; \
-	*(cp)++ = (s); \
-}
-
-/*
- * Warning: PUTLONG destroys its first argument.
- */
+        register u_int16_t t_s = (u_int16_t)(s); \
+        register u_char *t_cp = (u_char *)(cp); \
+        *t_cp++ = t_s >> 8; \
+        *t_cp   = t_s; \
+        (cp) += INT16SZ; \
+}
+
 #define PUTLONG(l, cp) { \
-	(cp)[3] = l; \
-	(cp)[2] = (l >>= 8); \
-	(cp)[1] = (l >>= 8); \
-	(cp)[0] = l >> 8; \
-	(cp) += sizeof(u_long); \
-}
+        register u_int32_t t_l = (u_int32_t)(l); \
+        register u_char *t_cp = (u_char *)(cp); \
+        *t_cp++ = t_l >> 24; \
+        *t_cp++ = t_l >> 16; \
+        *t_cp++ = t_l >> 8; \
+        *t_cp   = t_l; \
+        (cp) += INT32SZ; \
+}
+#endif /*!TCPV40HDRS*/
 
 /* function prototypes */
-u_short	_getshort(u_char*);
-u_long	_getlong(u_char*);
-void	putshort(u_short, u_char *);
-void	putlong(u_long, u_char *);
-int	dn_expand(__const__ u_char*, __const__ u_char*, __const__ u_char*, 
-		  u_char*, int);
-int	dn_comp(__const__ u_char*, u_char*, int, u_char**, u_char**);
-int	dn_find(u_char*, u_char*, u_char**, u_char**);
-int	dn_skipname(__const__ u_char*, __const__ u_char*);
-int	res_init(void);
-int	res_mkquery(int, __const__ char*, int, int, __const__ char*, 
-		    int, __const__ struct rrec*, char*, int);
-int	res_send(__const__ char*, int, char*, int);
-int	res_query(char*, int, int, u_char*, int);
-int	res_search(char*, int, int, u_char*, int);
-int	res_querydomain(char*, char*, int, int, u_char*, int);
+u_short _System _getshort(u_char*);
+u_long	_System _getlong(u_char*);
+#ifdef TCPV40HDRS /* newer have this in resolver */
+void	_System putshort(u_short, u_char *);
+void	_System putlong(u_long, u_char *);
+int	_System dn_expand(__const__ u_char*, __const__ u_char*, __const__ u_char*, u_char*, int);
+int	_System dn_comp(__const__ u_char*, u_char*, int, u_char**, u_char**);
+int	_System dn_find(u_char*, u_char*, u_char**, u_char**);
+int	_System dn_skipname(__const__ u_char*, __const__ u_char*);
+int	_System res_init(void);
+int	_System res_mkquery(int, __const__ char*, int, int, __const__ char*, int, __const__ struct rrec*, char*, int);
+int	_System res_send(__const__ char*, int, char*, int);
+int	_System res_query(char*, int, int, u_char*, int);
+int	_System res_search(char*, int, int, u_char*, int);
+int	_System res_querydomain(char*, char*, int, int, u_char*, int);
+#endif
 
 #if defined (__cplusplus)
Index: trunk/src/emx/include/arpa/telnet.h
===================================================================
--- trunk/src/emx/include/arpa/telnet.h	(revision 182)
+++ trunk/src/emx/include/arpa/telnet.h	(revision 183)
@@ -1,3 +1,4 @@
-/*
+/* Modified for gcc by bird 2003
+ *
  * Copyright (c) 1983 Regents of the University of California.
  * All rights reserved.
@@ -36,4 +37,5 @@
 #ifndef _TELNET_H_
 #define	_TELNET_H_
+#define _ARPA_TELNET_H_
 
 /*
@@ -75,5 +77,5 @@
 #define	TELCMD_FIRST	xEOF
 #define	TELCMD_LAST	IAC
-#define	TELCMD_OK(x)	((x) <= TELCMD_LAST && (x) >= TELCMD_FIRST)
+#define	TELCMD_OK(x)	((unsigned int)(x) <= TELCMD_LAST && (unsigned int)(x) >= TELCMD_FIRST)
 #define	TELCMD(x)	telcmds[(x)-TELCMD_FIRST]
 
@@ -115,11 +117,12 @@
 #define TELOPT_LINEMODE	34	/* Linemode option */
 #define TELOPT_XDISPLOC	35	/* X Display Location */
-#define TELOPT_ENVIRON	36	/* Environment variables */
+#define TELOPT_OLD_ENVIRON 36	/* Old - Environment variables */
 #define	TELOPT_AUTHENTICATION 37/* Authenticate */
 #define	TELOPT_ENCRYPT	38	/* Encryption option */
+#define TELOPT_NEW_ENVIRON 39   /* New - Environment variables */
 #define	TELOPT_EXOPL	255	/* extended-options-list */
 
 
-#define	NTELOPTS	(1+TELOPT_ENCRYPT)
+#define	NTELOPTS	(1+TELOPT_NEW_ENVIRON)
 #ifdef TELOPTS
 char *telopts[NTELOPTS+1] = {
@@ -132,11 +135,11 @@
 	"TACACS UID", "OUTPUT MARKING", "TTYLOC",
 	"3270 REGIME", "X.3 PAD", "NAWS", "TSPEED", "LFLOW",
-	"LINEMODE", "XDISPLOC", "ENVIRON", "AUTHENTICATION",
-	"ENCRYPT",
+	"LINEMODE", "XDISPLOC", "OLD-ENVIRON", "AUTHENTICATION",
+	"ENCRYPT", "NEW-ENVIRON",
 	0,
 };
 #define	TELOPT_FIRST	TELOPT_BINARY
-#define	TELOPT_LAST	TELOPT_ENCRYPT
-#define	TELOPT_OK(x)	((x) <= TELOPT_LAST && (x) >= TELOPT_FIRST)
+#define	TELOPT_LAST	TELOPT_NEW_ENVIRON
+#define	TELOPT_OK(x)	((unsigned int)(x) <= TELOPT_LAST)
 #define	TELOPT(x)	telopts[(x)-TELOPT_FIRST]
 #endif
@@ -148,4 +151,9 @@
 #define	TELQUAL_REPLY	2	/* AUTHENTICATION: client version of IS */
 #define	TELQUAL_NAME	3	/* AUTHENTICATION: client version of IS */
+
+#define LFLOW_OFF               0       /* Disable remote flow control */
+#define LFLOW_ON                1       /* Enable remote flow control */
+#define LFLOW_RESTART_ANY       2       /* Restart output on any char */
+#define LFLOW_RESTART_XON       3       /* Restart output only on XON */
 
 /*
@@ -209,5 +217,5 @@
 #endif
 
-#define	SLC_NAME_OK(x)	((x) >= 0 && (x) < NSLC)
+#define	SLC_NAME_OK(x)	((unsigned int)(x) <= NSLC)
 #define SLC_NAME(x)	slc_names[x]
 
@@ -226,7 +234,10 @@
 #define	SLC_FLUSHOUT	0x20
 
-#define	ENV_VALUE	0
-#define	ENV_VAR		1
-#define	ENV_ESC		2
+#define	OLD_ENV_VALUE	0
+#define	OLD_ENV_VAR	1
+#define NEW_ENV_VAR     0
+#define NEW_ENV_VALUE   1
+#define ENV_ESC         2
+#define ENV_USERVAR     3
 
 /*
@@ -265,5 +276,5 @@
 #endif
 
-#define	AUTHTYPE_NAME_OK(x)	((x) >= 0 && (x) < AUTHTYPE_CNT)
+#define AUTHTYPE_NAME_OK(x)     ((unsigned int)(x) < AUTHTYPE_CNT)
 #define	AUTHTYPE_NAME(x)	authtype_names[x]
 
@@ -302,8 +313,8 @@
 
 
-#define	ENCRYPT_NAME_OK(x)	((x) >= 0 && (x) < ENCRYPT_CNT)
+#define	ENCRYPT_NAME_OK(x)	((unsigned int)(x) < ENCRYPT_CNT)
 #define	ENCRYPT_NAME(x)		encrypt_names[x]
 
-#define	ENCTYPE_NAME_OK(x)	((x) >= 0 && (x) < ENCTYPE_CNT)
+#define	ENCTYPE_NAME_OK(x)	((unsigned int)(x) < ENCTYPE_CNT)
 #define	ENCTYPE_NAME(x)		enctype_names[x]
 
Index: trunk/src/emx/include/net/if.h
===================================================================
--- trunk/src/emx/include/net/if.h	(revision 182)
+++ trunk/src/emx/include/net/if.h	(revision 183)
@@ -1,3 +1,4 @@
 /* Modifed for emx by hv 1994,1996
+ * Modified for gcc/os2 by bird 2003
  *
  * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
@@ -43,4 +44,9 @@
 #endif
 
+/*  XXX fast fix for SNMP, going away soon */
+#include <sys/time.h>
+
+
+#ifdef TCPV40HDRS
 /*
  * Structures defining a network interface, providing a packet
@@ -67,13 +73,4 @@
  * interfaces.  These routines live in the files if.c and route.c
  */
-/*  XXX fast fix for SNMP, going away soon */
-#include <sys/time.h>
-
-#ifdef TCPIPV4
-#pragma pack(1)
-#else
-#pragma pack(4)
-#endif
-
 
 /*
@@ -82,6 +79,7 @@
  * (Would like to call this struct ``if'', but C isn't PL/1.)
  */
-/*forward*/ struct mbuf;
-/*forward*/ struct ifaddr;
+#pragma pack(1)
+struct mbuf;
+struct ifaddr;
 struct ifnet {
 	char	*if_name;		/* name, e.g. ``en'' or ``lo'' */
@@ -95,13 +93,7 @@
 		struct	mbuf *ifq_head;
 		struct	mbuf *ifq_tail;
-#ifndef TCPIPV4
-		int	ifq_len;
-		int	ifq_maxlen;
-		int	ifq_drops;
-#else
 		short	ifq_len;
 		short	ifq_maxlen;
 		u_short	ifq_drops;
-#endif
 	} if_snd;			/* output queue */
 /* procedure handles */
@@ -112,11 +104,4 @@
 	int	(*if_watchdog)(void);	/* timer routine */
 /* generic interface statistics */
-#ifndef TCPIPV4
-	int	if_ipackets;		/* packets received on interface */
-	int	if_ierrors;		/* input errors on interface */
-	int	if_opackets;		/* packets sent on interface */
-	int	if_oerrors;		/* output errors on interface */
-	int	if_collisions;		/* collisions on csma interfaces */
-#else
 	u_short	if_ipackets;		/* packets received on interface */
 	u_short	if_ierrors;		/* input errors on interface */
@@ -124,8 +109,8 @@
 	u_short	if_oerrors;		/* output errors on interface */
 	u_short	if_collisions;		/* collisions on csma interfaces */
-#endif
 /* end statistics */
 	struct	ifnet *if_next;
 
+#ifdef __OS2__
 /* the following structures are special for OS/2 TCP/IP only */
 	u_char	if_adapternum;          /* adapter number */
@@ -134,51 +119,25 @@
 	u_long	if_speed;
 
-#define IF_RTTSCALE	1000
-	u_short	if_rtt;                 /* Est interface rtt in ms */
-	u_short	if_rttvar;              /* Est interface rttvar in ms */
-	u_short	if_rttmin;              /* Fixed interface rttmin in ms */
-	u_short	if_sendpipe;            /* Send socket buffer/window size */
-	u_short	if_recvpipe;            /* Recv socket buffer/window size */
-	u_short	if_ssthresh;            /* Gateway buffer limit (slow strt) */
-#ifdef TCPIPV4
-	u_long	if_eflags;		/* Extended flags */
-	struct ifqueue if_traceq;	/* packet trace queue */
-	u_short	if_segsize;		/* segment size for interface */
-	u_short if_use576;		/* use 576 or 1460 as def. mss if */
-					/* going through a router */
-	u_short if_rfc1469;		/* using broadcast or functional */
-					/* addr for IP Multicast */
-#define	IFF_RFC1469_BC	1		/* use broadcast */
-#define	IFF_RFC1469_FA	2		/* use functional address */
-#define	IFF_RFC1469_MA	3		/* use multicast address */
-#endif
-};
-
-#ifndef TCPIPV4
-struct ifmib {
-	int	ifNumber;		/* number of network interfaces */
-	struct iftable {
-		int	ifIndex;	/* index of this interface */
-		char	ifDescr[45];	/* description */
-		int	ifType;		/* type of the interface */
-		int	ifMtu;		/* MTU of the interface */
-		char	ifPhysAddr[6];	/* MTU of the interface */
-		int	ifOperStatus;
-		u_long	ifSpeed;
-		u_long	ifLastChange;
-		u_long	ifInOctets;
-		u_long	ifOutOctets;
-		u_long	ifOutDiscards;
-		u_long	ifInDiscards;
-		u_long	ifInErrors;
-		u_long	ifOutErrors;
-		u_long	ifInUnknownProtos;
-		u_long	ifInUcastPkts;
-		u_long	ifOutUcastPkts;
-		u_long	ifInNUcastPkts;
-		u_long	ifOutNUcastPkts;
-	} iftable[20];
-};
-#else /* TCP/IP V4 */
+        /* Interface TCP estimates/controls.  Serves the same */
+        /* purpose as the per-route values in BSD-Reno, but I didn't */
+        /* have to touch any of the route manipulation code.         */
+        u_short if_rtt;                 /* Est interface rtt in ms */
+        u_short if_rttvar;              /* Est interface rttvar in ms */
+        u_short if_rttmin;              /* Fixed interface rttmin in ms */
+        u_short if_sendpipe;            /* Send socket buffer/window size */
+        u_short if_recvpipe;            /* Recv socket buffer/window size */
+        u_short if_ssthresh;            /* Gateway buffer limit (slow strt) */
+        u_long  if_eflags;              /* Extended Flags */
+        struct ifqueue if_traceq;       /* packet trace queue */
+        u_short if_segsize;             /* segment size for interface*/
+        u_short if_use576;              /* use 576 or 1460 as def. mss if going thru a router */
+        /* Token Ring IP multicast flag */
+        u_short if_rfc1469;             /* using broadcast or functional address */
+                                        /* for IP Mulitcast */
+#define IF_RTTSCALE 1000
+#endif /* __OS2__ */
+};
+#pragma pack()
+#endif /*TCPV40HDRS*/
 
 #ifndef IFMIB_ENTRIES
@@ -186,4 +145,6 @@
 #endif
 
+#ifdef TCPV40HDRS
+#pragma pack(1)
 struct ifmib {
 	short	ifNumber;		/* number of network interfaces */
@@ -210,6 +171,45 @@
 	} iftable[IFMIB_ENTRIES];
 };
-#endif /* TCP/IP V4 */
-#pragma pack()
+#pragma pack()
+
+#else /*TCPV40HDRS*/
+
+#pragma pack(1) /* force on doubleword boundary */
+struct iftable {
+    short  iftIndex;        /* index of this interface */
+    char   iftDescr[45];    /* description             */
+    short  iftType;         /* type of the interface   */
+    short  iftMtu;          /* MTU of the interface   */
+    char   iftPhysAddr[6];  /* MTU of the interface   */
+    short  iftOperStatus;
+    u_long iftSpeed;
+    u_long iftLastChange;
+    u_long iftInOctets;
+    u_long iftOutOctets;
+    u_long iftOutDiscards;
+    u_long iftInDiscards;
+    u_long iftInErrors;
+    u_long iftOutErrors;
+    u_long iftInUnknownProtos;
+    u_long iftInUcastPkts;
+    u_long iftOutUcastPkts;
+    u_long iftInNUcastPkts;
+    u_long iftOutNUcastPkts;
+};
+struct ifmib {
+    short ifNumber;
+    struct iftable iftable[IFMIB_ENTRIES];
+};
+#pragma pack()   /* reset to default packing */
+
+#define IFC_ALLRTSBCAST    0x0001
+#define IFC_802_3          0x0002
+#define IFC_FDDI           0x0004
+#define IFC_NOREDIR        0x0010
+
+#define OPERSTATUS_UP      0x1
+#define OPERSTATUS_DOWN    0x2
+#define OPERSTATUS_TESTING 0x3
+#endif /*TCPV40HDRS*/
 
 #define	IFF_UP		0x1		/* interface is up */
@@ -219,45 +219,131 @@
 #define	IFF_POINTOPOINT	0x10		/* interface is point-to-point link */
 #define	IFF_NOTRAILERS	0x20		/* avoid use of trailers */
+#ifndef TCPV40HDRS
+#define IFF_LINK2       IFF_NOTRAILERS  /* was trailers, not used */
+#endif
 #define	IFF_RUNNING	0x40		/* resources allocated */
 #define	IFF_NOARP	0x80		/* no address resolution protocol */
-/* next two not supported now, but reserved: */
 #define	IFF_PROMISC	0x100		/* receive all packets */
 #define	IFF_ALLMULTI	0x200		/* receive all multicast packets */
-#define	IFF_OACTIVE	0x400		/* transmission in progress */
-#define	IFF_SIMPLEX	0x800		/* can't hear own transmissions */
+#define IFF_DEFMTU      0x400           /* default mtu of 1500 */
+#define IFF_MULTICAST   0x800           /* supports multicast */
+/*
+ * The IFF_MULTICAST flag indicates that the network can support the
+ * transmission and reception of higher-level (e.g., IP) multicast packets.
+ * It is independent of hardware support for multicasting; for example,
+ * point-to-point links or pure broadcast networks may well support
+ * higher-level multicasts.
+ */
 #define	IFF_BRIDGE	0x1000		/* support token ring routine field */
-#define	IFF_SNAP	0x2000		/* support extended SNAP header */
+#define	IFF_SNAP	0x2000		/* support extended SAP header */
 #define	IFF_ETHER	0x4000		/* ethernet interface */
 #define IFF_LOOPBRD	0x8000		/* ethernet interface */
+#ifndef TCPV40HDRS
+#define IFF_SIMPLEX     0x10000         /* can't hear own transmissions */
+#define IFF_OACTIVE     0x20000         /* transmission in progress */
+#define IFF_802_3       0x40000         /* */
+#define IFF_CANONICAL   0x80000         /* */
+#define IFF_RUNNINGBLK  0x100000        /* threads waited for intf running */
+#endif
+
+#define IFF_RFC1469_BC 1  /* using broadcast */
+#define IFF_RFC1469_FA 2  /* using functional address */
+#define IFF_RFC1469_MA 3  /* using mulitcast address */
 
 /*hv: flags set internally only */
-#ifdef BSD_TCPCOMPAT
+#ifdef TCPV40HDRS
+#define IFF_CANTCHANGE  (IFF_BROADCAST | IFF_POINTOPOINT | IFF_RUNNING)
+#else
 #define IFF_CANTCHANGE \
 	(IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE| \
-	IFF_SIMPLEX|IFF_MULTICAST)
-#else
-#define IFF_CANTCHANGE  (IFF_BROADCAST | IFF_POINTOPOINT | IFF_RUNNING)
-#endif
-
-#ifdef TCPIPV4
+	    IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI)
+#endif
+
 /* packet tracing extension */
 #define	IFFE_PKTTRACE	0x00000001	/* trace datalink where possible */
 #define	IFFE_IPTRACE	0x00000002	/* trace ONLY IP packets */
 
+#ifndef TCPV40HDRS
+#pragma pack(1)
+#endif
 struct pkt_trace_hdr {
 	u_short		pt_htype;	/* header type */
-#define		HT_IP		0x01	/* 	IP */
-#define		HT_ETHER	0x06	/* 	Ethernet */
-#define		HT_ISO88023	0x07	/* 	CSMA CD */
-#define		HT_ISO88025	0x09	/* 	Token Ring */
-#define		HT_SLIP		0x1c	/* 	Serial Line IP */
-#define		HT_PPP		0x18	/* 	PPP IP */
 	u_short		pt_len;		/* in: pt_buf len, out: packet len */
 	caddr_t		pt_data;	/* packet ATTN: This is a _Seg16 addr! */
 	u_long		pt_tstamp;	/* time stamp in milliseconds */
 };
-
-#endif /* TCP/IP V4 */
-
+#ifndef TCPV40HDRS
+#pragma pack()
+#endif
+#define	HT_IP           0x01 /* IP */
+#define	HT_ETHER        0x06 /* Ethernet */
+#define	HT_ISO88023     0x07 /* CSMA CD */
+#define	HT_ISO88025     0x09 /* Token Ring */
+#define	HT_SLIP         0x1c /* Serial Line IP */
+#define	HT_PPP          0x18 /* PPP IP */
+
+#ifndef TCPV40HDRS
+/* genric interface information */
+#pragma pack(1)
+struct  if_data {
+                u_char  ifi_type;       /* ethernet, tokenring, etc */
+                u_char  ifi_addrlen;    /* media address length */
+                u_char  ifi_hdrlen;     /* media header length */
+                u_long  ifi_mtu;        /* maximum transmission unit */
+                u_long  ifi_metric;     /* routing metric (external only) */
+                u_long  ifi_baudrate;   /* linespeed */
+                                        /* volatile statistics */
+                u_long  ifi_collisions; /* collisions on csma interfaces */
+                u_long  ifi_ibytes;     /* total number of octets received */
+                u_long  ifi_obytes;     /* total number of octets sent */
+                u_long  ifi_oqdrops;    /* dropped on output, this interface */
+                u_long  ifi_iqdrops;    /* dropped on input, this interface */
+                u_long  ifi_ierrors;    /* input errors on interface */
+                u_long  ifi_oerrors;    /* output errors on interface */
+                u_long  ifi_noproto;    /* destined for unsupported protocol */
+                u_long  ifi_ipackets;   /* packets received on interface */
+                u_long  ifi_opackets;   /* packets sent on interface */
+                u_long  ifi_imcasts;    /* packets received via multicast */
+                u_long  ifi_omcasts;    /* packets sent via multicast */
+                short   ifi_OperStatus; /* SNMP Oper Status */
+                struct  timeval ifi_lastchange;/* last updated */
+                u_char  ifi_descr[45];  /* description of the interface */
+};
+#pragma pack()
+
+/*
+ * Message format for use in obtaining information about interfaces
+ * from getkerninfo and the routing socket
+ */
+#pragma pack(1)
+struct if_msghdr {
+        u_short ifm_msglen;     /* to skip over non-understood messages */
+        u_char  ifm_version;    /* future binary compatability */
+        u_char  ifm_type;       /* message type */
+        int     ifm_addrs;      /* like rtm_addrs */
+        int     ifm_flags;      /* value of if_flags */
+        u_short ifm_index;      /* index for associated ifp */
+        struct  if_data ifm_data;/* statistics and other data about if */
+};
+#pragma pack()
+
+/*
+ * Message format for use in obtaining information about interface addresses
+ * from getkerninfo and the routing socket
+ */
+#pragma pack(1)
+struct ifa_msghdr {
+        u_short ifam_msglen;    /* to skip over non-understood messages */
+        u_char  ifam_version;   /* future binary compatability */
+        u_char  ifam_type;      /* message type */
+        int     ifam_addrs;     /* like rtm_addrs */
+        int     ifam_flags;     /* value of ifa_flags */
+        u_short ifam_index;     /* index for associated ifp */
+        int     ifam_metric;    /* value of ifa_metric */
+};
+#pragma pack()
+#endif /*!TCPV40HDRS*/
+
+#ifdef TCPV40HDRS
 /*
  * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
@@ -284,13 +370,10 @@
 	(ifq)->ifq_len++;\
 }
-#define	IF_DEQUEUE(ifq, m) {\
-	(m)=(ifq)->ifq_head;\
-	if (m) {\
-		if (((ifq)->ifq_head=(m)->m_act)==0)\
-			(ifq)->ifq_tail=0;\
-		(m)->m_act=0;\
-		(ifq)->ifq_len--;\
-	}\
-}
+/*
+ * Packets destined for level-1 protocol input routines
+ * have a pointer to the receiving interface prepended to the data.
+ * IF_DEQUEUEIF extracts and returns this pointer when dequeueing the packet.
+ * IF_ADJ should be used otherwise to adjust for its presence.
+ */
 #define IF_ADJ(m) {\
 	(m)->m_off+=sizeof(struct ifnet*);\
@@ -313,4 +396,13 @@
         }\
 }
+#define	IF_DEQUEUE(ifq, m) {\
+	(m)=(ifq)->ifq_head;\
+	if (m) {\
+		if (((ifq)->ifq_head=(m)->m_act)==0)\
+			(ifq)->ifq_tail=0;\
+		(m)->m_act=0;\
+		(ifq)->ifq_len--;\
+	}\
+}
 
 #define	IFQ_MAXLEN	50
@@ -334,4 +426,5 @@
 	struct ifaddr	*ifa_next;		/* next address for interface */
 };
+#endif /*TCPV40HDRS*/
 
 /*
@@ -341,4 +434,7 @@
  * remainder may be interface specific.
  */
+#ifndef TCPV40HDRS
+#pragma pack(1)
+#endif
 struct	ifreq {
 #define	IFNAMSIZ	16
@@ -358,5 +454,22 @@
 #define	ifr_metric	ifr_ifru.ifru_metric	/* metric */
 #define	ifr_data	ifr_ifru.ifru_data	/* for use by interface */
-};
+#ifndef TCPV40HDRS
+#define ifr_eflags      ifr_ifru.ifru_data      /* Extended flags */
+#endif
+};
+#ifndef TCPV40HDRS
+#pragma pack()
+#endif
+
+#ifndef TCPV40HDRS
+#pragma pack(1)
+struct ifaliasreq {
+  char    ifra_name[IFNAMSIZ];            /* if name, e.g. "en0" */
+  struct  sockaddr ifra_addr;
+  struct  sockaddr ifra_broadaddr;
+  struct  sockaddr ifra_mask;
+};
+#pragma pack()
+#endif
 
 /*
@@ -366,4 +479,7 @@
  * must know all networks accessible).
  */
+#ifndef TCPV40HDRS
+#pragma pack(1) /* paranoia I believe */
+#endif
 struct	ifconf {
 	int	ifc_len;		/* size of associated buffer */
@@ -375,4 +491,7 @@
 #define	ifc_req	ifc_ifcu.ifcu_req	/* array of structures returned */
 };
+#ifndef TCPV40HDRS
+#pragma pack()
+#endif
 
 #include <net/if_arp.h>
@@ -382,3 +501,50 @@
 #endif
 
+#ifndef TCPV40HDRS
+#include <netinet/in.h>
+
+#pragma pack(1)
+struct  in_aliasreq {
+        char    ifra_name[IFNAMSIZ];            /* if name, e.g. "en0" */
+        struct  sockaddr_in ifra_addr;
+        struct  sockaddr_in ifra_broadaddr;
+#define ifra_dstaddr ifra_broadaddr
+        struct  sockaddr_in ifra_mask;
+};
+#pragma pack()
+
+#pragma pack(1)
+struct  addrreq  {                              /* get multicast addresses */
+        char    ifr_name[IFNAMSIZ];
+        struct  sockaddr ifr_addrs;
+        u_long  maddr[MAX_IN_MULTI];
+};
+#pragma pack()
+
+#pragma pack(1)
+struct  statatreq {
+        u_long addr;
+        short interface;
+        u_long mask;
+        u_long broadcast;
+};
+#pragma pack()
+
+/* PPP statistics table. Moved here from previous ifstat.h */
+struct ifstat {
+    u_long iftLastChange;
+    u_long iftInOctets;
+    u_long iftOutOctets;
+    u_long iftOutDiscards;
+    u_long iftInDiscards;
+    u_long iftInErrors;
+    u_long iftOutErrors;
+    u_long iftInUnknownProtos;
+    u_long iftInUcastPkts;
+    u_long iftOutUcastPkts;
+    u_long iftInNUcastPkts;
+    u_long iftOutNUcastPkts;
+};
+#endif /*!TCPV40HDRS*/
+
 #endif /* _NET_IF_H_ */
Index: trunk/src/emx/include/net/if_arp.h
===================================================================
--- trunk/src/emx/include/net/if_arp.h	(revision 182)
+++ trunk/src/emx/include/net/if_arp.h	(revision 183)
@@ -1,3 +1,4 @@
 /* Modified for emx by hv 1994,1996
+ * Modified for gcc/os2 by bird 2003
  *
  * Copyright (c) 1986 Regents of the University of California.
@@ -49,8 +50,14 @@
  * specified.  Field names used correspond to RFC 826.
  */
+#ifndef TCPV40HDR
+#pragma pack(1)
+#endif
 struct	arphdr {
 	u_short	ar_hrd;		/* format of hardware address */
 #define ARPHRD_ETHER 	1	/* ethernet hardware address */
 #define ARPHRD_802	6	/* 802 net hardware address */
+#ifndef TCPV40HDRS
+#define ARPHRD_FRELAY   15      /* frame relay hardware format */
+#endif
 	u_short	ar_pro;		/* format of protocol address */
 	u_char	ar_hln;		/* length of hardware address */
@@ -59,6 +66,14 @@
 #define	ARPOP_REQUEST	1	/* request to resolve address */
 #define	ARPOP_REPLY	2	/* response to previous request */
+#ifndef TCPV40HDRS
+#define ARPOP_REVREQUEST 3      /* request protocol address given hardware */
+#define ARPOP_REVREPLY   4      /* response giving protocol address */
+#define ARPOP_INVREQUEST 8      /* request to identify peer */
+#define ARPOP_INVREPLY   9      /* response identifying peer */
+#endif
+#if 0 /* not OS/2 */
 #define REVARP_REQUEST	3	/* reverse ARP request (not IBM) */
 #define REVARP_REPLY	4	/* reverse ARP reply (not IBM) */
+#endif
 /*
  * The remaining fields are variable in size,
@@ -70,8 +85,14 @@
 /*	u_char	ar_tpa[];	 * target protocol address */
 };
+#ifndef TCPV40HDRS
+#pragma pack()
+#endif
 
 /*
  * ARP ioctl request
  */
+#ifndef TCPV40HDRS
+#pragma pack(4)
+#endif
 struct arpreq {
 	struct	sockaddr arp_pa;		/* protocol address */
@@ -79,4 +100,23 @@
 	int	arp_flags;			/* flags */
 };
+#ifndef TCPV40HDRS
+#pragma pack()
+#endif
+
+#ifndef TCPV40HDRS
+/*
+ * Token ring ARP ioctl request
+ */
+#pragma pack(4)
+struct arpreq_tr {
+        struct  sockaddr arp_pa;                /* protocol address */
+        struct  sockaddr arp_ha;                /* hardware address */
+        long    arp_flags;                     /* flags */
+        u_short arp_rcf;                        /* token ring routing control field */
+        u_short arp_rseg[8];                    /* token ring routing segments */
+};
+#endif /*!TCPV40HDRS*/
+
+
 /*  arp_flags and at_flags field values */
 #define	ATF_INUSE	0x01	/* entry in use */
@@ -85,4 +125,7 @@
 #define	ATF_PUBL	0x08	/* publish entry (respond for other host) */
 #define	ATF_USETRAILERS	0x10	/* has requested trailers */
+#ifndef TCPV40HDRS
+#define ATF_802_3       0x20    /* sender's ether if set to 802.3 */
+#endif
 
 #endif /* !_NET_IF_ARP_H_ */
Index: trunk/src/emx/include/net/route.h
===================================================================
--- trunk/src/emx/include/net/route.h	(revision 182)
+++ trunk/src/emx/include/net/route.h	(revision 183)
@@ -1,4 +1,5 @@
 /* Modified for emx by hv and em 1994,1996
- * 
+ * Modified for gcc/os2 by bird 2003
+ *
  * Copyright (c) 1980, 1986 Regents of the University of California.
  * All rights reserved.
@@ -47,5 +48,5 @@
 /*
  * Kernel resident routing tables.
- * 
+ *
  * The routing tables are initialized when interface addresses
  * are set by making entries for all directly connected interfaces.
@@ -62,4 +63,24 @@
 };
 
+
+#ifndef TCPV40HDRS
+/*
+ * These numbers are used by reliable protocols for determining
+ * retransmission behavior and are included in the routing structure.
+ */
+struct rt_metrics {
+        u_long  rmx_locks;      /* Kernel must leave these values alone */
+        u_long  rmx_mtu;        /* MTU for this path */
+        u_long  rmx_hopcount;   /* max hops expected */
+        u_long  rmx_expire;     /* lifetime for route, e.g. redirect */
+        u_long  rmx_recvpipe;   /* inbound delay-bandwith product */
+        u_long  rmx_sendpipe;   /* outbound delay-bandwith product */
+        u_long  rmx_ssthresh;   /* outbound gateway buffer limit */
+        u_long  rmx_rtt;        /* estimated round trip time */
+        u_long  rmx_rttvar;     /* estimated rtt variance */
+        u_long  rmx_pksent;     /* packets sent using this route */
+        u_long  rmx_filler[4];  /* will be used for T/TCP later */
+};
+
 /*
  * rmx_rtt and rmx_rttvar are stored as microseconds;
@@ -69,4 +90,6 @@
 #define	RTM_RTTUNIT	1000000	/* units for rtt, rttvar, as units per sec */
 #define	RTTTOPRHZ(r)	((r) / (RTM_RTTUNIT / PR_SLOWHZ))
+#endif /* !TCPV40HDRS */
+
 
 /*
@@ -80,5 +103,11 @@
  * Following structure necessary for 4.3 compatibility;
  */
-struct rtentry {
+#pragma pack(1)
+#ifdef TCPV40HDRS
+struct rtentry
+#else
+struct ortentry
+#endif
+{
 	u_long	rt_hash;		/* to speed lookups */
 	struct	sockaddr rt_dst;	/* key */
@@ -90,6 +119,24 @@
 	long metric1,metric2,metric3,metric4; /*IBM special */
 };
-
-#define	RTF_UP		0x1		/* route useable */
+#pragma pack()
+
+/* IBM: hv: I think this is the internal structure of the RT table of the
+ * router daemon. Don't think it belongs here, but the toolkit has it as well
+ */
+#define RTENTRY_COUNT	512
+#pragma pack(1)
+struct rtentries {
+	short	hostcount;
+	short	netcount;
+        #ifdef TCPV40HDRS
+        struct rtentry  rttable[RTENTRY_COUNT];
+        #else
+        struct ortentry rttable[RTENTRY_COUNT];
+        #endif
+};
+#pragma pack()
+
+
+#define	RTF_UP		0x1		/* route usable */
 #define	RTF_GATEWAY	0x2		/* destination is a gateway */
 #define	RTF_HOST	0x4		/* host entry (net otherwise) */
@@ -104,6 +151,19 @@
 #define	RTF_STATIC	0x800		/* route manually added */
 #define	RTF_BLACKHOLE	0x1000		/* discard packets during updates */
+#ifndef TCPV40HDRS
+#define RTF_LLTEMP      0x2000          /* manually added temporary arp entry */
+#endif
 #define RTF_PROTO2	0x4000		/* protocol specific routing flag */
 #define RTF_PROTO1	0x8000		/* protocol specific routing flag */
+#ifndef TCPV40HDRS
+#define RTF_PRCLONING   0x10000         /* protocol requires cloning */
+#define RTF_WASCLONED   0x20000         /* route generated through cloning */
+#define RTF_PROTO3      0x40000         /* protocol specific routing flag */
+#define RTF_CHAINDELETE 0x80000         /* chain is being deleted (internal) */
+#define RTF_PINNED      0x100000        /* future use */
+#define RTF_TUNNEL      0x200000        /* tunnelling bit */
+#define RTF_CRYPT       0x400000        /* encrypting tunnel */
+#define RTF_AUTH        0x800000        /* authenticating tunnel */
+#endif
 
 
@@ -118,70 +178,92 @@
 	short	rts_wildcard;		/* lookups satisfied by a wildcard */
 };
+#ifndef TCPV40HDRS
 /*
  * Structures for routing messages.
  */
-#ifndef __EMX__
+#pragma pack(1)
 struct rt_msghdr {
-	u_short	rtm_msglen;	/* to skip over non-understood messages */
-	u_char	rtm_version;	/* future binary compatability */
-	u_char	rtm_type;	/* message type */
-	u_short	rtm_index;	/* index for associated ifp */
-	pid_t	rtm_pid;	/* identify sender */
-	int	rtm_addrs;	/* bitmask identifying sockaddrs in msg */
-	int	rtm_seq;	/* for sender to identify action */
-	int	rtm_errno;	/* why failed */
-	int	rtm_flags;	/* flags, incl. kern & message, e.g. DONE */
-	int	rtm_use;	/* from rtentry */
-	u_long	rtm_inits;	/* which metrics we are initializing */
-	struct	rt_metrics rtm_rmx; /* metrics themselves */
+#define IFNAMSIZ        16
+        u_short rtm_msglen;     /* to skip over non-understood messages */
+        u_char  rtm_version;    /* future binary compatibility */
+        u_char  rtm_type;       /* message type */
+        u_short rtm_index;      /* index for associated ifp */
+        short   rtm_unit;       /* new field for subnet routing */
+        int     rtm_flags;      /* flags, incl. kern & message, e.g. DONE */
+        int     rtm_addrs;      /* bitmask identifying sockaddrs in msg */
+        pid_t   rtm_pid;        /* identify sender */
+        int     rtm_seq;        /* for sender to identify action */
+        int     rtm_errno;      /* why failed */
+        int     rtm_use;        /* from rtentry */
+        u_long  rtm_inits;      /* which metrics we are initializing */
+        u_long  rtm_netmask;    /* new field for subnet routing */
+        char    rtm_name[IFNAMSIZ]; /* new field for subnet routing */
+        struct  rt_metrics rtm_rmx; /* metrics themselves */
+};
+#pragma pack()
+
+#define RTM_VERSION     4       /* Up the ante and ignore older versions */
+
+#define RTM_ADD         0x1     /* Add Route */
+#define RTM_DELETE      0x2     /* Delete Route */
+#define RTM_CHANGE      0x3     /* Change Metrics or flags */
+#define RTM_GET         0x4     /* Report Metrics */
+#define RTM_LOSING      0x5     /* Kernel Suspects Partitioning */
+#define RTM_REDIRECT    0x6     /* Told to use different route */
+#define RTM_MISS        0x7     /* Lookup failed on this address */
+#define RTM_LOCK        0x8     /* fix specified metrics */
+#define RTM_OLDADD      0x9     /* caused by SIOCADDRT */
+#define RTM_OLDDEL      0xa     /* caused by SIOCDELRT */
+#define RTM_RESOLVE     0xb     /* req to resolve dst to LL addr */
+#define RTM_NEWADDR     0xc     /* address being added to iface */
+#define RTM_DELADDR     0xd     /* address being removed from iface */
+#define RTM_IFINFO      0xe     /* iface going up/down etc. */
+
+#define RTV_MTU         0x1     /* init or lock _mtu */
+#define RTV_HOPCOUNT    0x2     /* init or lock _hopcount */
+#define RTV_EXPIRE      0x4     /* init or lock _hopcount */
+#define RTV_RPIPE       0x8     /* init or lock _recvpipe */
+#define RTV_SPIPE       0x10    /* init or lock _sendpipe */
+#define RTV_SSTHRESH    0x20    /* init or lock _ssthresh */
+#define RTV_RTT         0x40    /* init or lock _rtt */
+#define RTV_RTTVAR      0x80    /* init or lock _rttvar */
+
+/*
+ * Bitmask values for rtm_addr.
+ */
+#define RTA_DST         0x1     /* destination sockaddr present */
+#define RTA_GATEWAY     0x2     /* gateway sockaddr present */
+#define RTA_NETMASK     0x4     /* netmask sockaddr present */
+#define RTA_GENMASK     0x8     /* cloning mask sockaddr present */
+#define RTA_IFP         0x10    /* interface name sockaddr present */
+#define RTA_IFA         0x20    /* interface addr sockaddr present */
+#define RTA_AUTHOR      0x40    /* sockaddr for author of redirect */
+#define RTA_BRD         0x80    /* for NEWADDR, broadcast or p-p dest addr */
+
+/*
+ * Index offsets for sockaddr array for alternate internal encoding.
+ */
+#define RTAX_DST        0       /* destination sockaddr present */
+#define RTAX_GATEWAY    1       /* gateway sockaddr present */
+#define RTAX_NETMASK    2       /* netmask sockaddr present */
+#define RTAX_GENMASK    3       /* cloning mask sockaddr present */
+#define RTAX_IFP        4       /* interface name sockaddr present */
+#define RTAX_IFA        5       /* interface addr sockaddr present */
+#define RTAX_AUTHOR     6       /* sockaddr for author of redirect */
+#define RTAX_BRD        7       /* for NEWADDR, broadcast or p-p dest addr */
+#define RTAX_MAX        8       /* size of array to allocate */
+
+struct rt_addrinfo {
+        int     rti_addrs;
+        struct  sockaddr *rti_info[RTAX_MAX];
 };
 
 struct route_cb {
-	int	ip_count;
-	int	ns_count;
-	int	iso_count;
-	int	any_count;
-};
-#define RTM_VERSION	2	/* Up the ante and ignore older versions */
-
-#define RTM_ADD		0x1	/* Add Route */
-#define RTM_DELETE	0x2	/* Delete Route */
-#define RTM_CHANGE	0x3	/* Change Metrics or flags */
-#define RTM_GET		0x4	/* Report Metrics */
-#define RTM_LOSING	0x5	/* Kernel Suspects Partitioning */
-#define RTM_REDIRECT	0x6	/* Told to use different route */
-#define RTM_MISS	0x7	/* Lookup failed on this address */
-#define RTM_LOCK	0x8	/* fix specified metrics */
-#define RTM_OLDADD	0x9	/* caused by SIOCADDRT */
-#define RTM_OLDDEL	0xa	/* caused by SIOCDELRT */
-#define RTM_RESOLVE	0xb	/* req to resolve dst to LL addr */
-
-#define RTV_MTU		0x1	/* init or lock _mtu */
-#define RTV_HOPCOUNT	0x2	/* init or lock _hopcount */
-#define RTV_EXPIRE	0x4	/* init or lock _hopcount */
-#define RTV_RPIPE	0x8	/* init or lock _recvpipe */
-#define RTV_SPIPE	0x10	/* init or lock _sendpipe */
-#define RTV_SSTHRESH	0x20	/* init or lock _ssthresh */
-#define RTV_RTT		0x40	/* init or lock _rtt */
-#define RTV_RTTVAR	0x80	/* init or lock _rttvar */
-
-#define RTA_DST		0x1	/* destination sockaddr present */
-#define RTA_GATEWAY	0x2	/* gateway sockaddr present */
-#define RTA_NETMASK	0x4	/* netmask sockaddr present */
-#define RTA_GENMASK	0x8	/* cloning mask sockaddr present */
-#define RTA_IFP		0x10	/* interface name sockaddr present */
-#define RTA_IFA		0x20	/* interface addr sockaddr present */
-#define RTA_AUTHOR	0x40	/* sockaddr for author of redirect */
-#endif
-
-/* IBM: hv: I think this is the internal structure of the RT table of the
- * router daemon. Don't think it belongs here, but the toolkit has it as well
- */
-#define RTENTRY_COUNT	512
-struct rtentries {
-	short	hostcount;
-	short	netcount;
-	struct rtentry rttable[RTENTRY_COUNT];
-};
+        int     ip_count;
+        int     ns_count;
+        int     iso_count;
+        int     any_count;
+};
+#endif /* !TCPV40HDRS */
 
 #if defined (__cplusplus)
Index: trunk/src/emx/include/netdb.h
===================================================================
--- trunk/src/emx/include/netdb.h	(revision 182)
+++ trunk/src/emx/include/netdb.h	(revision 183)
@@ -1,3 +1,4 @@
 /*- Modified for emx by hv and em 1994-1997
+ *- Modified for gcc by bird 2003
  *
  * Copyright (c) 1980, 1983, 1988 Regents of the University of California.
@@ -33,13 +34,21 @@
  *
  *	from: @(#)netdb.h	5.15 (Berkeley) 4/3/91
- *	netdb.h,v 1.1 2003/04/16 15:53:07 bird Exp
+ *	netdb.h,v 1.2 2003/05/19 02:41:00 bird Exp
  */
 
 #ifndef _NETDB_H_
 #define _NETDB_H_
+#ifdef TCPV40HDRS
+#define __NETDB_32H
+#endif
 
 #if defined (__cplusplus)
 extern "C" {
 #endif
+
+/* toolkit compatibility - start */
+#include <sys/param.h>
+#include <sys/cdefs.h>
+/* toolkit compatibility - end */
 
 #ifndef _EMX_TCPIP
@@ -54,11 +63,16 @@
 #endif
 
-extern int h_errno;
-
-#define	_PATH_HEQUIV	"/tcpip/etc/hosts.equiv"
-#define	_PATH_HOSTS	"/tcpip/etc/hosts"
-#define	_PATH_NETWORKS	"/tcpip/etc/networks"
-#define	_PATH_PROTOCOLS	"/tcpip/etc/protocols"
-#define	_PATH_SERVICES	"/tcpip/etc/services"
+
+#define	_PATH_HEQUIV	"/mptn/etc/hosts.equiv"
+#define	_PATH_HOSTS	"/mptn/etc/hosts"
+#define	_PATH_NETWORKS	"/mptn/etc/networks"
+#define	_PATH_PROTOCOLS	"/mptn/etc/protocols"
+#define	_PATH_SERVICES	"/mptn/etc/services"
+
+#ifdef TCPV40HDRS
+#define h_errno         (tcp_h_errno())   /* __MT__ safe */
+#else
+#define h_errno         (*tcp_h_errno1()) /* __MT__ safe */
+#endif
 
 /*
@@ -104,6 +118,7 @@
  * (left in extern int h_errno).
  */
-#if 0
-#define h_errno (tcp_h_errno())	/* thread safe */
+#ifndef TCPV40HDRS
+#define NETDB_INTERNAL  -1      /* see errno */
+#define NETDB_SUCCESS   0       /* no problem */
 #endif
 #define	HOST_NOT_FOUND	1 /* Authoritative Answer Host not found */
@@ -113,28 +128,9 @@
 #define	NO_ADDRESS	NO_DATA		/* no address, look for MX record */
 
-int		gethostname (char *, int);
-void		endhostent (void);
-void		endnetent (void);
-void		endprotoent (void);
-void		endservent (void);
-struct hostent	*gethostbyaddr (__const__ char *, int, int);
-struct hostent	*gethostbyname (__const__ char *);
-struct hostent	*gethostent (void);
-struct netent	*getnetbyaddr (u_long, int);
-struct netent	*getnetbyname (__const__ char *);
-struct netent	*getnetent (void);
-struct protoent	*getprotobyname (__const__ char *);
-struct protoent	*getprotobynumber (int);
-struct protoent	*getprotoent (void);
-struct servent	*getservbyname (__const__ char *, __const__ char *);
-struct servent	*getservbyport (int, __const__ char *);
-struct servent	*getservent (void);
-void		herror (__const__ char *);
-void		sethostent (int);
-void		setnetent (int);
-void		setprotoent (int);
-void		setservent (int);
-
-#ifdef NETDB_IBM_ADDENDUM
+
+#ifdef TCPV40HDRS
+#include <stdio.h>
+#include <string.h>
+#include <netinet\in.h>
 
 /* IBM addendum structures and functions */
@@ -144,5 +140,5 @@
 #define	_MAXLINELEN	1024
 
-/* this is the internally used data structure to which pointers of 
+/* this is the internally used data structure to which pointers of
  * struct hostent ponit to, after gethostbyname_r/gethostbyaddr_r were
  * called. ATTENTION EMX: The component _opaque_ is a pointer to a data
@@ -159,5 +155,5 @@
 	int	stayopen;			/* AIX addon */
 	u_long	host_addresses[_MAXADDRS];	/* Actual Addresses. */
-};                                              
+};
 
 struct servent_data {
@@ -167,13 +163,59 @@
 	int	_serv_stayopen;
 };
-
-int gethostbyname_r(char*, struct hostent*, struct hostent_data*);
-int gethostbyaddr_r(char*, int, int, struct hostent*, struct hostent_data*);
-int getservbyname_r(char*, char*, struct servent*, struct servent_data*);
-struct hostent *_gethtbyname(char*);
-struct hostent *_gethtbyaddr(char*, int, int);
-int tcp_h_errno(void);	/* thread safe h_errno */
-
-#endif /* NETDB_IBM_ADDENDUM */
+#endif
+
+
+/* BSD */
+int                 _System gethostname( char *, int );
+struct hostent *    _System gethostbyname( __const__ char * );
+struct hostent *    _System gethostbyaddr( __const__ char *, int, int );
+struct netent *     _System getnetbyname( __const__ char * );
+struct netent *     _System getnetbyaddr( unsigned long, int );
+struct servent *    _System getservbyname( __const__ char *, char * );
+struct servent *    _System getservbyport( int, __const__ char * );
+struct servent *    _System getservent( void );
+struct protoent *   _System getprotobyname( __const__ char * );
+struct protoent *   _System getprotobynumber( int );
+void                _System sethostent( int );
+struct hostent *    _System gethostent( void );
+void                _System endhostent(void);
+void                _System setnetent( int );
+struct netent *     _System getnetent( void );
+void                _System endnetent(void);
+void                _System setprotoent( int );
+struct protoent *   _System getprotoent( void );
+void                _System endprotoent(void);
+void                _System setservent( int );
+struct servent *    _System getservent( void );
+void                _System endservent(void);
+#ifndef TCPV40HDRS
+struct hostent *    _System gethostbyname2( __const__ char *, int );
+#endif
+
+
+/* OS2 Additions */
+#ifdef TCPV40HDRS
+int                 _System tcp_h_errno(void);
+struct hostent *    _System Rgethostbyname(char *); /* Socks additions */
+#else
+const char *        _System hstrerror(int);
+/* void               _System sethostfile(const char *); */
+int *               _System tcp_h_errno1(void);
+#endif
+
+/* EMX/BSD additions. */
+void		    herror (__const__ char *);
+
+/* EMX/BSD stuff which isn't implemeneted  */
+#ifndef TCPV40HDRS
+struct hostent_data;
+struct servent_data;
+#endif
+int                 gethostbyname_r(char*, struct hostent*, struct hostent_data*);
+int                 gethostbyaddr_r(char*, int, int, struct hostent*, struct hostent_data*);
+int                 getservbyname_r(char*, char*, struct servent*, struct servent_data*);
+struct hostent *    _gethtbyname(char*);
+struct hostent *    _gethtbyaddr(char*, int, int);
+
 
 #ifdef __RSXNT__
@@ -187,2 +229,3 @@
 
 #endif /* !_NETDB_H_ */
+
Index: trunk/src/emx/include/netinet/icmp_var.h
===================================================================
--- trunk/src/emx/include/netinet/icmp_var.h	(revision 182)
+++ trunk/src/emx/include/netinet/icmp_var.h	(revision 183)
@@ -1,3 +1,4 @@
-/*
+/* Modified for gcc/os2 by bird 2003
+ *
  * Copyright (c) 1982, 1986, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -49,4 +50,5 @@
  */
 struct	icmpstat {
+#if 0 /* OS2 is slightly different */
 /* statistics related to icmp packets generated */
 	u_long	icps_error;		/* # of calls to icmp_error */
@@ -61,4 +63,17 @@
 	u_long	icps_reflect;		/* number of responses */
 	u_long	icps_inhist[ICMP_MAXTYPE + 1];
+#else  /* OS2: short not longs */
+	u_short	icps_error;		/* # of calls to icmp_error */
+	u_short	icps_oldshort;		/* no error 'cuz old ip too short */
+	u_short	icps_oldicmp;		/* no error 'cuz old was icmp */
+	u_short	icps_outhist[ICMP_MAXTYPE + 1];
+/* statistics related to input messages processed */
+ 	u_short	icps_badcode;		/* icmp_code out of range */
+	u_short	icps_tooshort;		/* packet < ICMP_MINLEN */
+	u_short	icps_checksum;		/* bad checksum */
+	u_short	icps_badlen;		/* calculated bound mismatch */
+	u_short	icps_reflect;		/* number of responses */
+	u_short	icps_inhist[ICMP_MAXTYPE + 1];
+#endif
 #if 0 /* not on OS/2 */
 	u_long	icps_bmcastecho; 	/* b/mcast echo requests dropped */
Index: trunk/src/emx/include/netinet/if_ether.h
===================================================================
--- trunk/src/emx/include/netinet/if_ether.h	(revision 182)
+++ trunk/src/emx/include/netinet/if_ether.h	(revision 183)
@@ -1,3 +1,4 @@
 /* Modified for emx by hv 1994,1996
+ * Modified for gcc by bird 2003
  *
  * Copyright (c) 1982, 1986 Regents of the University of California.
@@ -39,11 +40,5 @@
 #define _NETINET_IF_ETHER_H_
 
-/*
- * Ethernet address - 6 octets
- * this is only used by the ethers(3) functions.
- */
-struct ether_addr {
-	u_char ether_addr_octet[6];
-};
+#ifdef TCPV40HDRS
 
 /*
@@ -57,10 +52,10 @@
 
 #define	ETHERTYPE_PUP		0x0200	/* PUP protocol */
-/* the IBM header corrects the following to 0x608 for OS/2 but I believe
- * this is just a dirty hack 
- */
+#define	ETHERTYPE_IP		0x0800	/* IP protocol */
+#ifdef OS2 /* hv thinks this is just a dirty hack, but we must include it. */
+#define	ETHERTYPE_ARP		0x0608	/* address resolution protocol */
+#else
 #define	ETHERTYPE_ARP		0x0806	/* address resolution protocol */
-#define	ETHERTYPE_IP		0x0800	/* IP protocol */
-#define	ETHERTYPE_REVARP	0x8035	/* reverse addr resolution protocol */
+#endif
 
 /*
@@ -79,5 +74,5 @@
  *
  * See RFC 826 for protocol description.  Structure below is adapted
- * to resolving internet addresses.  Field names used correspond to 
+ * to resolving internet addresses.  Field names used correspond to
  * RFC 826.
  */
@@ -113,9 +108,5 @@
  * Internet to ethernet address resolution table.
  */
-#ifdef TCPIPV4
 #pragma pack(1)
-#else
-#pragma pack(4)
-#endif
 struct	arptab {
 	struct	in_addr at_iaddr;	/* internet address */
@@ -127,12 +118,47 @@
 	u_short	at_rcf;			/* token ring routing control field */
 	u_short at_rseg[8];		/* token ring routing segments */
+#ifdef OS2
 	u_long at_millisec;		/* TOD millsecons of last update */
-#ifdef TCPIPV4
 	short at_interface;		/* interface index */
-#else
-	int at_interface;		/* interface index */
 #endif
 };
 #pragma pack()
 
+
+#else /*TCPV40HDRS*/
+
+
+#pragma pack(1)
+struct sockaddr_inarp {
+        u_char  sin_len;
+        u_char  sin_family;
+        u_short sin_port;
+        struct  in_addr sin_addr;
+        struct  in_addr sin_srcaddr;
+        u_short sin_tos;
+        u_short sin_other;
+#define SIN_PROXY 1
+};
+struct oarptab {
+        struct  in_addr at_iaddr;       /* internet address */
+        u_char  at_enaddr[6];           /* ethernet address */
+        u_char  at_timer;               /* minutes since last reference */
+        u_char  at_flags;               /* flags */
+        void * at_hold;
+        u_short at_rcf;                 /* token ring routing control field */
+        u_short at_rseg[8];             /* token ring routing segments */
+        u_long  at_millisec;            /* TOD milliseconds of last update */
+        u_short at_interface;           /* interface index */
+};
+#pragma pack()
+
+/*
+ * IP and ethernet specific routing flags
+ */
+#define RTF_USETRAILERS RTF_PROTO1      /* use trailers */
+#define RTF_ANNOUNCE    RTF_PROTO2      /* announce new arp entry */
+
+
+#endif /*TCPV40HDRS (else) */
+
 #endif /* !_NETINET_IF_ETHER_H_ */
Index: trunk/src/emx/include/netinet/igmp.h
===================================================================
--- trunk/src/emx/include/netinet/igmp.h	(revision 182)
+++ trunk/src/emx/include/netinet/igmp.h	(revision 183)
@@ -1,3 +1,4 @@
 /* Modified for emx by hv 1996
+ * Modified for gcc/os2 by bird 2003
  *
  * Copyright (c) 1988 Stephen Deering.
@@ -47,4 +48,7 @@
  * IGMP packet format.
  */
+#ifndef TCPV40HDRS
+#pragma pack(1)
+#endif
 struct igmp {
 	u_char		igmp_type;	/* version & type of IGMP message  */
@@ -53,4 +57,7 @@
 	struct in_addr	igmp_group;	/* group address being reported    */
 };					/*  (zero for queries)             */
+#ifndef TCPV40HDRS
+#pragma pack()
+#endif
 
 #define	IGMP_MINLEN		     8
Index: trunk/src/emx/include/netinet/igmp_var.h
===================================================================
--- trunk/src/emx/include/netinet/igmp_var.h	(revision 182)
+++ trunk/src/emx/include/netinet/igmp_var.h	(revision 183)
@@ -1,3 +1,4 @@
-/*
+/* Modified for gcc/os2 by bird 2003
+ *
  * Copyright (c) 1988 Stephen Deering.
  * Copyright (c) 1992, 1993
Index: trunk/src/emx/include/netinet/in.h
===================================================================
--- trunk/src/emx/include/netinet/in.h	(revision 182)
+++ trunk/src/emx/include/netinet/in.h	(revision 183)
@@ -1,3 +1,4 @@
 /* Modified for emx by hv and em 1994,1996
+ * Modified for gcc/os2 by bird 2003
  *
  * Copyright (c) 1982, 1986, 1990 Regents of the University of California.
@@ -66,6 +67,9 @@
 #define	IPPROTO_UDP		17		/* user datagram protocol */
 #define	IPPROTO_IDP		22		/* xns idp */
+#ifndef TCPV40HDRS
 #define	IPPROTO_TP		29 		/* tp-4 w/ class negotiation */
 #define	IPPROTO_EON		80		/* ISO cnlp */
+#define IPPROTO_ENCAP           98              /* encapsulation header */
+#endif
 
 #define	IPPROTO_RAW		255		/* raw IP packet */
@@ -80,6 +84,22 @@
  * for servers, not necessarily privileged.
  */
+#ifdef TCPV40HDRS
 #define	IPPORT_RESERVED		1024
 #define	IPPORT_USERRESERVED	5000
+#else
+ /* Changing the ephemeral port #s as per Internet Assigned Numbers Authority's
+  * update as found in JUL '97. [Ref: http://www.isi.edu/div7/iana/descript/html] */
+#define IPPORT_RESERVED        49152  /* Old 1024. Changed as per IANA draft */
+#define IPPORT_USERRESERVED    65535  /* Old 5000. Changed as per IANA draft */
+#endif
+
+#ifdef TCPV40HDRS
+/*
+ * Link numbers
+ */
+#define IMPLINK_IP              155
+#define IMPLINK_LOWEXPER        156
+#define IMPLINK_HIGHEXPER       158
+#endif
 
 /*
@@ -113,18 +133,26 @@
 
 #define	IN_CLASSD(i)		(((long)(i) & 0xf0000000) == 0xe0000000)
+#ifdef TCPV40HDRS
+#define IN_CLASSD_NET           0xffffffff
+#define	IN_CLASSD_HOST		0
+#else
 #define	IN_CLASSD_NET		0xf0000000	/* These ones aren't really */
+#define	IN_CLASSD_HOST		0x0fffffff	/* routing needn't know. */
+#endif
 #define	IN_CLASSD_NSHIFT	28		/* net and host fields, but */
-#define	IN_CLASSD_HOST		0x0fffffff	/* routing needn't know. */
 #define	IN_MULTICAST(i)		IN_CLASSD(i)
 
+#ifdef TCPV40HDRS
 #define	IN_EXPERIMENTAL(i)	(((long)(i) & 0xe0000000) == 0xe0000000)
+#else
+#define	IN_EXPERIMENTAL(i)	(((long)(i) & 0xf0000000) == 0xe0000000)
+#endif
 #define	IN_BADCLASS(i)		(((long)(i) & 0xf0000000) == 0xf0000000)
 
 #define	INADDR_ANY		(u_long)0x00000000
+#ifndef TCPV40HDRS
 #define	INADDR_LOOPBACK		(u_long)0x7f000001
+#endif
 #define	INADDR_BROADCAST	(u_long)0xffffffff	/* must be masked */
-#ifndef KERNEL
-#define	INADDR_NONE		0xffffffff		/* -1 return */
-#endif
 
 #define	INADDR_UNSPEC_GROUP	(u_long)0xe0000000	/* 224.0.0.0 */
@@ -132,15 +160,15 @@
 #define	INADDR_MAX_LOCAL_GROUP	(u_long)0xe00000ff	/* 224.0.0.255 */
 
+#ifndef KERNEL
+#define	INADDR_NONE		0xffffffff		/* -1 return */
+#endif
+
 #define	IN_LOOPBACKNET		127			/* official! */
 
-/*
- * Define a macro to stuff the loopback address into an Internet address
- */
-#define	IN_SET_LOOPBACK_ADDR(a) { \
-	(a)->sin_addr.s_addr = htonl(INADDR_LOOPBACK); \
-	(a)->sin_family = AF_INET; }
+
 /*
  * Socket address, internet style. 4.3BSD
  */
+#ifdef TCPV40HDRS
 struct sockaddr_in {
 	short	sin_family;
@@ -149,4 +177,15 @@
 	char	sin_zero[8];
 };
+#else
+#pragma pack(1)
+struct sockaddr_in {
+        u_char  sin_len;
+        u_char  sin_family;
+        u_short sin_port;
+        struct  in_addr sin_addr;
+        char    sin_zero[8];
+};
+#pragma pack()
+#endif
 
 /*
@@ -157,8 +196,14 @@
  * (this gets put into the header proper).
  */
+#ifndef TCPV40HDRS
+#pragma pack(1)
+#endif
 struct ip_opts {
 	struct	in_addr ip_dst;		/* first hop, 0 w/o src rt */
 	char	ip_opts[40];		/* actually variable in size */
 };
+#ifndef TCPV40HDRS
+#pragma pack()
+#endif
 
 /*
@@ -167,5 +212,4 @@
  */
 #define	IP_OPTIONS		1	/* buf/ip_opts; set/get IP options */
-
 #define	IP_MULTICAST_IF		2	/* u_char; set/get IP mcast i/f */
 #define	IP_MULTICAST_TTL	3	/* u_char; set/get IP mcast ttl */
@@ -173,34 +217,80 @@
 #define	IP_ADD_MEMBERSHIP	5	/* ip_mreq; add IP group membership */
 #define	IP_DROP_MEMBERSHIP	6	/* ip_mreq; drop IP group membership */
-
-#ifndef __EMX__ /* not supported so far */
-#define	IP_HDRINCL		2	/* int; header is included with data */
-#define	IP_TOS			3	/* int; IP type of service and preced */
-#define	IP_TTL			4	/* int; IP time to live */
-#define	IP_RECVOPTS		5	/* bool; receive all IP opts w/dgram */
-#define	IP_RECVRETOPTS		6	/* bool; receive IP opts for response */
-#define	IP_RECVDSTADDR		7	/* bool; receive IP dst addr w/dgram */
-#define	IP_RETOPTS		8	/* ip_opts; set/get IP options */
-#endif
-
+#ifndef TCPV40HDRS
+#define IP_HDRINCL              7    /* int; header is included with data */
+#define IP_TOS                  8    /* int; IP type of service and preced. */
+#define IP_TTL                  9    /* int; IP time to live */
+#define IP_RECVOPTS             10   /* bool; receive all IP opts w/dgram */
+#define IP_RECVRETOPTS          11   /* bool; receive IP opts for response */
+#define IP_RECVDSTADDR          12   /* bool; receive IP dst addr w/dgram */
+#define IP_RETOPTS              13   /* ip_opts; set/get IP options */
+#define IP_RECVTRRI             14   /* bool; receive token ring routing inf */
+#endif
+
+/*
+ * Defaults and limits for options
+ */
 #define	IP_DEFAULT_MULTICAST_TTL   1    /* normally limit m'casts to 1 hop  */
 #define	IP_DEFAULT_MULTICAST_LOOP  1    /* normally hear sends if a member  */
 #define	IP_MAX_MEMBERSHIPS         20   /* per socket; must fit in one mbuf */
+#ifndef TCPV40HDRS
+#define MAX_IN_MULTI      16*IP_MAX_MEMBERSHIPS      /* 320 max per os2 */
+extern u_short CntInMulti;
+#endif
 
 /*
  * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP.
  */
+#ifndef TCPV40HDRS
+#pragma pack(1)
+#endif
 struct ip_mreq {
 	struct	in_addr imr_multiaddr;	/* IP multicast address of group */
 	struct	in_addr imr_interface;	/* local IP address of interface */
 };
-
-/* prototypes for functions in inet(3) */
-extern	u_long		inet_addr(__const__ char*);
-extern	struct in_addr	inet_makeaddr(u_long, u_long);
-extern	u_long		inet_network(__const__ char*);
-extern	char		*inet_ntoa(struct in_addr);
-extern	u_long		inet_netof(struct in_addr);
-extern	u_long		inet_lnaof(struct in_addr);
+#ifndef TCPV40HDRS
+#pragma pack()
+#endif
+
+#ifdef TCPV40HDRS
+/* for functions */
+#include <arpa/inet.h>
+
+#else
+
+/*
+ * Definitions for inet sysctl operations.
+ *
+ * Third level is protocol number.
+ * Fourth level is desired variable within that protocol.
+ */
+#define IPPROTO_MAXID   (IPPROTO_IDP + 1)       /* don't list to IPPROTO_MAX */
+
+#define CTL_IPPROTO_NAMES { \
+        { "ip", CTLTYPE_NODE }, \
+        { "icmp", CTLTYPE_NODE }, \
+        { "igmp", CTLTYPE_NODE }, \
+        { "ggp", CTLTYPE_NODE }, \
+        { 0, 0 }, \
+        { 0, 0 }, \
+        { "tcp", CTLTYPE_NODE }, \
+        { 0, 0 }, \
+        { "egp", CTLTYPE_NODE }, \
+        { 0, 0 }, \
+        { 0, 0 }, \
+        { 0, 0 }, \
+        { "pup", CTLTYPE_NODE }, \
+        { 0, 0 }, \
+        { 0, 0 }, \
+        { 0, 0 }, \
+        { 0, 0 }, \
+        { "udp", CTLTYPE_NODE }, \
+        { 0, 0 }, \
+        { 0, 0 }, \
+        { 0, 0 }, \
+        { 0, 0 }, \
+        { "idp", CTLTYPE_NODE }, \
+}
+#endif /*TCPV40HDRS (else) */
 
 #if defined (__cplusplus)
Index: trunk/src/emx/include/netinet/ip.h
===================================================================
--- trunk/src/emx/include/netinet/ip.h	(revision 182)
+++ trunk/src/emx/include/netinet/ip.h	(revision 183)
@@ -1,3 +1,4 @@
 /* Modified for emx by hv 1994,1996
+ * Modified for gcc/os2 by bird 2003
  *
  * Copyright (c) 1982, 1986 Regents of the University of California.
@@ -39,7 +40,5 @@
 #define _NETINET_IP_H_
 
-#ifdef __EMX__
 #include <machine/endian.h>
-#endif /* __EMX__ */
 
 /*
@@ -56,4 +55,5 @@
  * against negative integers quite easily, and fail in subtle ways.
  */
+#pragma pack(1)
 struct ip {
 #if BYTE_ORDER == LITTLE_ENDIAN
@@ -71,4 +71,7 @@
 #define	IP_DF 0x4000			/* dont fragment flag */
 #define	IP_MF 0x2000			/* more fragments flag */
+#ifndef TCPV40HDRS
+#define IP_OFFMASK 0x1fff               /* mask for fragmenting bits */
+#endif
 	u_char	ip_ttl;			/* time to live */
 	u_char	ip_p;			/* protocol */
@@ -76,6 +79,11 @@
 	struct	in_addr ip_src,ip_dst;	/* source and dest address */
 };
-
+#pragma pack()
+
+#ifdef TCPV40HDRS
 #define	IP_MAXPACKET	32767		/* OS2 maximum packet size */
+#else
+#define IP_MAXPACKET    65535           /* maximum packet size */
+#endif
 
 /*
@@ -96,9 +104,16 @@
 #define	IPTOS_PREC_IMMEDIATE		0x40
 #define	IPTOS_PREC_PRIORITY		0x20
+#ifdef TCPV40HDRS
 #define	IPTOS_PREC_ROUTINE		0x10
+#else
+#define IPTOS_PREC_ROUTINE              0x00
+#endif
 
 /*
  * Definitions for options.
  */
+#ifndef TCPV40HDRS
+#define IPOPT_COPY              0x80
+#endif
 #define	IPOPT_COPIED(o)		((o)&0x80)
 #define	IPOPT_CLASS(o)		((o)&0x60)
@@ -119,4 +134,7 @@
 #define	IPOPT_SATID		136		/* satnet id */
 #define	IPOPT_SSRR		137		/* strict source route */
+#ifndef TCPV40HDRS
+#define IPOPT_RALERT            148             /* router alert */
+#endif
 
 /*
@@ -131,4 +149,5 @@
  * Time stamp option structure.
  */
+#pragma pack(1)
 struct	ip_timestamp {
 	u_char	ipt_code;		/* IPOPT_TS */
@@ -151,9 +170,15 @@
 	} ipt_timestamp;
 };
+#pragma pack()
 
 /* flag bits for ipt_flg */
 #define	IPOPT_TS_TSONLY		0		/* timestamps only */
 #define	IPOPT_TS_TSANDADDR	1		/* timestamps and addresses */
+#ifdef TCPV40HDRS
+#define IPOPT_TS_PRESPEC        2               /* specified modules only */
+#else
 #define	IPOPT_TS_PRESPEC	3		/* specified modules only */
+#endif
+
 
 /* bits for security (not byte swapped) */
@@ -170,4 +195,7 @@
  */
 #define	MAXTTL		255		/* maximum time to live (seconds) */
+/* This is being defined as TCP_TTL, UDP_TTL etc in tcp_time.h
+   #define IPDEFTTL        64
+*/
 #define	IPFRAGTTL	60		/* time to live for frags, slowhz */
 #define	IPTTLDEC	1		/* subtracted when forwarding */
@@ -175,8 +203,5 @@
 #define	IP_MSS		576		/* default maximum segment size */
 
-/* hv: this is a new data structure in TCPIPV4; consult IBM's doc for
- * details (provided they tell anything about it at all)
- */
-#ifdef TCPIPV4
+#ifdef TCPV40HDRS
 struct  ipstat {
 	long	ips_total;
@@ -204,5 +229,6 @@
 	long	ips_ipInUnknownProtos;
 };
-#endif
+#endif /* TCPV40HDRS */
+
 
 #endif /* !_NETINET_IP_H_ */
Index: trunk/src/emx/include/netinet/ip_icmp.h
===================================================================
--- trunk/src/emx/include/netinet/ip_icmp.h	(revision 182)
+++ trunk/src/emx/include/netinet/ip_icmp.h	(revision 183)
@@ -1,3 +1,4 @@
 /* Modified for emx by hv 1994
+ * Modified for gcc/os2 by bird 2003
  *
  * Copyright (c) 1982, 1986 Regents of the University of California.
@@ -47,4 +48,5 @@
  * Structure of an icmp header.
  */
+#pragma pack(1)
 struct icmp {
 	u_char	icmp_type;		/* type of message, see below */
@@ -59,4 +61,12 @@
 		} ih_idseq;
 		int ih_void;
+#ifndef TCPV40HDRS
+
+                /* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */
+                struct ih_pmtu {
+                        n_short ipm_void;
+                        n_short ipm_nextmtu;
+                } ih_pmtu;
+#endif
 	} icmp_hun;
 #define	icmp_pptr	icmp_hun.ih_pptr
@@ -65,4 +75,8 @@
 #define	icmp_seq	icmp_hun.ih_idseq.icd_seq
 #define	icmp_void	icmp_hun.ih_void
+#ifndef TCPV40HDRS
+#define icmp_pmvoid     icmp_hun.ih_pmtu.ipm_void
+#define icmp_nextmtu    icmp_hun.ih_pmtu.ipm_nextmtu
+#endif
 	union {
 		struct id_ts {
@@ -85,4 +99,5 @@
 #define	icmp_data	icmp_dun.id_data
 };
+#pragma pack()
 
 /*
@@ -112,4 +127,13 @@
 #define		ICMP_UNREACH_NEEDFRAG	4		/* IP_DF caused drop */
 #define		ICMP_UNREACH_SRCFAIL	5		/* src route failed */
+#ifndef TCPV40HDRS
+#define         ICMP_UNREACH_NET_UNKNOWN 6              /* unknown net */
+#define         ICMP_UNREACH_HOST_UNKNOWN 7             /* unknown host */
+#define         ICMP_UNREACH_ISOLATED   8               /* src host isolated */
+#define         ICMP_UNREACH_NET_PROHIB 9               /* prohibited access */
+#define         ICMP_UNREACH_HOST_PROHIB 10             /* ditto */
+#define         ICMP_UNREACH_TOSNET     11              /* bad tos for net */
+#define         ICMP_UNREACH_TOSHOST    12              /* bad tos for host */
+#endif
 #define	ICMP_SOURCEQUENCH	4		/* packet lost, slow down */
 #define	ICMP_REDIRECT		5		/* shorter route, codes: */
@@ -119,8 +143,15 @@
 #define		ICMP_REDIRECT_TOSHOST	3		/* for tos and host */
 #define	ICMP_ECHO		8		/* echo service */
+#ifndef TCPV40HDRS
+#define ICMP_ROUTERADVERT       9               /* router advertisement */
+#define ICMP_ROUTERSOLICIT      10              /* router solicitation */
+#endif
 #define	ICMP_TIMXCEED		11		/* time exceeded, code: */
 #define		ICMP_TIMXCEED_INTRANS	0		/* ttl==0 in transit */
 #define		ICMP_TIMXCEED_REASS	1		/* ttl==0 in reass */
 #define	ICMP_PARAMPROB		12		/* ip header bad */
+#ifndef TCPV40HDRS
+#define         ICMP_PARAMPROB_OPTABSENT 1              /* req. opt. absent */
+#endif
 #define	ICMP_TSTAMP		13		/* timestamp request */
 #define	ICMP_TSTAMPREPLY	14		/* timestamp reply */
@@ -132,4 +163,5 @@
 #define	ICMP_MAXTYPE		18
 
+#ifdef TCPV40HDRS
 #define	ICMP_INFOTYPE(type) \
 	((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \
@@ -137,12 +169,22 @@
 	(type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \
 	(type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY)
-
-/* hv: this is a new TCPIPV4 data structure. Consult IBM's doc on that. */
-#ifdef TCPIPV4
+#else
+#define ICMP_INFOTYPE(type) \
+        ((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \
+        (type) == ICMP_ROUTERADVERT || (type) == ICMP_ROUTERSOLICIT || \
+        (type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \
+        (type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \
+        (type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY)
+#endif
+
+#ifdef TCPV40HDRS
+#pragma pack(1)
 struct  icmpstat {
+/* statistics related to icmp packets generated */
 	short	icps_error;
 	short	icps_oldshort;
 	short	icps_oldicmp;
 	short	icps_outhist[ICMP_MAXTYPE + 1];
+/* statistics related to input messages processed */
 	short	icps_badcode;
 	short	icps_tooshort;
@@ -177,4 +219,5 @@
 	u_long	icps_OutAddrMaskReps;
 };
+#pragma pack()
 #endif
 
Index: trunk/src/emx/include/netinet/ip_mroute.h
===================================================================
--- trunk/src/emx/include/netinet/ip_mroute.h	(revision 182)
+++ trunk/src/emx/include/netinet/ip_mroute.h	(revision 183)
@@ -59,15 +59,27 @@
  * Multicast Routing set/getsockopt commands.
  */
+#if 1 /* not on OS/2 - but let's include it anyway. */
 #define	MRT_INIT	100	/* initialize forwarder */
 #define	MRT_DONE	101	/* shut down forwarder */
 #define	MRT_ADD_VIF	102	/* create virtual interface */
 #define	MRT_DEL_VIF	103	/* delete virtual interface */
-#if 0 /* different on OS/2 */
 #define MRT_ADD_MFC	104	/* insert forwarding cache entry */
 #define MRT_DEL_MFC	105	/* delete forwarding cache entry */
 #define MRT_VERSION	106	/* get kernel version number */
 #define MRT_ASSERT      107     /* enable PIM assert processing */
+#if 0
 #define GET_TIME(t)	microtime(&t)
-#else /* OS2: */
+#endif
+#endif
+
+
+#if 1 /* OS2 only? It's aliases of the above defs it seems... */
+/*
+ * DVMRP-specific setsockopt commands.
+ */
+#define DVMRP_INIT      100
+#define DVMRP_DONE      101
+#define DVMRP_ADD_VIF   102
+#define DVMRP_DEL_VIF   103
 #define DVMRP_ADD_LGRP  104
 #define DVMRP_DEL_LGRP  105
@@ -105,5 +117,7 @@
 	u_char	vifc_flags;     	/* VIFF_ flags defined below */
 	u_char	vifc_threshold; 	/* min ttl required to forward on vif */
+#if 0 /* not on OS/2 */
 	u_int	vifc_rate_limit;	/* max rate */
+#endif
 	struct	in_addr vifc_lcl_addr;	/* local interface address */
 	struct	in_addr vifc_rmt_addr;	/* remote address (tunnels only) */
Index: trunk/src/emx/include/netinet/ip_var.h
===================================================================
--- trunk/src/emx/include/netinet/ip_var.h	(revision 182)
+++ trunk/src/emx/include/netinet/ip_var.h	(revision 183)
@@ -90,5 +90,5 @@
 #pragma pack()
 
-#if 0 /* different/not on OS/2 */
+
 /*
  * Structure stored in mbuf in inpcb.ip_options
@@ -97,4 +97,6 @@
  * is in m_len.
  */
+#define MAX_IPOPTLEN    40
+#if 0 /* different/not on OS/2 */
 struct ipoption {
 	struct	in_addr ipopt_dst;	/* first-hop dst if source routed */
Index: trunk/src/emx/include/netinet/tcp.h
===================================================================
--- trunk/src/emx/include/netinet/tcp.h	(revision 182)
+++ trunk/src/emx/include/netinet/tcp.h	(revision 183)
@@ -1,3 +1,4 @@
 /* Modified for emx by hv 1996
+ * Modified for gcc/os2 by bird 2003
  *
  * Copyright (c) 1982, 1986 Regents of the University of California.
@@ -46,4 +47,5 @@
  * Per RFC 793, September, 1981.
  */
+#pragma pack(1)
 struct tcphdr {
 	u_short	th_sport;		/* source port */
@@ -51,4 +53,24 @@
 	tcp_seq	th_seq;			/* sequence number */
 	tcp_seq	th_ack;			/* acknowledgement number */
+#ifdef TCPV40HDRS
+#if BYTE_ORDER == LITTLE_ENDIAN
+        u_int   th_x2:4,                /* (unused) */
+                th_off:4,               /* data offset */
+                th_flags:8,
+                th_win:16;
+#endif
+#if BYTE_ORDER == BIG_ENDIAN
+        u_int   th_win:16,
+                th_flags:8,
+                th_off:4,               /* data offset */
+                th_x2:4;                /* (unused) */
+#endif
+#define TH_FIN  0x01
+#define TH_SYN  0x02
+#define TH_RST  0x04
+#define TH_PUSH 0x08
+#define TH_ACK  0x10
+#define TH_URG  0x20
+#else
 #if BYTE_ORDER == LITTLE_ENDIAN
 	u_char	th_x2:4,		/* (unused) */
@@ -67,11 +89,35 @@
 #define	TH_URG	0x20
 	u_short	th_win;			/* window */
+#endif
 	u_short	th_sum;			/* checksum */
 	u_short	th_urp;			/* urgent pointer */
 };
+#pragma pack()
 
 #define	TCPOPT_EOL	0
 #define	TCPOPT_NOP	1
 #define	TCPOPT_MAXSEG	2
+#ifndef TCPV40HDRS
+#define    TCPOLEN_MAXSEG               4
+#define TCPOPT_WINDOW           3
+#define    TCPOLEN_WINDOW               3
+#define TCPOPT_SACK_PERMITTED   4               /* Experimental */
+#define    TCPOLEN_SACK_PERMITTED       2
+#define TCPOPT_SACK             5               /* Experimental */
+#define TCPOPT_TIMESTAMP        8
+#define    TCPOLEN_TIMESTAMP            10
+#define    TCPOLEN_TSTAMP_APPA          (TCPOLEN_TIMESTAMP+2) /* appendix A */
+
+#define TCPOPT_CC               11              /* CC options: RFC-1644 */
+#define TCPOPT_CCNEW            12
+#define TCPOPT_CCECHO           13
+#define    TCPOLEN_CC                   6
+#define    TCPOLEN_CC_APPA              (TCPOLEN_CC+2)
+#define    TCPOPT_CC_HDR(ccopt)         \
+    (TCPOPT_NOP<<24|TCPOPT_NOP<<16|(ccopt)<<8|TCPOLEN_CC)
+#define TTCP_CLIENT_SND_WND   4096 /* dflt send window of ttcp client */
+#define TCPOPT_TSTAMP_HDR       \
+    (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP)
+#endif /*!TCPV40HDRS*/
 
 /*
@@ -81,7 +127,22 @@
  * This should be defined as MIN(512, IP_MSS - sizeof (struct tcpiphdr)).
  */
+#ifdef TCPV40HDRS
+#ifdef  lint
+#define TCP_MSS 536
+#else
+#ifndef IP_MSS
+#define IP_MSS  576
+#endif
+#define TCP_MSS MIN(512, IP_MSS - 40)
+#endif
+#else /* TCPV40HDRS*/
 #define	TCP_MSS	512
+#endif
 
 #define	TCP_MAXWIN	65535		/* largest value for window */
+
+#ifndef TCPV40HDRS
+#define TCP_MAX_WINSHIFT        14      /* maximum window shift */
+#endif
 
 /*
@@ -90,7 +151,22 @@
 #define	TCP_NODELAY	0x01	/* don't delay send to coalesce packets */
 #define	TCP_MAXSEG	0x02	/* set maximum segment size */
+#ifndef TCPV40HDRS
+#define TCP_MSL         0x03    /* MSL HACK */
+#define TCP_TIMESTMP    0x04    /* RFC 1323 (RTTM TimeStamp)   */
+#define TCP_WINSCALE    0x05    /* RFC 1323 (Window Scale)     */
+#define TCP_CC          0x06    /* RFC 1644 (Connection Count) */
+#ifdef VEGAS
+#define TCP_TAHOE                       3
+#define TCP_RENO                        4
+#define TCP_VEGAS                       5
+#define TCP_VEGAS_SPIKE_ON              6
+#define TCP_VEGAS_EXP_INC_OFF           7
+#define TCP_VEGAS_CONG_DETECT_OFF       8
+#define TCP_VEGAS_24                    9
+#define TCP_VEGAS_CONG_DETECT_PRED_ON   10
+#endif
+#endif /*!TCPV40HDS*/
 
-/* hv: this is a new data structure in TCPIPV4. */
-#ifdef TCPIPV4
+#ifdef TCPV40HDRS
 #include <netinet/tcp_var.h>
 #endif
Index: trunk/src/emx/include/netinet/tcp_var.h
===================================================================
--- trunk/src/emx/include/netinet/tcp_var.h	(revision 182)
+++ trunk/src/emx/include/netinet/tcp_var.h	(revision 183)
@@ -1,4 +1,4 @@
 /* Modified for emx by hv 1996
- * 
+ *
  * Copyright (c) 1982, 1986 Regents of the University of California.
  * All rights reserved.
@@ -44,5 +44,4 @@
  * but that's inconvenient at the moment.
  */
-#ifdef TCPIPCV4
 struct	tcpstat {
 	u_long	tcps_connattempt;	/* connections initiated */
@@ -72,4 +71,5 @@
 	u_long	tcps_sndwinup;		/* window update-only packets sent */
 	u_long	tcps_sndctrl;		/* control (SYN|FIN|RST) packets sent */
+        u_long  tcps_sndrst;            /* RST packets sent, MIB II ... */
 
 	u_long	tcps_rcvtotal;		/* total packets received */
@@ -94,6 +94,60 @@
 	u_long	tcps_rcvackbyte;	/* bytes acked by rcvd acks */
 	u_long	tcps_rcvwinupd;		/* rcvd window update packets */
+#ifndef TCPV40HDRS
+        u_long  tcps_pawsdrop;          /* segments dropped due to PAWS */
+        u_long  tcps_predack;           /* times hdr predict ok for acks */
+        u_long  tcps_preddat;           /* times hdr predict ok for data pkts*/
+        u_long  tcps_pcbcachemiss;
+        u_long  tcps_persistdrop;       /* timeout in persist state */
+        u_long  tcps_badsyn;            /* bogus SYN, e.g. premature ACK */
+
+        /* the fillowing 7 are for mtudisco and ttcp */
+
+        u_long  tcps_mturesent;         /* resends due to MTU discovery */
+        u_long  tcps_cachedrtt;         /* times cached RTT in route updated */
+        u_long  tcps_cachedrttvar;      /* times cached rttvar updated */
+        u_long  tcps_cachedssthresh;    /* times cached ssthresh updated */
+        u_long  tcps_usedrtt;           /* times RTT initialized from route */
+        u_long  tcps_usedrttvar;        /* times RTTVAR initialized from rt */
+        u_long  tcps_usedssthresh;      /* times ssthresh initialized from rt*/
+#endif
 };
-#endif
+
+#ifndef TCPV40HDRS
+/*
+ * Names for TCP sysctl objects
+ */
+#define TCPCTL_MSSDFLT          1       /* MSS default */
+#define TCPCTL_STATS            2       /* statistics (read-only) */
+#define TCPCTL_RTTDFLT          3       /* default RTT estimate */
+#define TCPCTL_MSL              4       /* No Of Keepalive probes */
+#define TCPCTL_INETCFG          6       /* Generic TCP Inetcfg switching */
+#define TCPCTL_LINGERTIME       7       /* Linger On close timer */
+#define TCPCTL_KEEPCNT          8       /* No Of Keepalive probes */
+#define TCPCTL_TCPSWIN          9       /* TCP Send Window Size    */
+#define TCPCTL_TCPRWIN          10      /* TCP Recieve Window Size */
+#define TCPCTL_TTL              11      /* TTL for TCP  packets */
+#define TCPCTL_MTU              12      /* Path MTU Discovery ON/OFF flg */
+#define TCPCTL_WINSCALE         13      /* Winow Scale (Fat Pipe) ON/OFF flg */
+#define TCPCTL_TIMESTMP         14      /* TCP TimeStamp ON/OFF flg */
+#define TCPCTL_CC               15      /* Cc, CCnew & Echo ON/OFF flg */
+#define TCPCTL_REALSLOW         16      /* Real Slow Timer for Time Wait Q */
+#define TCPCTL_REUSETW          17      /* Reuse TW inetcfg */
+#define TCPCTL_SYNCOOKIE        18      /* Syncookie inetcfg */
+#define TCPCTL_PERFHTTP        19      /* Fast Path HTTP */
+
+
+/*Inetcfg ioctl constants */
+#define ICFG_SETKEEPALIVE       20      /* sysctl code:Set the KeepAlive timer */
+#define ICFG_GETKEEPALIVE       21      /* sysctl code:Get the KeepAlive timer defaults */
+
+#define TCPCTL_NAMES { \
+        { 0, 0 }, \
+        { "mssdflt", CTLTYPE_INT },    \
+        { "stats",   CTLTYPE_STRUCT }, \
+        { "rttdflt", CTLTYPE_INT },    \
+        { "inetcfg", CTLTYPE_INETCFG },\
+}
+#endif /* !TCPV40HDRS */
 
 #endif /* !_NETINET_TCP_VAR_H_ */
Index: trunk/src/emx/include/netinet/udp.h
===================================================================
--- trunk/src/emx/include/netinet/udp.h	(revision 182)
+++ trunk/src/emx/include/netinet/udp.h	(revision 183)
@@ -1,3 +1,4 @@
 /* Modified for emx by hv 1996
+ * Modified for gcc/os2 by bird 2003
  *
  * Copyright (c) 1982, 1986 Regents of the University of California.
@@ -39,8 +40,12 @@
 #define _NETINET_UDP_H_
 
+#ifdef TCPV40HDRS
+#include <netinet/udp_var.h>
+#else
 /*
  * Udp protocol header.
  * Per RFC 768, September, 1981.
  */
+#pragma pack(1)
 struct udphdr {
 	u_short	uh_sport;		/* source port */
@@ -49,16 +54,5 @@
 	u_short	uh_sum;			/* udp checksum */
 };
-
-/* hv: this is a new structure of TCPIPV4. Consult IBM's docs on that */
-#ifdef TCPIPV4
-#include <netinet/udp_var.h>
-struct  udpstat {
-	u_long	udps_hdrops;
-	u_long	udps_badsum;
-	u_long	udps_badlen;
-	u_long	udps_udpInDatagrams;
-	u_long	udps_udpNoPorts;
-	u_long	udps_udpOutDatagrams;
-};
+#pragma pack()
 #endif
 
Index: trunk/src/emx/include/netinet/udp_var.h
===================================================================
--- trunk/src/emx/include/netinet/udp_var.h	(revision 182)
+++ trunk/src/emx/include/netinet/udp_var.h	(revision 183)
@@ -1,4 +1,5 @@
 /* Modified for emx by hv 1996
- * 
+ * Modified for gcc/os2 by bird 2003
+ *
  * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
  * All rights reserved.
@@ -39,29 +40,68 @@
 #define _NETINET_UDP_VAR_H_
 
-#ifdef TCPIPV4
-struct	udpstat {
-				/* input statistics: */
-#ifndef __EMX__
-	u_long	udps_ipackets;		/* total input packets */
-#endif
-	u_long	udps_hdrops;		/* packet shorter than header */
-	u_long	udps_badsum;		/* checksum error */
-	u_long	udps_badlen;		/* data length larger than packet */
-#ifndef __EMX__
-	u_long	udps_noport;		/* no socket on port */
-	u_long	udps_noportbcast;	/* of above, arrived as broadcast */
-	u_long	udps_fullsock;		/* not delivered, input socket full */
-	u_long	udpps_pcbcachemiss;	/* input packets missing pcb cache */
-					/* output statistics: */
-	u_long	udps_opackets;		/* total output packets */
-#else /* __EMX__ */
+#ifdef TCPV40HDRS
+struct  udpstat {
+	u_long	udps_hdrops;
+	u_long	udps_badsum;
+	u_long	udps_badlen;
 	u_long	udps_udpInDatagrams;
 	u_long	udps_udpNoPorts;
 	u_long	udps_udpOutDatagrams;
-#endif /* __EMX__ */
 };
-#endif /* TCPIPV4 */
 
-#define	UDP_TTL		30	/* default time to live for UDP packets */
+#else
+
+/*
+ * UDP kernel structures and variables.
+ */
+#pragma pack(1)
+struct  udpiphdr {
+        struct  ipovly ui_i;            /* overlaid ip structure */
+        struct  udphdr ui_u;            /* udp header */
+};
+#pragma pack()
+#define ui_next         ui_i.ih_next
+#define ui_prev         ui_i.ih_prev
+#define ui_x1           ui_i.ih_x1
+#define ui_pr           ui_i.ih_pr
+#define ui_len          ui_i.ih_len
+#define ui_src          ui_i.ih_src
+#define ui_dst          ui_i.ih_dst
+#define ui_sport        ui_u.uh_sport
+#define ui_dport        ui_u.uh_dport
+#define ui_ulen         ui_u.uh_ulen
+#define ui_sum          ui_u.uh_sum
+
+struct  udpstat {
+                                /* input statistics: */
+        u_long  udps_ipackets;          /* total input packets */
+        u_long  udps_hdrops;            /* packet shorter than header */
+        u_long  udps_badsum;            /* checksum error */
+        u_long  udps_badlen;            /* data length larger than packet */
+        u_long  udps_noport;            /* no socket on port */
+        u_long  udps_noportbcast;       /* of above, arrived as broadcast */
+        u_long  udps_fullsock;          /* not delivered, input socket full */
+        u_long  udpps_pcbcachemiss;     /* input packets missing pcb cache */
+                                /* output statistics: */
+        u_long  udps_opackets;          /* total output packets */
+};
+
+/*
+ * Names for UDP sysctl objects
+ */
+#define UDPCTL_CHECKSUM         1       /* checksum UDP packets */
+#define UDPCTL_STATS            2       /* statistics (read-only) */
+#define UDPCTL_INETCFG          31      /* sysctl code-Generic UDP Inetcfg switching */
+#define UDPCTL_TTL              32      /* sysctl code-TTL for UDP  packets */
+#define UDPCTL_UDPSWIN          33      /* sysctl code-UDP really MAX datagram Size */
+#define UDPCTL_UDPRWIN          34      /* sysctl code-UDP recieve window size */
+
+#define UDPCTL_NAMES { \
+        { 0, 0 }, \
+        { "stats", CTLTYPE_STRUCT }, \
+        { "inetcfg",CTLTYPE_INETCFG},\
+}
+
+#endif /* TCPV40HDRS */
 
 #endif /* !_NETINET_UDP_VAR_H_ */
Index: trunk/src/emx/include/netnb/nb.h
===================================================================
--- trunk/src/emx/include/netnb/nb.h	(revision 182)
+++ trunk/src/emx/include/netnb/nb.h	(revision 183)
@@ -12,5 +12,5 @@
 
 #define	NBPROTO_NB	1
-#define	NB_FAMILY	AF_NETBIOS
+#define	NB_FAMILY	18 /* temporary hack? */
 #define	NB_ADDRSIZE	sizeof(struct sockaddr_nb)
 #define	NB_UNIQUE	0
@@ -20,5 +20,5 @@
 #define	NB_NETIDLEN	8
 #define	NB_HOSTLEN	12
-#define	NB_PORTLEN	4
+#define	NB_PORTLEN	(NB_NAMELEN - NB_HOSTLEN)
 /*                       1234567890123456 */
 #define	NB_BCAST_NAME	"*               "
@@ -26,14 +26,27 @@
 #define NB_NULL_NAME	"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
 
-#define	NBPORT_RESERVED	IPPORT_RESERVED
-#define	NBPORT_USERRESERVED IPPORT_USERRESERVED
+/* must match IOPORT_* constants in netinet/in.h! */
+#ifdef TCPV40HDRS
+#define	NBPORT_RESERVED	        "1024"
+#define	NBPORT_USERRESERVED     "5000"
+#else
+#define NBPORT_RESERVED         "49152"
+#define NBPORT_USERRESERVED     "65535"
+#endif
 
 /* address format for netbios */
+#pragma pack(1)
 struct sockaddr_nb {
+#ifdef TCPV40HDRS
 	short	snb_family;		/* protocol family */
+#else
+        u_char  snb_len;
+        u_char  snb_family;             /* netbios protocol family */
+#endif
 	short	snb_type;		/* unique/multicast */
 	char	snb_netid[NB_NETIDLEN];	/* netid */
 	char	snb_name[NB_NAMELEN];	/* name */
 };
+#pragma pack()
 
 #endif /* !_NETNB_NB_H_ */
Index: trunk/src/emx/include/resolv.h
===================================================================
--- trunk/src/emx/include/resolv.h	(revision 182)
+++ trunk/src/emx/include/resolv.h	(revision 183)
@@ -1,3 +1,4 @@
 /* Modified for EMX by hv 1994,1996
+ * Modified for gcc by bird 2003
  *
  * Copyright (c) 1983, 1987, 1989 The Regents of the University of California.
@@ -33,5 +34,5 @@
  *
  *	from: @(#)resolv.h	5.15 (Berkeley) 4/3/91
- *	resolv.h,v 1.1 2003/04/16 15:53:07 bird Exp
+ *	resolv.h,v 1.2 2003/05/19 02:41:00 bird Exp
  */
 
@@ -39,9 +40,26 @@
 #define	_RESOLV_H_
 
+
 #if defined (__cplusplus)
 extern "C" {
 #endif
 
-#pragma pack(4)
+/* toolkit includes a bunch of headers */
+#ifndef TCPV40HDRS
+#include <sys/param.h>
+#include <types.h>
+#include <sys/cdefs.h>
+#include <stdio.h>
+
+
+/*
+ * Revision information.  This is the release date in YYYYMMDD format.
+ * It can change every day so the right thing to do with it is use it
+ * in preprocessor commands such as "#if (__RES > 19931104)".  Do not
+ * compare for equality; rather, use it to determine whether your resolver
+ * is new enough to contain a certain feature.
+ */
+
+#define __RES   19960801
 
 /*
@@ -52,6 +70,7 @@
 
 #ifndef _PATH_RESCONF
-#define _PATH_RESCONF        "/tcpip/etc/resolv.conf"
-#endif
+#define _PATH_RESCONF        "/mptn/etc/resolv.conf"
+#endif
+#endif /* TCPV40HDRS */
 
 /*
@@ -60,9 +79,16 @@
 #define	MAXNS			3	/* max # name servers we'll track */
 #define	MAXDFLSRCH		3	/* # default domain levels to try */
+#define	LOCALDOMAINPARTS	2	/* min levels in name that is "local" */
+#define RES_TIMEOUT             4       /* min. seconds between retries */
+#ifdef TCPV40HDRS
+#define	MAXDNSRCH		3	/* max # domains in search path */
+#else
 #define	MAXDNSRCH		6	/* max # domains in search path */
-#define	LOCALDOMAINPARTS	2	/* min levels in name that is "local" */
-#define	MAXDNSLUS		4	/* max # of host lookup types */
-
-#define	RES_TIMEOUT		5	/* min. seconds between retries */
+#define MAXRESOLVSORT           10      /* number of net to sort on */
+#define RES_MAXNDOTS            15      /* should reflect bit field size */
+#endif
+
+
+#ifdef TCPV40HDRS
 
 #pragma pack(4)
@@ -77,7 +103,34 @@
 	char	defdname[MAXDNAME];	/* default domain */
 	char	*dnsrch[MAXDNSRCH+1];	/* components of domain to search */
-/*	char	lookups[MAXDNSLUS];*/	/* not in OS/2 */
 };
-#pragma pack(1)
+#pragma pack()
+
+#else
+
+#pragma pack(4)
+struct __res_state {
+        int     retrans;                /* retransmition time interval */
+        int     retry;                  /* number of times to retransmit */
+        u_long  options;                /* option flags - see below. */
+        int     nscount;                /* number of name servers */
+        struct sockaddr_in
+                nsaddr_list[MAXNS];     /* address of name server */
+#define nsaddr  nsaddr_list[0]          /* for backward compatibility */
+        u_short id;                     /* current message id */
+        char    defdname[256];          /* default domain (deprecated) */
+        char    *dnsrch[MAXDNSRCH+1];   /* components of domain to search */
+        u_long  pfcode;                 /* RES_PRF_ flags - see below. */
+        unsigned ndots:4;               /* threshold for initial abs. query */
+        unsigned nsort:4;               /* number of elements in sort_list[] */
+        char    unused[3];
+        struct {
+                struct in_addr  addr;
+                u_int32_t       mask;
+        } sort_list[MAXRESOLVSORT];
+        char    pad[72];                /* on an i386 this means 512b total */
+};
+#pragma pack()
+
+#endif
 
 /*
@@ -94,22 +147,170 @@
 #define RES_STAYOPEN	0x0100		/* Keep TCP socket open */
 #define RES_DNSRCH	0x0200		/* search up local domain tree */
+#ifndef TCPV40HDRS
+#define RES_INSECURE1   0x00000400      /* type 1 security disabled */
+#define RES_INSECURE2   0x00000800      /* type 2 security disabled */
+#define RES_NOALIASES   0x00001000      /* shuts off HOSTALIASES feature */
+#define RES_USE_INET6   0x00002000      /* use/map IPv6 in gethostbyname() */
+#endif
 
 #define RES_DEFAULT	(RES_RECURSE | RES_DEFNAMES | RES_DNSRCH)
 
+
+
+#ifdef TCPV40HDRS
+
 extern	struct state _res;
 
+#else
+
+/*
+ * Resolver "pfcode" values.  Used by dig.
+ */
+#define RES_PRF_STATS   0x00000001
+/*                      0x00000002      */
+#define RES_PRF_CLASS   0x00000004
+#define RES_PRF_CMD     0x00000008
+#define RES_PRF_QUES    0x00000010
+#define RES_PRF_ANS     0x00000020
+#define RES_PRF_AUTH    0x00000040
+#define RES_PRF_ADD     0x00000080
+#define RES_PRF_HEAD1   0x00000100
+#define RES_PRF_HEAD2   0x00000200
+#define RES_PRF_TTLID   0x00000400
+#define RES_PRF_HEADX   0x00000800
+#define RES_PRF_QUERY   0x00001000
+#define RES_PRF_REPLY   0x00002000
+#define RES_PRF_INIT    0x00004000
+/*                      0x00008000      */
+
+/* hooks are still experimental as of 4.9.2 */
+typedef enum { res_goahead, res_nextns, res_modified, res_done, res_error }
+        res_sendhookact;
+
+typedef res_sendhookact (* _System res_send_qhook)(struct sockaddr_in * const *ns,
+                                              const u_char **query,
+                                              int *querylen,
+                                              u_char *ans,
+                                              int anssiz,
+                                              int *resplen);
+
+typedef res_sendhookact (* _System res_send_rhook)(const struct sockaddr_in *ns,
+                                              const u_char *query,
+                                              int querylen,
+                                              u_char *ans,
+                                              int anssiz,
+                                              int *resplen);
+
+#pragma pack(4)
+struct res_sym {
+        int     number;         /* Identifying number, like T_MX */
+        char *  name;           /* Its symbolic name, like "MX" */
+        char *  humanname;      /* Its fun name, like "mail exchanger" */
+};
+#pragma pack()
+
+extern struct __res_state   _ress[2];
+extern const struct res_sym __p_class_syms[];
+extern const struct res_sym __p_type_syms[];
+#define _res (_ress[0])
+
 /* Private routines shared between libc/net, named, nslookup and others. */
-int	dn_skipname (__const__ u_char *, __const__ u_char *);
-void	putlong (u_long, u_char *);
-void	putshort (u_short, u_char *);
-
-/* public routines */
-int	dn_comp(__const__ u_char *, u_char *, int, u_char **, u_char **);
-int	dn_expand(__const__ u_char *, __const__ u_char *, __const__ u_char *,
-			u_char *, int);
-int	res_init(void);
-int	res_mkquery(int, __const__ char *, int, int, __const__ char *, int,
-			__const__ struct rrec *, char *, int);
-int	res_send(__const__ char *, int, char *, int);
+#define res_hnok        __res_hnok
+#define res_ownok       __res_ownok
+#define res_mailok      __res_mailok
+#define res_dnok        __res_dnok
+#define sym_ston        __sym_ston
+#define sym_ntos        __sym_ntos
+#define sym_ntop        __sym_ntop
+#define b64_ntop        __b64_ntop
+#define b64_pton        __b64_pton
+#define loc_ntoa        __loc_ntoa
+#define loc_aton        __loc_aton
+#define dn_skipname     __dn_skipname
+#define fp_resstat      __fp_resstat
+#define fp_query        __fp_query
+#define fp_nquery       __fp_nquery
+#define hostalias       __hostalias
+#define putlong         __putlong
+#define putshort        __putshort
+#define p_class         __p_class
+#define p_time          __p_time
+#define p_type          __p_type
+#define p_query         __p_query
+#define p_cdnname       __p_cdnname
+#define p_cdname        __p_cdname
+#define p_fqnname       __p_fqnname
+#define p_fqname        __p_fqname
+#define p_rr            __p_rr
+#define p_option        __p_option
+#define p_secstodate    __p_secstodate
+#define dn_count_labels __dn_count_labels
+#define dn_comp         __dn_comp
+#define dn_expand       __dn_expand
+#define res_init        __res_init
+#define res_randomid    __res_randomid
+#define res_query       __res_query
+#define res_search      __res_search
+#define res_querydomain __res_querydomain
+#define res_mkquery     __res_mkquery
+#define res_send        __res_send
+#define res_isourserver __res_isourserver
+#define res_nameinquery __res_nameinquery
+#define res_queriesmatch __res_queriesmatch
+#define res_close       __res_close
+
+int             _System res_hnok(const char *);
+int             _System res_ownok(const char *);
+int             _System res_mailok(const char *);
+int             _System res_dnok(const char *);
+int             _System sym_ston(const struct res_sym *, char *, int *);
+const char *    _System sym_ntos(const struct res_sym *, int, int *);
+const char *    _System sym_ntop(const struct res_sym *, int, int *);
+int             _System b64_ntop(u_char const *, size_t, char *, size_t);
+int             _System b64_pton(char const *, u_char *, size_t);
+int             _System loc_aton(const char *, u_char *);
+const char *    _System loc_ntoa(const u_char *, char *);
+int             _System dn_skipname(const u_char *, const u_char *);
+void            _System fp_resstat(struct __res_state *, int);
+void            _System fp_query(const u_char *, int);
+void            _System fp_nquery(const u_char *, int, int);
+const char *    _System hostalias(const char *);
+void            _System putlong(u_int32_t, u_char *);
+void            _System putshort(u_int16_t, u_char *);
+const char *    _System p_class(int);
+const char *    _System p_time(u_int32_t);
+const char *    _System p_type(int);
+void            _System p_query(const u_char *);
+const u_char *  _System p_cdnname(const u_char *, const u_char *, int, int);
+const u_char *  _System p_cdname(const u_char *, const u_char *, int);
+const u_char *  _System p_fqnname(const u_char *cp, const u_char *msg,
+                                             int, char *, int);
+const u_char *  _System p_fqname(const u_char *, const u_char *, int);
+const u_char *  _System p_rr(const u_char *, const u_char *, int);
+const char *    _System p_option(u_long option);
+char *          _System p_secstodate(u_long);
+int             _System dn_count_labels(char *);
+int             _System dn_comp(const char *, u_char *, int,
+                                u_char **, u_char **);
+int             _System dn_expand(const u_char *, const u_char *, const u_char *,
+                                  char *, int);
+int             _System res_init(void);
+u_int           _System res_randomid(void);
+int             _System res_query(const char *, int, int, u_char *, int);
+int             _System res_search(const char *, int, int, u_char *, int);
+int             _System res_querydomain(const char *, const char *, int, int, u_char *, int);
+int             _System res_mkquery(int, const char *, int, int, const u_char *, int,
+                                    const u_char *, u_char *, int);
+int             _System res_send(const u_char *, int, u_char *, int);
+int             _System res_isourserver(const struct sockaddr_in *);
+int             _System res_nameinquery(const char *, int, int,
+                                        const u_char *, const u_char *);
+int             _System res_queriesmatch(const u_char *, const u_char *,
+                                         const u_char *, const u_char *);
+void            _System res_close(void);
+int             _System dn_find(u_char *exp_dn, u_char *msg,
+                               u_char **dnptrs, u_char **lastdnptr);
+#endif /* !TCPV40HDRS */
+
 
 #if defined (__cplusplus)
Index: trunk/src/emx/include/socks.h
===================================================================
--- trunk/src/emx/include/socks.h	(revision 182)
+++ trunk/src/emx/include/socks.h	(revision 183)
@@ -51,4 +51,6 @@
 
 -----------------------------------------------------------------*/
+#ifndef _SOCKS_H_
+#define _SOCKS_H_
 #include <netinet\in.h>
 
@@ -80,4 +82,5 @@
 } Socks_t;
 
+
 typedef struct socksdata {
    /* the following feilds are for socks */
@@ -95,3 +98,3 @@
    struct sockaddr_in me;
 } SD;
-
+#endif
Index: trunk/src/emx/include/sys/cdefs.h
===================================================================
--- trunk/src/emx/include/sys/cdefs.h	(revision 182)
+++ trunk/src/emx/include/sys/cdefs.h	(revision 183)
@@ -1,3 +1,4 @@
-/*
+/*- modified for gcc/os2 by bird 2003
+ *
  * Copyright (c) 1991, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -34,13 +35,15 @@
  * SUCH DAMAGE.
  *
- *	@(#)cdefs.h	8.7 (Berkeley) 1/21/94
- */
-
-#ifndef	_CDEFS_H_
-#define	_CDEFS_H_
+ *	@(#)cdefs.h	8.8 (Berkeley) 1/9/95
+ * $FreeBSD: src/sys/sys/cdefs.h,v 1.68 2002/10/21 20:50:30 mike Exp $
+ */
+
+#ifndef	_SYS_CDEFS_H_
+#define	_SYS_CDEFS_H_
+#define _CDEFS_H_ /* compatability */
 
 #if defined(__cplusplus)
 #define	__BEGIN_DECLS	extern "C" {
-#define	__END_DECLS	};
+#define	__END_DECLS	}
 #else
 #define	__BEGIN_DECLS
@@ -51,12 +54,19 @@
  * The __CONCAT macro is used to concatenate parts of symbol names, e.g.
  * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
- * The __CONCAT macro is a bit tricky -- make sure you don't put spaces
- * in between its arguments.  __CONCAT can also concatenate double-quoted
- * strings produced by the __STRING macro, but this only works with ANSI C.
+ * The __CONCAT macro is a bit tricky to use if it must work in non-ANSI
+ * mode -- there must be no spaces between its arguments, and for nested
+ * __CONCAT's, all the __CONCAT's must be at the left.  __CONCAT can also
+ * concatenate double-quoted strings produced by the __STRING macro, but
+ * this only works with ANSI C.
+ *
+ * __XSTRING is like __STRING, but it expands any macros in its argument
+ * first.  It is only available with ANSI C.
  */
 #if defined(__STDC__) || defined(__cplusplus)
 #define	__P(protos)	protos		/* full-blown ANSI C */
-#define	__CONCAT(x,y)	x ## y
-#define	__STRING(x)	#x
+#define	__CONCAT1(x,y)	x ## y
+#define	__CONCAT(x,y)	__CONCAT1(x,y)
+#define	__STRING(x)	#x		/* stringify without expanding x */
+#define	__XSTRING(x)	__STRING(x)	/* expand x, then stringify */
 
 #define	__const		const		/* define reserved names to standard */
@@ -94,29 +104,296 @@
 #define	signed
 #define	volatile
-#endif
+#endif	/* !NO_ANSI_KEYWORDS */
 #endif	/* !__GNUC__ */
 #endif	/* !(__STDC__ || __cplusplus) */
 
 /*
- * GCC1 and some versions of GCC2 declare dead (non-returning) and
- * pure (no side effects) functions using "volatile" and "const";
- * unfortunately, these then cause warnings under "-ansi -pedantic".
- * GCC2 uses a new, peculiar __attribute__((attrs)) style.  All of
- * these work for GNU C++ (modulo a slight glitch in the C++ grammar
- * in the distribution version of 2.5.5).
- */
-#if !defined(__GNUC__) || __GNUC__ < 2 || __GNUC_MINOR__ < 5
-#define	__attribute__(x)	/* delete __attribute__ if non-gcc or gcc1 */
-#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
-#define	__dead		__volatile
-#define	__pure		__const
-#endif
-#endif
-
-/* Delete pseudo-keywords wherever they are not available or needed. */
-#ifndef __dead
-#define	__dead
-#define	__pure
-#endif
-
-#endif /* !_CDEFS_H_ */
+ * Compiler-dependent macros to help declare dead (non-returning) and
+ * pure (no side effects) functions, and unused variables.  They are
+ * null except for versions of gcc that are known to support the features
+ * properly (old versions of gcc-2 supported the dead and pure features
+ * in a different (wrong) way).  If we do not provide an implementation
+ * for a given compiler, let the compile fail if it is told to use
+ * a feature that we cannot live without.
+ */
+#ifdef lint
+#define	__dead2
+#define	__pure2
+#define	__unused
+#define	__packed
+#define	__aligned(x)
+#define	__section(x)
+#else
+#if __GNUC__ < 2 || __GNUC__ == 2 && __GNUC_MINOR__ < 5
+#define	__dead2
+#define	__pure2
+#define	__unused
+#endif
+#if __GNUC__ == 2 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 7
+#define	__dead2		__attribute__((__noreturn__))
+#define	__pure2		__attribute__((__const__))
+#define	__unused
+/* XXX Find out what to do for __packed, __aligned and __section */
+#endif
+#if __GNUC__ == 2 && __GNUC_MINOR__ >= 7 || __GNUC__ == 3
+#define	__dead2		__attribute__((__noreturn__))
+#define	__pure2		__attribute__((__const__))
+#define	__unused	__attribute__((__unused__))
+#define	__packed	__attribute__((__packed__))
+#define	__aligned(x)	__attribute__((__aligned__(x)))
+#define	__section(x)	__attribute__((__section__(x)))
+#endif
+#endif
+
+/* XXX: should use `#if __STDC_VERSION__ < 199901'. */
+#if !(__GNUC__ == 2 && __GNUC_MINOR__ >= 7 || __GNUC__ >= 3)
+#define	__func__	NULL
+#endif
+
+#if __GNUC__ >= 2 && !defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901
+#define	__LONG_LONG_SUPPORTED
+#endif
+
+/*
+ * GCC 2.95 provides `__restrict' as an extension to C90 to support the
+ * C99-specific `restrict' type qualifier.  We happen to use `__restrict' as
+ * a way to define the `restrict' type qualifier without disturbing older
+ * software that is unaware of C99 keywords.
+ */
+#if !(__GNUC__ == 2 && __GNUC_MINOR__ == 95)
+#if __STDC_VERSION__ < 199901
+#define	__restrict
+#else
+#define	__restrict	restrict
+#endif
+#endif
+
+/*
+ * We define this here since <stddef.h>, <sys/queue.h>, and <sys/types.h>
+ * require it.
+ */
+#define	__offsetof(type, field)	((size_t)(&((type *)0)->field))
+
+/*
+ * Compiler-dependent macros to declare that functions take printf-like
+ * or scanf-like arguments.  They are null except for versions of gcc
+ * that are known to support the features properly (old versions of gcc-2
+ * didn't permit keeping the keywords out of the application namespace).
+ */
+#if __GNUC__ < 2 || __GNUC__ == 2 && __GNUC_MINOR__ < 7
+#define	__printflike(fmtarg, firstvararg)
+#define	__scanflike(fmtarg, firstvararg)
+#else
+#define	__printflike(fmtarg, firstvararg) \
+	    __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
+#define	__scanflike(fmtarg, firstvararg) \
+	    __attribute__((__format__ (__scanf__, fmtarg, firstvararg)))
+#endif
+
+/* Compiler-dependent macros that rely on FreeBSD-specific extensions. */
+#if __FreeBSD_cc_version >= 300001 && __FreeBSD_cc_version < 500003
+#define	__printf0like(fmtarg, firstvararg) \
+	    __attribute__((__format__ (__printf0__, fmtarg, firstvararg)))
+#else
+#define	__printf0like(fmtarg, firstvararg)
+#endif
+
+#if 0 /* def __GNUC__ - ELF specific, so skip everything */
+#define	__strong_reference(sym,aliassym)	\
+	extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym)));
+#ifdef __STDC__
+#define	__weak_reference(sym,alias)	\
+	__asm__(".weak " #alias);	\
+	__asm__(".equ "  #alias ", " #sym)
+#define	__warn_references(sym,msg)	\
+	__asm__(".section .gnu.warning." #sym);	\
+	__asm__(".asciz \"" msg "\"");	\
+	__asm__(".previous")
+#else
+#define	__weak_reference(sym,alias)	\
+	__asm__(".weak alias");		\
+	__asm__(".equ alias, sym")
+#define	__warn_references(sym,msg)	\
+	__asm__(".section .gnu.warning.sym"); \
+	__asm__(".asciz \"msg\"");	\
+	__asm__(".previous")
+#endif	/* __STDC__ */
+#endif	/* __GNUC__ */
+
+#if 0 /*def __GNUC__ - ELF specific. */
+#define	__IDSTRING(name,string)	__asm__(".ident\t\"" string "\"")
+#else
+/*
+ * This doesn't work in header files. But it may be better than nothing.
+ * The alternative is: #define __IDSTRING(name,string)  [nothing]
+ */
+#define	__IDSTRING(name,string)	static const char name[] __unused = string
+#endif
+
+/*
+ * Embed the rcs id of a source file in the resulting library.  Note that in
+ * more recent ELF binutils, we use .ident allowing the ID to be stripped.
+ * Usage:
+ *	__FBSDID("$FreeBSD: src/sys/sys/cdefs.h,v 1.68 2002/10/21 20:50:30 mike Exp $");
+ */
+#ifndef	__FBSDID
+#if !defined(lint) && !defined(STRIP_FBSDID)
+#define	__FBSDID(s)	__IDSTRING(__CONCAT(__rcsid_,__LINE__),s)
+#else
+#define	__FBSDID(s)	struct __hack
+#endif
+#endif
+
+#ifndef	__RCSID
+#ifndef	NO__RCSID
+#define	__RCSID(s)	__IDSTRING(__CONCAT(__rcsid_,__LINE__),s)
+#else
+#define	__RCSID(s)
+#endif
+#endif
+
+#ifndef	__RCSID_SOURCE
+#ifndef	NO__RCSID_SOURCE
+#define	__RCSID_SOURCE(s)	__IDSTRING(__CONCAT(__rcsid_source_,__LINE__),s)
+#else
+#define	__RCSID_SOURCE(s)
+#endif
+#endif
+
+#ifndef	__SCCSID
+#ifndef	NO__SCCSID
+#define	__SCCSID(s)	__IDSTRING(__CONCAT(__sccsid_,__LINE__),s)
+#else
+#define	__SCCSID(s)
+#endif
+#endif
+
+#ifndef	__COPYRIGHT
+#ifndef	NO__COPYRIGHT
+#define	__COPYRIGHT(s)	__IDSTRING(__CONCAT(__copyright_,__LINE__),s)
+#else
+#define	__COPYRIGHT(s)
+#endif
+#endif
+
+#ifndef	__DECONST
+#define	__DECONST(type, var)	((type)(uintptr_t)(const void *)(var))
+#endif
+
+#ifndef	__DEVOLATILE
+#define	__DEVOLATILE(type, var)	((type)(uintptr_t)(volatile void *)(var))
+#endif
+
+#ifndef	__DEQUALIFY
+#define	__DEQUALIFY(type, var)	((type)(uintptr_t)(const volatile void *)(var))
+#endif
+
+/*-
+ * The following definitions are an extension of the behavior originally
+ * implemented in <sys/_posix.h>, but with a different level of granularity.
+ * POSIX.1 requires that the macros we test be defined before any standard
+ * header file is included.
+ *
+ * Here's a quick run-down of the versions:
+ *  defined(_POSIX_SOURCE)		1003.1-1988
+ *  _POSIX_C_SOURCE == 1		1003.1-1990
+ *  _POSIX_C_SOURCE == 2		1003.2-1992 C Language Binding Option
+ *  _POSIX_C_SOURCE == 199309		1003.1b-1993
+ *  _POSIX_C_SOURCE == 199506		1003.1c-1995, 1003.1i-1995,
+ *					and the omnibus ISO/IEC 9945-1: 1996
+ *  _POSIX_C_SOURCE == 200112		1003.1-2001
+ *
+ * In addition, the X/Open Portability Guide, which is now the Single UNIX
+ * Specification, defines a feature-test macro which indicates the version of
+ * that specification, and which subsumes _POSIX_C_SOURCE.
+ *
+ * Our macros begin with two underscores to avoid namespace screwage.
+ */
+
+/* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1. */
+#if _POSIX_C_SOURCE == 1
+#undef _POSIX_C_SOURCE		/* Probably illegal, but beyond caring now. */
+#define	_POSIX_C_SOURCE		199009
+#endif
+
+/* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2. */
+#if _POSIX_C_SOURCE == 2
+#undef _POSIX_C_SOURCE
+#define	_POSIX_C_SOURCE		199209
+#endif
+
+/* Deal with various X/Open Portability Guides and Single UNIX Spec. */
+#ifdef _XOPEN_SOURCE
+#if _XOPEN_SOURCE - 0 >= 600
+#define	__XSI_VISIBLE		600
+#undef _POSIX_C_SOURCE
+#define	_POSIX_C_SOURCE		200112
+#elif _XOPEN_SOURCE - 0 >= 500
+#define	__XSI_VISIBLE		500
+#undef _POSIX_C_SOURCE
+#define	_POSIX_C_SOURCE		199506
+#endif
+#endif
+
+/*
+ * Deal with all versions of POSIX.  The ordering relative to the tests above is
+ * important.
+ */
+#if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE)
+#define	_POSIX_C_SOURCE		198808
+#endif
+#ifdef _POSIX_C_SOURCE
+#if _POSIX_C_SOURCE >= 200112
+#define	__POSIX_VISIBLE		200112
+#define	__ISO_C_VISIBLE		1999
+#elif _POSIX_C_SOURCE >= 199506
+#define	__POSIX_VISIBLE		199506
+#define	__ISO_C_VISIBLE		1990
+#elif _POSIX_C_SOURCE >= 199309
+#define	__POSIX_VISIBLE		199309
+#define	__ISO_C_VISIBLE		1990
+#elif _POSIX_C_SOURCE >= 199209
+#define	__POSIX_VISIBLE		199209
+#define	__ISO_C_VISIBLE		1990
+#elif _POSIX_C_SOURCE >= 199009
+#define	__POSIX_VISIBLE		199009
+#define	__ISO_C_VISIBLE		1990
+#else
+#define	__POSIX_VISIBLE		198808
+#define	__ISO_C_VISIBLE		0
+#endif /* _POSIX_C_SOURCE */
+#else
+/*-
+ * Deal with _ANSI_SOURCE:
+ * If it is defined, and no other compilation environment is explicitly
+ * requested, then define our internal feature-test macros to zero.  This
+ * makes no difference to the preprocessor (undefined symbols in preprocessing
+ * expressions are defined to have value zero), but makes it more convenient for
+ * a test program to print out the values.
+ *
+ * If a program mistakenly defines _ANSI_SOURCE and some other macro such as
+ * _POSIX_C_SOURCE, we will assume that it wants the broader compilation
+ * environment (and in fact we will never get here).
+ */
+#if defined(_ANSI_SOURCE)	/* Hide almost everything. */
+#define	__POSIX_VISIBLE		0
+#define	__XSI_VISIBLE		0
+#define	__BSD_VISIBLE		0
+#define	__ISO_C_VISIBLE		1990
+#elif defined(_C99_SOURCE)	/* Localism to specify strict C99 env. */
+#define	__POSIX_VISIBLE		0
+#define	__XSI_VISIBLE		0
+#define	__BSD_VISIBLE		0
+#define	__ISO_C_VISIBLE		1999
+#else				/* Default environment: show everything. */
+#define	__POSIX_VISIBLE		200112
+#define	__XSI_VISIBLE		600
+#define	__BSD_VISIBLE		1
+#define	__ISO_C_VISIBLE		1999
+#endif
+#endif
+
+/* toolkit pollution */
+#define __TCPPROTO(args) __P(args)
+
+#endif /* !_SYS_CDEFS_H_ */
Index: trunk/src/emx/include/sys/ioctl.h
===================================================================
--- trunk/src/emx/include/sys/ioctl.h	(revision 182)
+++ trunk/src/emx/include/sys/ioctl.h	(revision 183)
@@ -8,7 +8,7 @@
 #endif
 
-#if defined (_EMX_TCPIP)
-#include <sys/so_ioctl.h>
-#endif
+#include <sys/ioccom.h>
+#include <sys/sockio.h>
+#include <sys/filio.h>
 
 #if !defined (TCGETA)
@@ -26,8 +26,4 @@
 #define _TCSADRAIN  10          /* Used internally for tcsetattr() */
 #define _TCSAFLUSH  11          /* Used internally for tcsetattr() */
-
-#if !defined (FIONREAD)
-#define FIONREAD   16
-#endif
 
 #if !defined (FGETHTYPE)
@@ -47,8 +43,4 @@
 #endif
 
-int ioctl (int, int, ...);
-
-int _ioctl (int, int, ...);
-
 #if defined (__cplusplus)
 }
Index: trunk/src/emx/include/sys/param.h
===================================================================
--- trunk/src/emx/include/sys/param.h	(revision 182)
+++ trunk/src/emx/include/sys/param.h	(revision 183)
@@ -1,6 +1,12 @@
-/* sys/param.h (emx+gcc) */
+/** @file sys/param.h
+ * BSD like sys\param.h file.
+ *
+ * TCPV40HDRS does include this file, but as we don't need to be
+ * 100% compatible we don't care.
+ */
 
 #ifndef _SYS_PARAM_H
 #define _SYS_PARAM_H
+#define _SYS_PARAM_H_ /* toolkit */
 
 #if defined (__cplusplus)
@@ -8,22 +14,160 @@
 #endif
 
-#if !defined (PAGE_SIZE)
-#define PAGE_SIZE 0x1000
+
+#if !defined (NULL)
+#if defined (__cplusplus)
+#define NULL    0
+#else
+#define NULL    ((void*)0)
+#endif
 #endif
 
-#if !defined (HZ)
+
+/** @group BSD version defines.
+ * OS2: The toolkit headers define these. Resent FreeBSD release does too.
+ * Warning! Be aware that config scripts and programs may check for these and
+ *          assume they're running on BSD. We might have to take out these
+ *          defines.
+ * @{
+ */
+/** System version - year and month */
+#ifdef TCPV40HDRS
+#define BSD     43
+#else
+#define BSD     199506
+#endif
+#ifndef TCPV40HDRS
+/** Indicate BSD4.3 features present. */
+#define BSD4_3  1
+/** Indicate BSD4.4 features present. */
+#define BSD4_4  1
+#endif
+/** @} */
+
+
+#ifndef LOCORE
+#include <types.h>
+#endif
+#include <sys/syslimits.h>
+#include <sys/signal.h>
+#include <machine/param.h>
+#include <machine/limits.h>
+
+
+/** @group  System Parameters (BSD flavored)
+ *
+ * @{ */
+#ifndef MAXCOMLEN
+/** Max command name remembered. */
+#define MAXCOMLEN       19
+#endif
+
+#ifndef MAXINTERP
+/** Max interpreter file name length (ELF?).
+ * OS2: Have no meaning. */
+#define MAXINTERP       12
+#endif
+
+#ifndef MAXLOGNAME
+/** Max login name length including terminating NULL. */
+#define MAXLOGNAME      LOGIN_NAME_MAX
+#endif
+
+#ifndef MAXUPRC
+/** Maximum simultaneous processes. */
+#define MAXUPRC         CHILD_MAX
+#endif
+
+#ifndef NCARGS
+/** Max argument size for an exec function.
+ * OS2: Assuming at least 4KB of environment gives us 0xf000 at the very best.
+ *      However we set it to 32KB which should be a safe max. */
+#define NCARGS          ARG_MAX
+#endif
+#ifndef NGROUPS
+/** Max supplemental group id's.
+ * OS2: doesn't make much sens just set it high. */
+#define NGROUPS         NGROUPS_MAX
+#endif
+
+#ifndef NOFILE
+/** Max number of open files per process.
+ * OS2: Using DosSetMaxFH the theoretical maximum should be 0xfff0 I believe.
+ */
+#define NOFILE          OPEN_MAX
+#endif
+
+#ifndef NOGROUP
+/** Marker for empty group set member.
+ * OS2: no meaning currently. */
+#define NOGROUP         0xffff
+#endif
+
+#ifndef MAXHOSTNAMELEN
+/** Max number of bytes in a hostname. */
+#define MAXHOSTNAMELEN  256
+#endif
+
+#ifndef SPECNAMELEN
+/** Max number of bytes in a devicename.
+ * OS2: no real meaning. */
+#define SPECNAMELEN     16
+#endif
+
+#ifndef MAXNAMLEN
+/** Max number of chars in a file name.
+ * BSD name for posix NAME_MAX. */
+#define MAXNAMLEN       NAME_MAX
+#endif
+
+#ifndef MAXPATHLEN
+/** Max number of chars in a path name.
+ * BSD name for posix PATH_MAX.
+ * @remark Very strict BSD kernel/user code may expect it to be a number which
+ *         is the power of two an. The OS/2 number is not a power of 2. */
+#define MAXPATHLEN      PATH_MAX
+#endif
+/** @} */
+
+
+/** @group EMX defines
+ * @{
+ */
+#ifndef HZ
+/** Frequencey of something but have no clue of what...
+ * Freebsd isn't defining this, linux is but only for the kernel sources.
+ * Considered EMX specific. */
 #define HZ        100
 #endif
+/** @} */
 
-#if !defined (MAXNAMLEN)
-#define MAXNAMLEN  260
+
+/** @group Bitmap Access
+ * The bitmaps in question is arrays if integer.
+ * @{ */
+/** number of bytes in an int */
+#define NBPW sizeof(int)
+/** Set a bit in the bitmap */
+#define setbit(Bitmap,iBit)   ( (Bitmap)[(i)/NBBY] |=   1 << ((i) % NBBY)  )
+/** Clear a bit in the bitmap */
+#define clrbit(Bitmap,iBit)   ( (Bitmap)[(i)/NBBY] &= ~(1 << ((i) % NBBY)) )
+/** Test if a bit in a bitmap is set. */
+#define isset(Bitmap,iBit)    ( (Bitmap)[(i)/NBBY]  &  (1 << ((i) % NBBY)) )
+/** Test if a bit in a bitmap is clear. */
+#define isclr(Bitmap,iBit)    (((Bitmap)[(i)/NBBY]  & 1 << ((i) % NBBY)) == 0 )
+/** @} */
+
+
+/* Handle flags of some kind... Toolkit defines it here.
+ * Freebsd headers indicates that these are KERNEL flags, but
+ * there is a chance one or two tcpip ioctls are using them. */
+#ifndef _POSIX_SOURCE
+#define FREAD   1
+#define FWRITE  2
 #endif
 
-#if !defined (MAXPATHLEN)
-#define MAXPATHLEN 260
-#endif
-
-/* Don't try to do this inline for now */
-
+#if 0 /* we don't need it, endian takes care of this */
+/* Basic byte order conversion (non-inline).
+ * Note that freebsd only does this when KERNEL is defined. */
 #if !defined (htonl)
 #define htonl(X) _swapl(X)
@@ -32,7 +176,8 @@
 #define ntohs(X) _swaps(X)
 #endif
-
 unsigned short _swaps (unsigned short _x);
 unsigned long _swapl (unsigned long _x);
+#endif
+
 
 #if defined (__cplusplus)
Index: trunk/src/emx/include/sys/select.h
===================================================================
--- trunk/src/emx/include/sys/select.h	(revision 182)
+++ trunk/src/emx/include/sys/select.h	(revision 183)
@@ -3,4 +3,5 @@
 #ifndef _SYS_SELECT_H
 #define _SYS_SELECT_H
+#define _SYS_SELECT_H_
 
 #if defined (__cplusplus)
@@ -8,34 +9,100 @@
 #endif
 
+#include <sys/cdefs.h>
+
+/** Define sigset_t here for pselect(). */
+#if !defined (_SIGSET_T)
+#define _SIGSET_T
+typedef unsigned long sigset_t;
+#endif
+
+/** Define the number of file handles in the select buffer.
+ * @remark we might wanna bump this one up a bit... */
 #if !defined (FD_SETSIZE)
-#define	FD_SETSIZE      256
+#define	FD_SETSIZE 256
 #elif FD_SETSIZE < 256
 #error FD_SETSIZE must be at least 256
 #endif
 
+/** BSD thingy to figure out the size of a bitmap array. */
+#ifndef _howmany
+#define	_howmany(a,b)       (((a) + ((b) - 1)) / (b))
+#endif
+#if defined(TCPV40HDRS) && !defined(howmany)
+#define	howmany(a,b)        (((a) + ((b) - 1)) / (b))
+#endif
+
 #if !defined (_FD_SET_T)
 #define _FD_SET_T
+/** The base type for the select file descriptor bitmap. */
+typedef unsigned long   __fd_mask;
+/** Number of bits in a byte. */
+#define NBBY        8
+/** Number of bits in a byte. */
+#define _NFDBITS    (sizeof(__fd_mask) * 8)	/* bits per mask */
+/** Select set. */
+typedef struct fd_set
+{
+    __fd_mask   __fds_bits[_howmany(FD_SETSIZE, _NFDBITS)];
+} fd_set;
 
-typedef struct _fd_set
-{
-  unsigned long fds_bits[(FD_SETSIZE+31) / 32];
-} fd_set;
+#if defined(__BSD_VISIBLE) || defined(TCPV40HDRS)
+typedef __fd_mask   fd_mask;
+#define fds_bits    __fds_bits
+#define NFDBITS     _NFDBITS
+#endif
 
 #endif
 
-#define	FD_SET(n,s)    ((s)->fds_bits[(n)/32] |=  (1L << ((n) & 0x1f)))
-#define	FD_CLR(n,s)    ((s)->fds_bits[(n)/32] &= ~(1L << ((n) & 0x1f)))
-#define	FD_ISSET(n,s)  ((s)->fds_bits[(n)/32] &   (1L << ((n) & 0x1f)))
-#define FD_ZERO(s)     (void)memset (s, 0, sizeof (*(s)))
+#ifndef FD_SET
+/** Set a bit in the select file descriptor bitmap. */
+#define	FD_SET(n,s)    ((s)->__fds_bits[(n)/_NFDBITS] |=  (1L << ((n) & (_NFDBITS - 1))))
+/** Clear a bit in the select file descriptor bitmap. */
+#define	FD_CLR(n,s)    ((s)->__fds_bits[(n)/_NFDBITS] &= ~(1L << ((n) & (_NFDBITS - 1))))
+/** Test if a bit in the select file descriptor bitmap is set. */
+#define	FD_ISSET(n,s)  ((s)->__fds_bits[(n)/_NFDBITS] &   (1L << ((n) & (_NFDBITS - 1))))
+/** Initialize the select file descriptor bitmap clearing all bits. */
+#define FD_ZERO(s)     (void)memset(s, 0, sizeof(*(s)))
+#if __BSD_VISIBLE
+/** Copy a select file descriptor bitmap. */
+#define	FD_COPY(src,trg) (void)(*(trg) = *(src))
+#endif
+#endif /* !FD_SET */
 
 struct timeval;
+int select (int, struct fd_set *, struct fd_set *, struct fd_set *, struct timeval *);
+int _select (int, struct fd_set *, struct fd_set *, struct fd_set *, struct timeval *);
+void *memset (void *, int, size_t); /* Used by FD_ZERO */
+#ifdef _LIBC_TODO
+/** A slightly different select call which have better time precision and signal support. */
+#warning int pselect(int, fd_set *, fd_set *, fd_set *, const struct timespec *, const sigset_t *);
+#endif
 
-int select (int, struct _fd_set *, struct _fd_set *, struct _fd_set *,
-    struct timeval *);
+#ifdef TCPV40HDRS
+/** This is the TCPIP v4.0 bsd styled select.
+ * Normally it's mapped to select(), but since we don't want any such
+ * confusion we don't.
+ * @remark The normal select() doesn't have socket capabilities int the sys style libc.
+ */
+int _System bsdselect(int, struct fd_set *, struct fd_set *, struct fd_set *, struct timeval *);
+#define os2_select  tcpip40_os2_select
+#endif
+/** This is the TCPIP OS/2 styled select. */
+int _System os2_select(int *, int, int, int, long);
 
-int _select (int, struct _fd_set *, struct _fd_set *, struct _fd_set *,
-    struct timeval *);
-
-void *memset (void *, int, size_t); /* Used by FD_ZERO */
+/* toolkit BSD pollution: */
+#ifndef TCPV40HDRS
+/*
+ * Used to maintain information about processes that wish to be
+ * notified when I/O becomes possible.
+ */
+#pragma pack(1)
+struct selinfo {
+        pid_t   si_pid;         /* process to be notified */
+        short   si_flags;       /* see below */
+};
+#pragma pack()
+#define SI_COLL 0x0001          /* collision occurred */
+#endif /* !TCPV40HDRS */
 
 #if defined (__cplusplus)
Index: trunk/src/emx/include/sys/so_ioctl.h
===================================================================
--- trunk/src/emx/include/sys/so_ioctl.h	(revision 182)
+++ trunk/src/emx/include/sys/so_ioctl.h	(revision 183)
@@ -1,104 +1,4 @@
-/* so_ioctl.h derived from BSD's ioctl.h by hv and em 1994,1996
- *
- * Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	from: @(#)ioctl.h	7.19 (Berkeley) 6/26/91
- */
+/* backward compatibility */
+#warning sys/so_ioctl.h is outdated, use sys/ioctl.h or sys/sockio.h.
+#include <sys/sockio.h>
 
-#if !defined (_SYS_SO_IOCTL_H)
-#define _SYS_SO_IOCTL_H
-
-#define _IOC(a,b) ((a<<8)|b)
-#define _IOW(a,b,c) _IOC(a,b)
-#define _IOR(a,b,c) _IOC(a,b)
-#define _IOWR(a,b,c) _IOC(a,b)
-
-#define _TCPIP_FIONREAD  _IOC('f', 127)
-#define FIONBIO         _IOC('f', 126)
-#define FIOASYNC        _IOC('f', 125)
-#define FIOTCPCKSUM     _IOC('f', 128)
-#define FIONSTATUS      _IOC('f', 120)
-#define FIONURG         _IOC('f', 121)
-#define	FIOBSTATUS	_IOC('f', 122)
-
-/* socket i/o controls */
-#define SIOCSHIWAT      _IOW('s',  0, int)	/* set high watermark */
-#define SIOCGHIWAT      _IOR('s',  1, int)	/* get high watermark */
-#define SIOCSLOWAT      _IOW('s',  2, int)	/* set low watermark */
-#define SIOCGLOWAT      _IOR('s',  3, int)	/* get low watermark */
-#define SIOCATMARK      _IOR('s',  7, int)	/* at oob mark? */
-#define SIOCSPGRP       _IOW('s',  8, int)	/* set process group */
-#define SIOCGPGRP       _IOR('s',  9, int)	/* get process group */
-#define	SIOCSHOSTID	_IOW('s', 10, int)	/* set hostid */
-
-/*hv Netbios IOCtls excluded here - no docs about them */
-
-#define SIOCADDRT       _IOW('r', 10, struct ortentry)	/* add route */
-#define SIOCDELRT       _IOW('r', 11, struct ortentry)	/* delete route */
-
-/* hv SIOMETRIC*RT excluded here - no docs about them (routing, nonportable) */
-/* hv SIOCREG* excluded here - no docs about them (routing, nonportable) */
-
-#define SIOCSIFADDR     _IOW('i', 12, struct ifreq)	/* set ifnet address */
-#define SIOCGIFADDR     _IOWR('i',13, struct ifreg)	/* get ifnet addres */
-#define OSIOCGIFADDR	SIOCGIFADDR
-#define SIOCSIFDSTADDR  _IOW('i', 14, struct ifreq)	/* set p-p address */
-#define SIOCGIFDSTADDR  _IOWR('i',15, struct ifreq)	/* get p-p address */
-#define OSIOCGIFDSTADDR	SIOCGIFDSTADDR
-#define SIOCSIFFLAGS    _IOW('i', 16, struct ifreq)	/* set ifnet flags */
-#define SIOCGIFFLAGS    _IOWR('i',17, struct ifreq)	/* get ifnet flags */
-#define SIOCGIFBRDADDR  _IOWR('i',18, struct ifreq)	/* get broadcast addr */
-#define OSIOCGIFBRDADDR	SIOCGIFBRDADDR
-#define SIOCSIFBRDADDR  _IOW('i', 19, struct ifreq)	/* set broadcast addr */
-#define SIOCGIFCONF     _IOWR('i',20, struct ifreq)	/* get ifnet list */
-#define OSIOCGIFCONF	SIOCGIFCONF
-#define SIOCGIFNETMASK  _IOWR('i',21, struct ifreq)	/* get net addr mask */
-#define OSIOCGIFNETMASK	SIOCGIFNETMASK
-#define SIOCSIFNETMASK  _IOW('i', 22, struct ifreq)	/* set net addr mask */
-#define SIOCGIFMETRIC   _IOWR('i',23, struct ifreq)	/* get if metric */
-#define SIOCSIFMETRIC   _IOW('i', 24, struct ifreq)	/* set if metric */
-
-#define SIOCSARP        _IOW('i', 30, struct arpreq)	/* set arp entry */
-#define SIOCGARP        _IOWR('i',31, struct arpreq)	/* get arp entry */
-#define OSIOCGARP	SIOCGARP
-#define SIOCDARP        _IOW('i', 32, struct arpreq)	/* delete arp entry */
-
-/*hv: several SIOC* excluded - no docs, nonportable */
-
-#define	SIOCADDMULTI	_IOW('i', 51, struct ifreq)	/* add m'cast addr */
-#define	SIOCDELMULTI	_IOW('i', 52, struct ifreq)	/* del m'cast addr */
-#define	SIOCMULTISBC	_IOC('i', 61)			/* use broadcast for MC */
-#define	SIOCMULTISFA	_IOC('i', 62)			/* use functional addr for MC */
-
-/* various more ioctls (netstat, slstat, iptrace) excluded, no docs */
-
-#endif /* !defined (_SYS_SO_IOCTL_H) */
Index: trunk/src/emx/include/sys/socket.h
===================================================================
--- trunk/src/emx/include/sys/socket.h	(revision 182)
+++ trunk/src/emx/include/sys/socket.h	(revision 183)
@@ -1,3 +1,4 @@
 /* Modified for emx by hv and em 1994-1997
+ * Modified for gcc/os2 by bird 2003
  *
  * Copyright (c) 1982,1985,1986,1988 Regents of the University of California.
@@ -39,10 +40,14 @@
 #define _SYS_SOCKET_H_
 
-#if !defined (_SYS_TYPES_H)
-#warning <sys/socket.h> requires <sys/types.h>
+#include <machine/ansi.h>
+#define _NO_NAMESPACE_POLLUTION
+#include <machine/param.h>
+#undef _NO_NAMESPACE_POLLUTION
+
+
+/* toolkit stuff */
 #include <sys/types.h>
-#endif
-
 #include <sys/uio.h>
+#include <sys/cdefs.h>
 
 #if defined (__cplusplus)
@@ -82,4 +87,8 @@
 #define	SO_RCV_SHUTDOWN	0x0400		/* set if shut down called for rcv */
 #define	SO_SND_SHUTDOWN	0x0800		/* set if shutdown called for send */
+#ifndef TCPV40HDRS
+#define SO_REUSEPORT    0x1000          /* allow local address & port reuse */
+#define SO_TTCP         0x2000          /* allow t/tcp on socket */
+#endif
 
 /*
@@ -90,6 +99,8 @@
 #define SO_SNDLOWAT	0x1003		/* send low-water mark */
 #define SO_RCVLOWAT	0x1004		/* receive low-water mark */
+#ifndef TCPV40HDRS
 #define SO_SNDTIMEO	0x1005		/* send timeout */
 #define SO_RCVTIMEO	0x1006		/* receive timeout */
+#endif
 #define	SO_ERROR	0x1007		/* get error status and clear */
 #define	SO_TYPE		0x1008		/* get socket type */
@@ -119,4 +130,8 @@
 #define	AF_UNSPEC	0		/* unspecified */
 #define	AF_UNIX		1		/* local to host (pipes, portals) */
+#ifndef TCPV40HDRS
+#define AF_LOCAL        AF_UNIX
+#endif
+#define AF_OS2          AF_UNIX
 #define	AF_INET		2		/* internetwork: UDP, TCP, etc. */
 #define	AF_IMPLINK	3		/* arpanet imp addresses */
@@ -124,6 +139,8 @@
 #define	AF_CHAOS	5		/* mit CHAOS protocols */
 #define	AF_NS		6		/* XEROX NS protocols */
+#ifdef TCPV40HDRS
 #define	AF_NBS		7		/* IBM: nbs protocols */
 					/* (hv: I think IBM is outdated here */
+#endif
 #define	AF_ISO		7		/* ISO protocols */
 #define	AF_OSI		AF_ISO
@@ -140,7 +157,26 @@
 #define	AF_NETBIOS	AF_NB
 
-#define	AF_OS2		AF_UNIX
-
+#ifdef TCPV40HDRS
 #define	AF_MAX		18
+#else
+#define AF_LINK         18              /* Link layer interface */
+#define pseudo_AF_XTP   19              /* eXpress Transfer Protocol (no AF) */
+#define AF_COIP         20              /* connection-oriented IP, aka ST II */
+#define AF_CNT          21              /* Computer Network Technology */
+#define pseudo_AF_RTIP  22              /* Help Identify RTIP packets */
+#define AF_IPX          23              /* Novell Internet Protocol */
+#define AF_SIP          24              /* Simple Internet Protocol */
+#define AF_INET6        24
+#define pseudo_AF_PIP   25              /* Help Identify PIP packets */
+#define AF_ROUTE        39              /* Internal Routing Protocol */
+#define AF_FWIP         40              /* firewall support */
+#define AF_IPSEC        41              /* IPSEC and encryption techniques */
+#define AF_DES          42              /* DES */
+#define AF_MD5          43
+#define AF_CDMF         44
+
+#define AF_MAX          45
+#endif
+
 
 /*
@@ -150,6 +186,12 @@
  */
 struct sockaddr {
+#ifdef TCPV40HDRS
 	u_short	sa_family;		/* address family */
 	char	sa_data[14];		/* up to 14 bytes of direct address */
+#else
+        u_char  sa_len;                 /* total length */
+        u_char  sa_family;              /* address family */
+        char    sa_data[14];            /* actually longer; address value */
+#endif
 };
 
@@ -168,4 +210,8 @@
 #define	PF_UNSPEC	AF_UNSPEC
 #define	PF_UNIX		AF_UNIX
+#ifndef TCPV40HDRS
+#define PF_LOCAL        AF_LOCAL
+#endif
+#define	PF_OS2		AF_UNIX
 #define	PF_INET		AF_INET
 #define	PF_IMPLINK	AF_IMPLINK
@@ -173,7 +219,9 @@
 #define	PF_CHAOS	AF_CHAOS
 #define	PF_NS		AF_NS
+#ifdef TCPV40HDRS
 #define	PF_NBS		AF_NBS
+#endif
 #define	PF_ISO		AF_ISO
-#define	PF_OSI		AF_ISO
+#define	PF_OSI		AF_OSI
 #define	PF_ECMA		AF_ECMA
 #define	PF_DATAKIT	AF_DATAKIT
@@ -185,13 +233,94 @@
 #define	PF_HYLINK	AF_HYLINK
 #define	PF_APPLETALK	AF_APPLETALK
+#define	PF_NETBIOS	AF_NB
 #define	PF_NB		AF_NB
-#define	PF_NETBIOS	AF_NB
-#define	PF_OS2		AF_UNIX
+#ifndef TCPV40HDRS
+#define PF_ROUTE        AF_ROUTE
+#define PF_LINK         AF_LINK
+#define PF_XTP          pseudo_AF_XTP   /* really just proto family, no AF */
+#define PF_COIP         AF_COIP
+#define PF_CNT          AF_CNT
+#define PF_SIP          AF_SIP
+#define PF_INET6        AF_INET6
+#define PF_IPX          AF_IPX          /* same format as AF_NS */
+#define PF_RTIP         pseudo_AF_FTIP  /* same format as AF_INET */
+#define PF_PIP          pseudo_AF_PIP
+#endif /* !TCPV40HDRS */
+
 #define	PF_MAX		AF_MAX
 
+
+#ifndef TCPV40HDRS
+/*
+ * Definitions for network related sysctl, CTL_NET.
+ *
+ * Second level is protocol family.
+ * Third level is protocol number.
+ *
+ * Further levels are defined by the individual families below.
+ */
+#define NET_MAXID       AF_MAX
+
+#define CTL_NET_NAMES { \
+        { 0, 0 }, \
+        { "local", CTLTYPE_NODE }, \
+        { "inet", CTLTYPE_NODE }, \
+        { "implink", CTLTYPE_NODE }, \
+        { "pup", CTLTYPE_NODE }, \
+        { "chaos", CTLTYPE_NODE }, \
+        { "xerox_ns", CTLTYPE_NODE }, \
+        { "iso", CTLTYPE_NODE }, \
+        { "emca", CTLTYPE_NODE }, \
+        { "datakit", CTLTYPE_NODE }, \
+        { "ccitt", CTLTYPE_NODE }, \
+        { "ibm_sna", CTLTYPE_NODE }, \
+        { "decnet", CTLTYPE_NODE }, \
+        { "dec_dli", CTLTYPE_NODE }, \
+        { "lat", CTLTYPE_NODE }, \
+        { "hylink", CTLTYPE_NODE }, \
+        { "appletalk", CTLTYPE_NODE }, \
+        { "netbios", CTLTYPE_NODE }, \
+        { "route", CTLTYPE_NODE }, \
+        { "link_layer", CTLTYPE_NODE }, \
+        { "xtp", CTLTYPE_NODE }, \
+        { "coip", CTLTYPE_NODE }, \
+        { "cnt", CTLTYPE_NODE }, \
+        { "rtip", CTLTYPE_NODE }, \
+        { "ipx", CTLTYPE_NODE }, \
+        { "sip", CTLTYPE_NODE }, \
+        { "pip", CTLTYPE_NODE }, \
+}
+
+/*
+ * PF_ROUTE - Routing table
+ *
+ * Three additional levels are defined:
+ *      Fourth: address family, 0 is wildcard
+ *      Fifth: type of info, defined below
+ *      Sixth: flag(s) to mask with for NET_RT_FLAGS
+ */
+#define NET_RT_DUMP     1               /* dump; may limit to a.f. */
+#define NET_RT_FLAGS    2               /* by flags, e.g. RESOLVING */
+#define NET_RT_IFLIST   3               /* survey interface list */
+#define NET_RT_MAXID    4
+
+#define CTL_NET_RT_NAMES { \
+        { 0, 0 }, \
+        { "dump", CTLTYPE_STRUCT }, \
+        { "flags", CTLTYPE_STRUCT }, \
+        { "iflist", CTLTYPE_STRUCT }, \
+}
+
+#endif /* !TCPV40HDRS */
+
+
 /*
  * Maximum queue length specifiable by listen.
  */
+#ifdef TCPV40HDRS
 #define	SOMAXCONN	5
+#else
+#define SOMAXCONN       1024
+#endif
 
 /*
@@ -201,4 +330,5 @@
 struct msghdr {
 	caddr_t	msg_name;		/* optional address */
+#ifdef TCPV40HDRS
 	int	msg_namelen;		/* size of address */
 	struct	iovec *msg_iov;		/* scatter/gather array */
@@ -206,4 +336,12 @@
 	caddr_t	msg_accrights;		/* access rights sent/received */
 	int	msg_accrightslen;
+#else
+        u_int   msg_namelen;            /* size of address */
+        struct  iovec *msg_iov;         /* scatter/gather array */
+        u_int   msg_iovlen;             /* # elements in msg_iov */
+        caddr_t msg_control;            /* ancillary data, see below */
+        u_int   msg_controllen;         /* ancillary data buffer len */
+        long    msg_flags;              /* flags on received message */
+#endif
 };
 
@@ -211,10 +349,21 @@
 #define	MSG_PEEK	0x2		/* peek at incoming message */
 #define	MSG_DONTROUTE	0x4		/* send without using routing tables */
-#define	MSG_EOR		0x8		/* data completes record */
-#define	MSG_TRUNC	0x10		/* data discarded before delivery */
-#define	MSG_CTRUNC	0x20		/* control data lost before delivery */
-#define	MSG_WAITALL	0x40		/* wait for full request or error */
-
+#define MSG_FULLREAD    0x8             /* send without using routing tables */
+#ifndef TCPV40HDRS
+#define MSG_EOR         0x10            /* data completes record */
+#define MSG_TRUNC       0x20            /* data discarded before delivery */
+#define MSG_CTRUNC      0x40            /* control data lost before delivery */
+#define MSG_WAITALL     0x80            /* wait for full request or error */
+#define MSG_DONTWAIT    0x100           /* this message should be nonblocking */
+#ifdef TTCP
+#define MSG_EOF         0x200
+#endif
+#define MSG_MAPIO       0x400           /* mem mapped io */
+#define MSG_CLOSE       0x800           /* close connection after succesful send_file */
+#endif
+
+#ifdef TCPV40HDRS
 #define	MSG_MAXIOVLEN	16
+#endif
 
 /*
@@ -246,39 +395,101 @@
 #define	SCM_RIGHTS	0x01		/* access rights (array of int) */
 
-extern	int	accept (int, struct sockaddr *, int *);
-extern	int	bind (int, __const__ struct sockaddr *, int);
-extern	int	connect (int, __const__ struct sockaddr *, int);
-extern	int	gethostid (void);
-extern	int	getpeername (int, struct sockaddr *, int *);
-extern	int	getsockname (int, struct sockaddr *, int *);
-extern	int	getsockopt (int, int, int, void *, int *);
-extern	int	listen (int, int);
-extern	int	recv (int, void *, int, int);
-extern	int	recvfrom (int, void *, int, int, struct sockaddr *, int *);
-extern	int	recvmsg (int, struct msghdr *, int);
-extern	int	send (int, __const__ void *, int, int);
-extern	int	sendto (int, __const__ void *, int, int, __const__ struct sockaddr *, int);
-extern	int	sendmsg (int, __const__ struct msghdr *, int);
-extern	int	setsockopt (int, int, int, __const__ void *, int);
-extern	int	shutdown (int, int);
-extern	int	socket (int, int, int);
-extern	int	socketpair (int, int, int, int *);
-
-extern	int	_impsockhandle (int, int);
-
-/* special IBM prototypes 
- * hv: warning: usage of these routines may interfere with EMX operation
- * usage is not recommended.
- */
-extern	void	psock_errno(__const__ char*);
-extern	int	soabort(int);
-extern	int	soclose(int);
-extern	int	sock_init(void);
-extern	int	sock_errno(void);
-extern	int	so_cancel(int);
-extern	int	getinetversion(char*);
-
-/* hv: these are new TCPIPV4 data structures. Consult IBM doc on that */
-#ifdef TCPIPV4
+#ifndef TCPV40HDRS
+/*
+ * 4.3 compat sockaddr, move to compat file later
+ */
+struct osockaddr {
+        u_short sa_family;              /* address family */
+        char    sa_data[14];            /* up to 14 bytes of direct address */
+};
+
+/*
+ * 4.3-compat message header (move to compat file later).
+ */
+struct omsghdr {
+        caddr_t msg_name;               /* optional address */
+        int     msg_namelen;            /* size of address */
+        struct  iovec *msg_iov;         /* scatter/gather array */
+        int     msg_iovlen;             /* # elements in msg_iov */
+        caddr_t msg_accrights;          /* access rights sent/received */
+        int     msg_accrightslen;
+};
+
+/*
+ * send_file parameter structure
+ */
+struct sf_parms {
+        void   *header_data;      /* ptr to header data */
+        size_t header_length;     /* size of header data */
+        int    file_handle;       /* file handle to send from */
+        size_t file_size;         /* size of file */
+        int    file_offset;       /* byte offset in file to send from */
+        size_t file_bytes;        /* bytes of file to be sent */
+        void   *trailer_data;     /* ptr to trailer data */
+        size_t trailer_length;    /* size of trailer data */
+        size_t bytes_sent;        /* bytes sent in this send_file call */
+};
+#endif
+
+int     _System accept (int, struct sockaddr *, int *);
+int     _System bind (int, __const__ struct sockaddr *, int);
+int     _System connect (int, __const__ struct sockaddr *, int);
+int     _System gethostid (void);
+int     _System getpeername (int, struct sockaddr *, int *);
+int     _System getsockname (int, struct sockaddr *, int *);
+int     _System getsockopt (int, int, int, void *, int *);
+int     _System listen (int, int);
+int     _System recv (int, void *, int, int);
+int     _System recvfrom (int, void *, int, int, struct sockaddr *, int *);
+int     _System recvmsg (int, struct msghdr *, int);
+int     _System send (int, __const__ void *, int, int);
+int     _System sendto (int, __const__ void *, int, int, __const__ struct sockaddr *, int);
+int     _System sendmsg (int, __const__ struct msghdr *, int);
+int     _System setsockopt (int, int, int, __const__ void *, int);
+int     _System shutdown (int, int);
+int     _System socket (int, int, int);
+int     _System socketpair (int, int, int, int *);
+
+/* EMX addition */
+int    _impsockhandle (int, int);
+
+#ifndef TCPV40HDRS
+int     _System accept_and_recv (long, long*, struct sockaddr *, long*, struct sockaddr*, long*, caddr_t, size_t);
+#endif
+
+/* OS/2 additions */
+void    _System addsockettolist(int);
+int     _System removesocketfromlist(int);
+#include <sys/ioccom.h>
+#ifdef TCPV40HDRS
+#include <sys/select.h>
+#endif
+int     _System sock_init( void );
+int     _System sock_errno( void );
+void    _System psock_errno( char * );
+int     _System soclose( int );
+int     _System so_cancel(int);
+int     _System Raccept(int, struct sockaddr *, int *);
+#ifdef TCPV40HDRS
+struct sockaddr_in;
+int     _System Rbind(int, struct sockaddr_in *, int, struct sockaddr_in *);
+#else
+int     _System Rbind(int, struct sockaddr *, int, struct sockaddr *);
+#endif
+int     _System Rconnect(int, const struct sockaddr *, int);
+int     _System Rgetsockname(int, struct sockaddr *, int *);
+int     _System Rlisten(int, int);
+#ifndef TCPV40HDRS
+ssize_t _System send_file(int *, struct sf_parms *, int );
+char *  _System sock_strerror(int);
+int     _System getinetversion(char *);
+#endif
+
+
+/* more OS/2 stuff. */
+#ifndef MAXSOCKETS
+#define MAXSOCKETS	2048
+#endif
+
 #define	MT_FREE		0
 #define	MT_DATA		1
@@ -305,11 +516,13 @@
 };
 
-#define MAXSOCKETS	2048
 
 struct sostats {
 	short count;
-	short socketdata[9*MAXSOCKETS];
-};
-#endif
+#ifdef TCPV40HDRS
+        short socketdata[9*MAXSOCKETS];
+#else
+        short socketdata[13*MAXSOCKETS];
+#endif
+};
 
 #if defined (__cplusplus)
Index: trunk/src/emx/include/sys/sockio.h
===================================================================
--- trunk/src/emx/include/sys/sockio.h	(revision 182)
+++ trunk/src/emx/include/sys/sockio.h	(revision 183)
@@ -1,12 +1,290 @@
-/* Copyright (c)1996 by Holger Veit
- * May be freely used with EMX 
+/*- Modified for gcc/os2 by bird 2003
+ *
+ * Copyright (c) 1982, 1986, 1990, 1993, 1994
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *	This product includes software developed by the University of
+ *	California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *	@(#)sockio.h	8.1 (Berkeley) 3/28/94
+ * $FreeBSD: src/sys/sys/sockio.h,v 1.14.2.6 2002/02/07 15:12:37 ambrisko Exp $
  */
 
-/* BSD uses this to declare some more ioctls */
-
-#ifndef _SYS_SOCKIO_H_
-#define _SYS_SOCKIO_H_
-
-#include <sys/so_ioctl.h>
+#ifndef	_SYS_SOCKIO_H_
+#define	_SYS_SOCKIO_H_
+
+#include <sys/ioccom.h>
+#include "ioccom.h"
+
+/* Socket ioctl's. */
+#ifdef TCPV40HDRS
+#define	SIOCSHIWAT	 _IOW('s',  0, int)		/* set high watermark */
+#define	SIOCGHIWAT	 _IOR('s',  1, int)		/* get high watermark */
+#define	SIOCSLOWAT	 _IOW('s',  2, int)		/* set low watermark */
+#define	SIOCGLOWAT	 _IOR('s',  3, int)		/* get low watermark */
+#endif /* TCPV40HDRS */
+#define	SIOCATMARK	 _IOR('s',  7, int)		/* at oob mark? */
+#define	SIOCSPGRP	 _IOW('s',  8, int)		/* set process group */
+#define	SIOCGPGRP	 _IOR('s',  9, int)		/* get process group */
+
+#define	SIOCADDRT	 _IOW('r', 10, struct ortentry)	/* add route */
+#define	SIOCDELRT	 _IOW('r', 11, struct ortentry)	/* delete route */
+#if 0 /* not on OS/2 */
+#define	SIOCGETVIFCNT	_IOWR('r', 15, struct sioc_vif_req)/* get vif pkt cnt */
+#define	SIOCGETSGCNT	_IOWR('r', 16, struct sioc_sg_req) /* get s,g pkt cnt */
+#endif
+
+#define	SIOCSIFADDR	 _IOW('i', 12, struct ifreq)	/* set ifnet address */
+#define	OSIOCGIFADDR	_IOWR('i', 13, struct ifreq)	/* get ifnet address */
+#ifdef TCPV40HDRS
+#define	SIOCGIFADDR	_IOWR('i', 13, struct ifreq)	/* get ifnet address */
+#else
+#define	SIOCGIFADDR	_IOWR('i', 33, struct ifreq)	/* get ifnet address */
+#endif /* TCPV40HDRS */
+#define	SIOCSIFDSTADDR	 _IOW('i', 14, struct ifreq)	/* set p-p address */
+#define	OSIOCGIFDSTADDR	_IOWR('i', 15, struct ifreq)	/* get p-p address */
+#ifdef TCPV40HDRS
+#define	SIOCGIFDSTADDR	_IOWR('i', 15, struct ifreq)	/* get p-p address */
+#else
+#define	SIOCGIFDSTADDR	_IOWR('i', 34, struct ifreq)	/* get p-p address */
+#endif /* TCPV40HDRS */
+#define	SIOCSIFFLAGS	 _IOW('i', 16, struct ifreq)	/* set ifnet flags */
+#define	SIOCGIFFLAGS	_IOWR('i', 17, struct ifreq)	/* get ifnet flags */
+#define	OSIOCGIFBRDADDR	_IOWR('i', 18, struct ifreq)	/* get broadcast addr */
+#ifdef TCPV40HDRS
+#define	SIOCGIFBRDADDR	_IOWR('i', 18, struct ifreq)	/* get broadcast addr */
+#else
+#define	SIOCGIFBRDADDR	_IOWR('i', 35, struct ifreq)	/* get broadcast addr */
+#endif /* TCPV40HDRS */
+#define	SIOCSIFBRDADDR	 _IOW('i', 19, struct ifreq)	/* set broadcast addr */
+#define	OSIOCGIFCONF	_IOWR('i', 20, struct ifconf)	/* get ifnet list */
+#ifdef TCPV40HDRS
+#define	SIOCGIFCONF	_IOWR('i', 20, struct ifconf)	/* get ifnet list */
+#else
+#define	SIOCGIFCONF	_IOWR('i', 36, struct ifconf)	/* get ifnet list */
+#endif /* TCPV40HDRS */
+#define	OSIOCGIFNETMASK	_IOWR('i', 21, struct ifreq)	/* get net addr mask */
+#ifdef TCPV40HDRS
+#define	SIOCGIFNETMASK	_IOWR('i', 21, struct ifreq)	/* get net addr mask */
+#else
+#define	SIOCGIFNETMASK	_IOWR('i', 37, struct ifreq)	/* get net addr mask */
+#endif /* TCPV40HDRS */
+#define	SIOCSIFNETMASK	 _IOW('i', 22, struct ifreq)	/* set net addr mask */
+#define	SIOCGIFMETRIC	_IOWR('i', 23, struct ifreq)	/* get IF metric */
+#define	SIOCSIFMETRIC	 _IOW('i', 24, struct ifreq)	/* set IF metric */
+
+#if 1 /* different on OS/2 */
+#define SIOCDIFADDR      _IOW('i', 64, struct ifreq)    /* delete IF addr */
+#define SIOCAIFADDR      _IOW('i', 63, struct ifaliasreq)/* add/chg IF alias */
+#else /*!OS2:*/
+#define	SIOCDIFADDR	 _IOW('i', 25, struct ifreq)	/* delete IF addr */
+#define	SIOCAIFADDR	 _IOW('i', 26, struct ifaliasreq)/* add/chg IF alias */
+#endif
+
+#if 0 /* not on OS/2 */
+#define	SIOCALIFADDR	 _IOW('i', 27, struct if_laddrreq) /* add IF addr */
+#define	SIOCGLIFADDR	_IOWR('i', 28, struct if_laddrreq) /* get IF addr */
+#define	SIOCDLIFADDR	 _IOW('i', 29, struct if_laddrreq) /* delete IF addr */
+#define	SIOCSIFCAP	 _IOW('i', 30, struct ifreq)	/* set IF features */
+#define	SIOCGIFCAP	_IOWR('i', 31, struct ifreq)	/* get IF features */
+#endif /*!OS2*/
+
+#if 1 /* different on OS/2 */
+#define SIOCADDMULTI     _IOW('i', 51, struct ifreq)    /* add m'cast addr */
+#define SIOCDELMULTI     _IOW('i', 52, struct ifreq)    /* del m'cast addr */
+#else /* !OS2: */
+#define	SIOCADDMULTI	 _IOW('i', 49, struct ifreq)	/* add m'cast addr */
+#define	SIOCDELMULTI	 _IOW('i', 50, struct ifreq)	/* del m'cast addr */
+#endif
+
+#if 1 /* different on OS/2 */
+#define SIOCGIFMTU        _IOR('i', 57, struct ifreq)   /* get IF mtu */
+#define SIOCSIFMTU        _IOW('i', 45, struct ifreq)   /* set IF mtu */
+#else
+#define	SIOCGIFMTU	_IOWR('i', 51, struct ifreq)	/* get IF mtu */
+#define	SIOCSIFMTU	 _IOW('i', 52, struct ifreq)	/* set IF mtu */
+#endif
+#if 0 /* not on OS/2 */
+#define	SIOCGIFPHYS	_IOWR('i', 53, struct ifreq)	/* get IF wire */
+#define	SIOCSIFPHYS	 _IOW('i', 54, struct ifreq)	/* set IF wire */
+#define	SIOCSIFMEDIA	_IOWR('i', 55, struct ifreq)	/* set net media */
+#define	SIOCGIFMEDIA	_IOWR('i', 56, struct ifmediareq) /* get net media */
+
+#define	SIOCSIFPHYADDR   _IOW('i', 70, struct ifaliasreq) /* set gif addres */
+#define	SIOCGIFPSRCADDR	_IOWR('i', 71, struct ifreq)	/* get gif psrc addr */
+#define	SIOCGIFPDSTADDR	_IOWR('i', 72, struct ifreq)	/* get gif pdst addr */
+#define	SIOCDIFPHYADDR	 _IOW('i', 73, struct ifreq)	/* delete gif addrs */
+#define	SIOCSLIFPHYADDR	 _IOW('i', 74, struct if_laddrreq) /* set gif addrs */
+#define	SIOCGLIFPHYADDR	_IOWR('i', 75, struct if_laddrreq) /* get gif addrs */
+
+#define	SIOCSIFGENERIC	 _IOW('i', 57, struct ifreq)	/* generic IF set op */
+#define	SIOCGIFGENERIC	_IOWR('i', 58, struct ifreq)	/* generic IF get op */
+
+#define	SIOCGIFSTATUS	_IOWR('i', 59, struct ifstat)	/* get IF status */
+#define	SIOCSIFLLADDR	 _IOW('i', 60, struct ifreq)	/* set linklevel addr */
+
+#define	SIOCGPRIVATE_0	_IOWR('i', 80, struct ifreq)	/* Linux Private + 0 */
+#define	SIOCGPRIVATE_1	_IOWR('i', 81, struct ifreq)	/* Linux Private + 1 */
+
+#define SIOCIFCREATE	_IOWR('i', 122, struct ifreq)	/* create clone if */
+#define SIOCIFDESTROY	 _IOW('i', 121, struct ifreq)	/* destroy clone if */
+#define SIOCIFGCLONERS	_IOWR('i', 120, struct if_clonereq) /* get cloners */
+#endif /*!OS2*/
+
+/* OS2 specific ioctls */
+#define SIOCSHOSTID       _IOW('s', 10, long)
+#define SIOCGNBNAME       _IOR('s', 11, long)   /* AFNB code. Not clear now */
+#define SIOCSNBNAME       _IOW('s', 12, long)   /* AFNB                     */
+#define SIOCGNCBFN        _IOR('s', 13, long)   /* AFNB                     */
+#ifndef TCPV40HDRS
+#define SIOCSSYN          _IOW('s', 14, long)   /* SYN Attack */
+#endif /* !TCPV40HDRS */
+#define SIOCSIFBRD        _IOW('i', 27, int)    /* SINGLE-rt bcst. using old # for bkw cmpt */
+#ifdef TCPV40HDRS
+#define SIOCSIFALLRTB      ioc('i', 63) /* added to configure all-route broadcst */
+#else
+#define SIOCSIFALLRTB     _IOW('i', 65, struct ifreq) /* added to configure all-route broadcst */
+#endif /* TCPV40HDRS */
+
+#define SIOCSARP          _IOW('i', 30, struct arpreq)/* set ARP entry */
+#define SIOCGARP          _IOR('i', 31, struct arpreq)
+#define SIOCDARP          _IOW('i', 32, struct arpreq)
+
+#define SIOCSIF802_3      _IOW('i', 40, struct ifreq)
+#define SIOCSIFNO802_3    _IOW('i', 41, struct ifreq)
+#define SIOCSIFNOREDIR    _IOW('i', 42, struct ifreq)
+#define SIOCSIFYESREDIR   _IOW('i', 43, struct ifreq)
+
+#define SIOCSIFFDDI       _IOW('i', 46, struct ifreq)
+#define SIOCSIFNOFDDI     _IOW('i', 47, struct ifreq)
+#define SIOCSRDBRD        _IOW('i', 48, struct ifreq)
+
+#define SIOCGARP_TR       _IOR('i', 50, struct arpreq_tr)
+#define SIOCSARP_TR       _IOW('i', 49, struct arpreq_tr)
+
+#if defined(SLBOOTP) || defined(INCL_TCPIP_ALLIOCTLS)
+/** Used to retreive unit number on serial interface. */
+#define SIOCGUNIT         _IOR('i', 70, struct ifreq)
+#endif
+
+/** To check if the interface is Valid or not */
+#define SIOCGIFVALID      _IOR('i', 75, struct ifreq)
+/** Ioctl to return bound/shld bind ifs */
+struct bndreq { short bindings; short bound; };
+#define SIOCGIFBOUND      _IOR('i', 76, struct bndreq)
+
+/** Get multicast gp. info for an interface ret list of m-cast addrs for an if */
+#define SIOCGMCAST        _IOR('i', 81, struct addrreq)
+#define SIOCMULTISBC      _IOW('i', 61, struct ifreq)   /* use broadcast to send IP multicast*/
+#define SIOCMULTISFA      _IOW('i', 62, struct ifreq)   /* use functional addr to send IP multicast*/
+
+#ifndef TCPV40HDRS
+/** block until intf change to running state */
+#define SIOCSIFRUNNINGBLK _IOW('i', 77, struct ifreq)
+#endif
+
+/* Interface Tracing Support */
+#define SIOCGIFEFLAGS     _IOR('i', 150, struct ifreq)
+#define SIOCSIFEFLAGS     _IOW('i', 151, struct ifreq)
+#define SIOCGIFTRACE      _IOR('i', 152, struct ifreq)
+#define SIOCSIFTRACE      _IOW('i', 153, struct ifreq)
+
+/* SLIP STATS */
+#define SIOCSSTAT         _IOW('i', 154, struct ifreq)
+#define SIOCGSTAT         _IOR('i', 155, struct ifreq)
+
+#ifndef TCPV40HDRS
+#define SIOCSMSL          _IOW('t', 1, long)          /* set the msl in seconds */
+#define SIOCGMSL          _IOR('t', 2, long)          /* get the msl in seconds */
+#endif
+
+/* NETSTAT stuff */
+#define SIOSTATMBUF       _IOR('n', 40, struct mbstat)
+#define SIOSTATTCP        _IOR('n', 41, struct tcpstat)
+#define SIOSTATUDP        _IOR('n', 42, struct udpstat)
+#define SIOSTATIP         _IOR('n', 43, struct ipstat)
+#define SIOSTATSO         _IOR('n', 44, char /*struct sockaddr*/)
+#ifndef TCPV40HDRS
+#define SIOSTATTCPZ       _IOR('n', 241, struct tcpstat)
+#define SIOSTATUDPZ       _IOR('n', 242, struct udpstat)
+#define SIOSTATIPZ        _IOR('n', 243, struct ipstat)
+#endif
+
+#define SIOSTATRT         _IOR('n', 45, char /*struct rtentries*/)
+#define SIOFLUSHRT        _IOW('n', 46, long)                     /* Backward compatibility */
+#define SIOSTATICMP       _IOR('n', 47, struct icmpstat)
+#ifndef TCPV40HDRS
+#define SIOSTATICMPZ      _IOR('n', 247, struct icmpstat)
+#endif
+#define SIOSTATIF         _IOR('n', 48, char /*struct ifmib*/)
+#define SIOSTATAT         _IOR('n', 49, char /*struct statatreq*/)
+#define SIOSTATARP        _IOR('n', 50, char /*struct oarptab*/)
+#define SIOSTATIF42       _IOR('n', 51, char /*struct ifmib*/)
+#define SIOSTATCNTRT      _IOR('n', 52, int)
+#define SIOSTATCNTAT      _IOR('n', 53, int)
+
+#ifndef TCPV40HDRS
+#define SIOSTATIGMP       _IOR('n', 54, struct igmpstat)  /* SNMP stuff     */
+#define SIOFLUSHRTIFP     _IOW('n', 55, long) /* delete routes on an interface */
+#define SIOSTATIGMPZ      _IOR('n', 254, struct igmpstat) /* SNMP stuff     */
+
+/** adding this ioctl() to be able to send arp request using an ioctl() */
+#define SIOCARP           _IOR('i', 156, int)
+#endif /* !TCPV40HDRS */
+
+#if defined(TCPV40HDRS) || defined(INCL_TCPIP_ALLIOCTLS)
+#define SIOMETRIC1RT    ioc('r', 12)
+#define SIOMETRIC2RT    ioc('r', 13)
+#define SIOMETRIC3RT    ioc('r', 14)
+#define SIOMETRIC4RT    ioc('r', 15)
+#define SIOCREGADDNET   ioc('r', 12)
+#define SIOCREGDELNET   ioc('r', 13)
+#define SIOCREGROUTES   ioc('r', 14)
+#define SIOCFLUSHROUTES ioc('r', 15)
+#define SIOCSIFSETSIG   ioc('i', 25)
+#define SIOCSIFCLRSIG   ioc('i', 26)
+#define SIOCGIFLOAD     ioc('i', 27)
+#define SIOCSIFFILTERSRC ioc('i', 28)
+#define SIOCGIFFILTERSRC ioc('i',29)
+#define SIOCSIFSNMPSIG  ioc('i', 33)
+#define SIOCSIFSNMPCLR  ioc('i', 34)
+#define SIOCSIFSNMPCRC  ioc('i', 35)
+#define SIOCSIFPRIORITY ioc('i', 36)
+#define SIOCGIFPRIORITY ioc('i', 37)
+#define SIOCSIFFILTERDST ioc('i', 38)
+#define SIOCGIFFILTERDST ioc('i',39)
+#define SIOCSIFSPIPE    ioc('i',71)   /* used to set pipe size on interface */
+                                      /* this is used as tcp send buffer size */
+#define SIOCSIFRPIPE    ioc('i',72)   /* used to set pipe size on interface */
+                                      /* this is used as tcp recv buffer size */
+#define SIOCSIFTCPSEG   ioc('i',73)   /* set the TCP segment size on interface*/
+#define SIOCSIFUSE576   ioc('i',74)   /* enable/disable the automatic change of mss to 576 */
+                                      /* if going through a router */
+#endif  /* TCPV40HDRS || ALL */
 
 #endif /* !_SYS_SOCKIO_H_ */
Index: trunk/src/emx/include/sys/syslimits.h
===================================================================
--- trunk/src/emx/include/sys/syslimits.h	(revision 182)
+++ trunk/src/emx/include/sys/syslimits.h	(revision 183)
@@ -57,6 +57,6 @@
 #ifndef NGROUPS_MAX
 /** Max supplemental group id's.
- * OS2: doesn't make much sens just set it high. */
-#define NGROUPS_MAX     256
+ * OS2: doesn't make much sense. Redefined in limits.h btw. */
+#define NGROUPS_MAX     0
 #endif
 
Index: trunk/src/emx/include/sys/time.h
===================================================================
--- trunk/src/emx/include/sys/time.h	(revision 182)
+++ trunk/src/emx/include/sys/time.h	(revision 183)
@@ -1,8 +1,43 @@
-/* sys/time.h (emx+gcc) */
+/* - modified for gcc/os2 by bird 2003
+ *
+ * Copyright (c) 1982, 1986, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *	This product includes software developed by the University of
+ *	California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *	@(#)time.h	8.5 (Berkeley) 5/4/95
+  */
 
-#ifndef _SYS_TIME_H
-#define _SYS_TIME_H
+#ifndef _SYS_TIME_H_
+#define _SYS_TIME_H_
 
 #include <time.h>
+#include <sys/types.h>
 
 #if defined (__cplusplus)
@@ -12,7 +47,10 @@
 #if !defined (_TIMEVAL)
 #define _TIMEVAL
+/** gettimeofday return structure */
 struct timeval
 {
+  /** seconds */
   long tv_sec;
+  /** and microseconds */
   long tv_usec;
 };
@@ -21,19 +59,112 @@
 #if !defined (_TIMEZONE)
 #define _TIMEZONE
+/** Timezone information */
 struct timezone
 {
+  /** minutes west of Greenwich */
   int tz_minuteswest;
+  /** type of dst correction. */
   int tz_dsttime;
 };
 #endif
 
-int utimes (__const__ char *, __const__ struct timeval *);
-int gettimeofday (struct timeval *, struct timezone *);
-int settimeofday (__const__ struct timeval *, __const__ struct timezone *);
+#if !defined(TCPV40HDRS) && !defined(DST_NONE)
+#define DST_NONE    0   /* not on dst */
+#define DST_USA     1   /* USA style dst. */
+#define DST_AUST    2   /* Australian style dst. */
+#define DST_WET     3   /* Western European dst. */
+#define DST_MET     4   /* Middle European dst. */
+#define DST_EET     5   /* Eastern European dst. */
+#define DST_CAN     6   /* Canada. */
+#endif  /* !TCPV40HDRS */
+
+#ifndef TCPV40HDRS
+#pragma pack(4)
+/** POSIX.4 version of timeval. */
+struct timespec {
+        time_t  ts_sec;         /* seconds */
+        long    ts_nsec;        /* and nanoseconds */
+};
+#pragma pack()
+#define TIMEVAL_TO_TIMESPEC(tv, ts) {                                   \
+        (ts)->ts_sec = (tv)->tv_sec;                                    \
+        (ts)->ts_nsec = (tv)->tv_usec * 1000;                           \
+}
+#define TIMESPEC_TO_TIMEVAL(tv, ts) {                                   \
+        (tv)->tv_sec = (ts)->ts_sec;                                    \
+        (tv)->tv_usec = (ts)->ts_nsec / 1000;                           \
+}
+
+/* Operations on timevals. */
+#define timerclear(tvp)         ((tvp)->tv_sec = (tvp)->tv_usec = 0)
+#define timerisset(tvp)         ((tvp)->tv_sec || (tvp)->tv_usec)
+#ifndef timercmp
+#define timercmp(tvp, uvp, cmp)                                         \
+        (((tvp)->tv_sec == (uvp)->tv_sec) ?                             \
+            ((tvp)->tv_usec cmp (uvp)->tv_usec) :                       \
+            ((tvp)->tv_sec cmp (uvp)->tv_sec))
+#endif
+#ifndef timeradd
+#define timeradd(tvp, uvp, vvp)						\
+	do {								\
+		(vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec;		\
+		(vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec;	\
+		if ((vvp)->tv_usec >= 1000000) {			\
+			(vvp)->tv_sec++;				\
+			(vvp)->tv_usec -= 1000000;			\
+		}							\
+	} while (0)
+#endif
+#ifdef timersub
+#define timersub(tvp, uvp, vvp)						\
+	do {								\
+		(vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec;		\
+		(vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec;	\
+		if ((vvp)->tv_usec < 0) {				\
+			(vvp)->tv_sec--;				\
+			(vvp)->tv_usec += 1000000;			\
+		}							\
+	} while (0)
+#endif
+
+/*
+ * Getkerninfo clock information structure
+ */
+struct clockinfo {
+        int     hz;             /* clock frequency */
+        int     tick;           /* micro-seconds per hz tick */
+        int     stathz;         /* statistics clock frequency */
+        int     profhz;         /* profiling clock frequency */
+};
+
+/*
+ * Names of the interval timers, and structure
+ * defining a timer setting.
+ */
+#define ITIMER_REAL     0
+#define ITIMER_VIRTUAL  1
+#define ITIMER_PROF     2
+#endif /* !TCPV40HDRS */
+
+#pragma pack(4)
+struct  itimerval {
+        struct  timeval it_interval;    /* timer interval */
+        struct  timeval it_value;       /* current value */
+};
+#pragma pack()
 
 
-int _utimes (__const__ char *, __const__ struct timeval *);
-int _gettimeofday (struct timeval *, struct timezone *);
-int _settimeofday (__const__ struct timeval *, __const__ struct timezone *);
+#if defined(TCPV40HDRS) || !defined(_POSIX_SOURCE)
+int     _System utimes (__const__ char *, __const__ struct timeval *);
+int     _System gettimeofday (struct timeval *, struct timezone *);
+int     _System settimeofday (__const__ struct timeval *, __const__ struct timezone *);
+#ifndef TCPV40HDRS
+#include <sys/cdefs.h>
+int     _System adjtime(const struct timeval *, struct timeval *);
+int     _System getitimer(int, struct itimerval *);
+int     _System setitimer(int, const struct itimerval *, struct itimerval *);
+#endif
+#endif /* TCPV40HDRS */
+
 
 #if defined (__cplusplus)
@@ -41,3 +172,3 @@
 #endif
 
-#endif /* not _SYS_TIME_H */
+#endif /* not _SYS_TIME_H_ */
Index: trunk/src/emx/include/sys/types.h
===================================================================
--- trunk/src/emx/include/sys/types.h	(revision 182)
+++ trunk/src/emx/include/sys/types.h	(revision 183)
@@ -4,7 +4,13 @@
 #define _SYS_TYPES_H
 
+/* freebsd/toolkit compatibility */
+#include <sys/cdefs.h>
+#include <sys/inttypes.h> /* includes machine/ansi.h */
+#include <machine/types.h>
+
 #if !defined (_SIZE_T)
 #define _SIZE_T
 typedef unsigned long size_t;
+#undef  _BSD_SIZE_T_
 #endif
 
@@ -12,4 +18,5 @@
 #define _SSIZE_T
 typedef int ssize_t;
+#undef  _BSD_SSIZE_T_
 #endif
 
@@ -17,4 +24,5 @@
 #define _TIME_T
 typedef unsigned long time_t;
+#undef  _BSD_TIME_T_
 #endif
 
@@ -22,4 +30,5 @@
 #define _INO_T
 typedef int ino_t;
+#undef  _BSD_INO_T_
 #endif
 
@@ -27,4 +36,5 @@
 #define _DEV_T
 typedef int dev_t;
+#undef  _BSD_DEV_T_
 #endif
 
@@ -32,4 +42,5 @@
 #define _OFF_T
 typedef long off_t;
+#undef  _BSD_OFF_T_
 #endif
 
@@ -37,4 +48,5 @@
 #define _MODE_T
 typedef int mode_t;
+#undef  _BSD_MODE_T_
 #endif
 
@@ -42,4 +54,5 @@
 #define _NLINK_T
 typedef int nlink_t;
+#undef  _BSD_NLINK_T_
 #endif
 
@@ -47,4 +60,5 @@
 #define _UID_T
 typedef int uid_t;
+#undef  _BSD_UID_T_
 #endif
 
@@ -52,4 +66,5 @@
 #define _PID_T
 typedef int pid_t;
+#undef  _BSD_PID_T_
 #endif
 
@@ -57,4 +72,5 @@
 #define _GID_T
 typedef int gid_t;
+#undef  _BSD_GID_T_
 #endif
 
@@ -62,27 +78,54 @@
 
 #if !defined (FD_SETSIZE)
-#define	FD_SETSIZE      256
-#else
-#if FD_SETSIZE < 256
- #error FD_SETSIZE must be at least 256
+#define	FD_SETSIZE 256
+#elif FD_SETSIZE < 256
+#error FD_SETSIZE must be at least 256
 #endif
+
+#ifndef _howmany
+#define	_howmany(a,b)       (((a) + ((b) - 1)) / (b))
+#endif
+#if defined(TCPV40HDRS) && !defined(howmany)
+#define	howmany(a,b)        (((a) + ((b) - 1)) / (b))
 #endif
 
 #if !defined (_FD_SET_T)
 #define _FD_SET_T
+/** The base type for the select file descriptor bitmap. */
+typedef unsigned long   __fd_mask;
+/** Number of bits in a byte. */
+#define NBBY        8
+/** Number of bits in a byte. */
+#define _NFDBITS    (sizeof(__fd_mask) * 8)	/* bits per mask */
+/** Select set. */
+typedef struct fd_set
+{
+    __fd_mask   __fds_bits[_howmany(FD_SETSIZE, _NFDBITS)];
+} fd_set;
 
-typedef struct _fd_set
-{
-  unsigned long fds_bits[(FD_SETSIZE+31) / 32];
-} fd_set;
+#if defined(__BSD_VISIBLE) || defined(TCPV40HDRS)
+typedef __fd_mask   fd_mask;
+#define fds_bits    __fds_bits
+#define NFDBITS     _NFDBITS
+#endif
 
 #endif
 
-#define	FD_SET(n,s)    ((s)->fds_bits[(n)/32] |=  (1L << ((n) & 0x1f)))
-#define	FD_CLR(n,s)    ((s)->fds_bits[(n)/32] &= ~(1L << ((n) & 0x1f)))
-#define	FD_ISSET(n,s)  ((s)->fds_bits[(n)/32] &   (1L << ((n) & 0x1f)))
-#define FD_ZERO(s)     (void)memset (s, 0, sizeof (*(s)))
+#ifndef FD_SET
+/** Set a bit in the select file descriptor bitmap. */
+#define	FD_SET(n,s)    ((s)->__fds_bits[(n)/_NFDBITS] |=  (1L << ((n) & (_NFDBITS - 1))))
+/** Clear a bit in the select file descriptor bitmap. */
+#define	FD_CLR(n,s)    ((s)->__fds_bits[(n)/_NFDBITS] &= ~(1L << ((n) & (_NFDBITS - 1))))
+/** Test if a bit in the select file descriptor bitmap is set. */
+#define	FD_ISSET(n,s)  ((s)->__fds_bits[(n)/_NFDBITS] &   (1L << ((n) & (_NFDBITS - 1))))
+/** Initialize the select file descriptor bitmap clearing all bits. */
+#define FD_ZERO(s)     (void)memset(s, 0, sizeof(*(s)))
+#if __BSD_VISIBLE
+/** Copy a select file descriptor bitmap. */
+#define	FD_COPY(src,trg) (void)(*(trg) = *(src))
+#endif
+#endif /* !FD_SET */
 
-#endif
+#endif /* !_POSIX_SOURCE */
 
 #if !defined (_POSIX_SOURCE)
@@ -94,5 +137,17 @@
 typedef char *caddr_t;
 
+/* toolkit pollution */
+#ifdef __32BIT__
+typedef int             long_int;       /* 32-bit compilers */
+#else
+typedef long int        long_int;       /* 16-bit compilers */
 #endif
 
+#endif /* not _POSIX_SOURCE */
+
+typedef __uint8_t	u_int8_t;
+typedef __uint16_t	u_int16_t;
+typedef __uint32_t	u_int32_t;
+typedef __uint64_t	u_int64_t;
+
 #endif /* not _SYS_TYPES_H */
Index: trunk/src/emx/include/sys/uio.h
===================================================================
--- trunk/src/emx/include/sys/uio.h	(revision 182)
+++ trunk/src/emx/include/sys/uio.h	(revision 183)
@@ -3,4 +3,5 @@
 #ifndef _SYS_UIO_H
 #define _SYS_UIO_H
+#define _SYS_UIO_H_ /*toolkit pollution*/
 
 #if defined (__cplusplus)
@@ -11,9 +12,14 @@
 {
   caddr_t iov_base;
+#if defined(__32BIT__) && !defined(TCPV40HDRS)
+  size_t  iov_len;
+#else
   int     iov_len;
+#endif
 };
 
+
 /* needed for sys\socket.h TCPIPV4 now */
-#ifdef TCPIPV4
+#ifdef TCPV40HDRS
 struct uio {
 	struct iovec	*uio_iov;
@@ -23,14 +29,23 @@
 	unsigned int	uio_resid;
 };
-enum	uio_rw { UIO_READ, UIO_WRITE };
+#ifndef FREAD
 #define FREAD   1
 #define FWRITE  2
 #endif
+#endif
 
-int readv (int, __const__ struct iovec *, int);
-int writev (int, __const__ struct iovec *, int);
+enum	uio_rw { UIO_READ, UIO_WRITE };
 
-int _readv (int, __const__ struct iovec *, int);
-int _writev (int, __const__ struct iovec *, int);
+#ifndef TCPV40HDRS
+/* Segment flag values. */
+enum uio_seg {
+        UIO_USERSPACE,          /* from user data space */
+        UIO_SYSSPACE,           /* from system space */
+        UIO_USERISPACE          /* from user I space */
+};
+#endif
+
+int _System readv (int, __const__ struct iovec *, int);
+int _System writev (int, __const__ struct iovec *, int);
 
 #if defined (__cplusplus)
Index: trunk/src/emx/include/sys/un.h
===================================================================
--- trunk/src/emx/include/sys/un.h	(revision 182)
+++ trunk/src/emx/include/sys/un.h	(revision 183)
@@ -1,4 +1,5 @@
 /* Copyright (c)1996 by Holger Veit
- * May be freely used with EMX 
+ * May be freely used with EMX
+ * Modified 2003 by bird
  */
 
@@ -6,8 +7,19 @@
 #define _SYS_UN_H_
 
+/** Definitions for UNIX IPC domain. */
 struct  sockaddr_un {
+#ifdef TCPV40HDRS
 	u_short	sun_family;	/* socket family: AF_UNIX */
+#else
+        u_char  sun_len;        /* sockaddr len including null */
+        u_char  sun_family;     /* AF_UNIX */
+#endif
 	char	sun_path[108];	/* path name (not used) */
 };
 
+#ifndef TCPV40HDRS
+/* actual length of an initialized sockaddr_un */
+#define SUN_LEN(su) (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path))
+#endif
+
 #endif /* !_SYS_UN_H_ */
Index: trunk/src/emx/include/types.h
===================================================================
--- trunk/src/emx/include/types.h	(revision 183)
+++ trunk/src/emx/include/types.h	(revision 183)
@@ -0,0 +1,50 @@
+/* toolkit compatibility. */
+#ifndef __TYPES_H_
+#define __TYPES_H_
+
+#include <sys/cdefs.h>
+
+/* Machine type dependent parameters. */
+#include <machine/ansi.h>
+#include <machine/types.h>
+
+#include <sys/types.h>
+
+
+#ifdef TCPV40HDRS
+
+#define NIL ((char *) 0)
+
+#define PZERO 0
+#define BSD 43
+#include <errno.h>
+/*#include <nerrno.h> */
+#include <sys/time.h>
+#include <utils.h>
+
+#define MAXHOSTNAMELEN 120
+#ifndef MAXPATHLEN
+#define MAXPATHLEN 260
+#endif
+#define MAXSOCKETS 2048
+
+#define index(string,c) strchr((string),(c))
+
+#ifndef TRUE
+#define TRUE 1
+#endif
+#ifndef FALSE
+#define FALSE 0
+#endif
+
+
+#else  /* TCPV40HDRS */
+
+/* OS/2 additions */
+#define MAXSOCKETS 32768
+#define BSDMAXSOCKETS 2048
+
+#endif /* TCPV40HDRS */
+
+#endif
+
Index: trunk/src/emx/include/unistd.h
===================================================================
--- trunk/src/emx/include/unistd.h	(revision 182)
+++ trunk/src/emx/include/unistd.h	(revision 183)
@@ -3,4 +3,5 @@
 #ifndef _UNISTD_H
 #define _UNISTD_H
+#define _UNISTD_H_ /* toolkit compatibility */
 
 #if defined (__cplusplus)
@@ -221,4 +222,19 @@
 #endif
 
+/* Toolkit compatibility */
+#include <sys/cdefs.h>
+#include <sys/types.h>
+int     _System     soclose (int);
+
+#ifndef _POSIX_SOURCE
+int     _System     gethostid (void);
+int     _System     gethostname (char *, int);
+int     _System     iruserok (unsigned long, int, const char *, const char *);
+int     _System     rcmd (char **, int, const char *, const char *, const char *, int *);
+int     _System     rresvport (int *);
+int     _System     ruserok (const char *, int, const char *, const char *);
+#include <sys/select.h>
+#endif /* !_POSIX_SOURCE */
+
 
 #if defined (__cplusplus)
Index: trunk/src/emx/include/utils.h
===================================================================
--- trunk/src/emx/include/utils.h	(revision 183)
+++ trunk/src/emx/include/utils.h	(revision 183)
@@ -0,0 +1,38 @@
+/* emx/gcc */
+#ifndef _UTILS_H_
+#define _UTILS_H_
+
+#ifdef TCPV40HDRS
+
+unsigned long   _System lswap(unsigned long);
+unsigned short  _System bswap(unsigned short);
+int             _System rexec(char **, int, char *, char *, char *, int *);
+
+/* Definition for bswap */
+#ifndef htonl
+#include <machine/endian.h>
+#endif
+
+#define ovbcopy(x,y,z)  bcopy((x),(y),(z))
+#define copyout(x,y,z)  memcpy((y),(x),(z))
+#ifndef XP_OS2_VACPP /* mozilla */
+#define strcasecmp(x,y)     strcmpi((x),(y))
+#define strncasecmp(x,y,z)  strnicmp(x,y,z)
+#endif
+
+#ifndef MIN
+#define MIN(a,b) (((a)<(b))?(a):(b))
+#define imin(x,y) MIN((x),(y))
+#define MAX(a,b) (((a)>(b))?(a):(b))
+#endif
+#ifndef min
+#define min(a,b) (((a)<(b))?(a):(b))
+#endif
+/* timercmp */
+#include <sys/time.h>
+
+#else
+int     _System rexec(char **, int, char *, char *, char *, int *);
+#endif /*TCPV40HDRS*/
+
+#endif
