diff --git a/Quake/net_defs.h b/Quake/net_defs.h index c95eede5..a57f2eb4 100644 --- a/Quake/net_defs.h +++ b/Quake/net_defs.h @@ -24,6 +24,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. net_defs.h functions and data private to the network layer + net_sys.h and its dependencies must be included + before net_defs.h. */ #ifndef __NET_DEFS_H @@ -31,7 +33,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. struct qsockaddr { +#if defined(HAVE_SA_LEN) + unsigned char qsa_len; + unsigned char qsa_family; +#else short qsa_family; +#endif /* BSD, sockaddr */ unsigned char qsa_data[14]; }; diff --git a/Quake/net_sys.h b/Quake/net_sys.h index ec696c03..9b3dfa85 100644 --- a/Quake/net_sys.h +++ b/Quake/net_sys.h @@ -29,6 +29,8 @@ limited SDL_net functionality. */ #undef BAN_TEST +#undef HAVE_SA_LEN + #define sys_socket_t int #define INVALID_SOCKET (-1) #define SOCKET_ERROR (-1) @@ -53,11 +55,26 @@ #ifndef __NET_SYS_H__ #define __NET_SYS_H__ +#undef HAVE_SA_LEN + #include #include #include #include +#if defined(__FreeBSD__) || defined(__DragonFly__) || \ + defined(__OpenBSD__) || defined(__NetBSD__) || \ + defined(__MACOSX__) +/* struct sockaddr has unsigned char sa_len as the first member in BSD + * in BSD variants and the family member is also an unsigned char instead + * of (unsigned) short. This should matter only when PLATFORM_UNIX is + * defined. */ +#define HAVE_SA_LEN 1 +#define SA_FAM_OFFSET 1 +#else +#define SA_FAM_OFFSET 0 +#endif /* BSD, sockaddr */ + /* unix includes and compatibility macros */ #if defined(PLATFORM_UNIX) || defined(PLATFORM_AMIGA) @@ -95,6 +112,9 @@ typedef int socklen_t; #define socketerror(x) strerror((x)) +/* Verify that we defined HAVE_SA_LEN correctly: */ +typedef char _check_sockaddr[2 * (offsetof(struct sockaddr, sa_family) == SA_FAM_OFFSET) - 1]; + #endif /* end of unix stuff */ @@ -126,6 +146,9 @@ typedef SOCKET sys_socket_t; /* must #include "wsaerror.h" for this : */ #define socketerror(x) __WSAE_StrError((x)) +/* Verify that we defined HAVE_SA_LEN correctly: */ +typedef char _check_sockaddr[2 * (offsetof(struct sockaddr, sa_family) == SA_FAM_OFFSET) - 1]; + #endif /* end of windows stuff */