2010-06-21 10:55:21 +00:00
|
|
|
/*
|
2012-07-07 07:15:23 +00:00
|
|
|
* net_sys.h -- common network system header.
|
2012-06-25 11:51:23 +00:00
|
|
|
* - depends on arch_def.h
|
|
|
|
* - may depend on q_stdinc.h
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007-2012 O.Sezer <sezero@users.sourceforge.net>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*
|
|
|
|
* See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2010-06-21 10:55:21 +00:00
|
|
|
|
|
|
|
#if defined(_USE_SDLNET)
|
|
|
|
|
|
|
|
/* can not use the IP banning mechanism in net_dgrm.c with
|
|
|
|
limited SDL_net functionality. */
|
|
|
|
#undef BAN_TEST
|
|
|
|
|
2010-08-09 12:20:39 +00:00
|
|
|
#undef HAVE_SA_LEN
|
|
|
|
|
2010-06-21 10:55:21 +00:00
|
|
|
#define sys_socket_t int
|
|
|
|
#define INVALID_SOCKET (-1)
|
|
|
|
#define SOCKET_ERROR (-1)
|
|
|
|
|
|
|
|
#ifndef MAXHOSTNAMELEN
|
|
|
|
#define MAXHOSTNAMELEN 256
|
|
|
|
#endif
|
|
|
|
#ifndef AF_INET
|
|
|
|
#define AF_INET 2 /* internet */
|
|
|
|
#endif
|
|
|
|
#ifndef INADDR_LOOPBACK
|
|
|
|
#define INADDR_LOOPBACK 0x7f000001 /* 127.0.0.1 */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __NET_SYS_H__
|
|
|
|
#define __NET_SYS_H__ /* the rest below are not needed. */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* _USE_SDLNET */
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __NET_SYS_H__
|
|
|
|
#define __NET_SYS_H__
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <limits.h>
|
|
|
|
|
2013-01-07 17:30:17 +00:00
|
|
|
#if defined(PLATFORM_BSD) || defined(PLATFORM_OSX) || \
|
2012-06-25 11:51:23 +00:00
|
|
|
defined(PLATFORM_AMIGA) /* bsdsocket.library */ || \
|
2012-07-07 05:09:55 +00:00
|
|
|
defined(__GNU__) /* GNU/Hurd */ || defined(__riscos__)
|
2010-08-09 12:20:39 +00:00
|
|
|
/* struct sockaddr has unsigned char sa_len as the first member in BSD
|
2010-08-09 14:03:07 +00:00
|
|
|
* variants and the family member is also an unsigned char instead of an
|
|
|
|
* unsigned short. This should matter only when PLATFORM_UNIX is defined,
|
|
|
|
* however, checking for the offset of sa_family in every platform that
|
|
|
|
* provide a struct sockaddr doesn't hurt either (see down below for the
|
|
|
|
* compile time asserts.) */
|
2012-06-25 11:51:23 +00:00
|
|
|
/* FIXME : GET RID OF THIS ABOMINATION !!! */
|
2010-08-09 12:20:39 +00:00
|
|
|
#define HAVE_SA_LEN 1
|
|
|
|
#define SA_FAM_OFFSET 1
|
|
|
|
#else
|
2010-08-09 14:03:07 +00:00
|
|
|
#undef HAVE_SA_LEN
|
2010-08-09 12:20:39 +00:00
|
|
|
#define SA_FAM_OFFSET 0
|
|
|
|
#endif /* BSD, sockaddr */
|
|
|
|
|
2010-06-21 10:55:21 +00:00
|
|
|
/* unix includes and compatibility macros */
|
2012-06-25 11:51:23 +00:00
|
|
|
#if defined(PLATFORM_UNIX) || defined(PLATFORM_RISCOS)
|
2010-06-21 10:55:21 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#if defined(__sun) || defined(sun)
|
|
|
|
#include <sys/filio.h>
|
2012-06-25 11:51:23 +00:00
|
|
|
#include <sys/sockio.h>
|
2010-06-21 10:55:21 +00:00
|
|
|
#endif /* __sunos__ */
|
2012-09-10 14:33:30 +00:00
|
|
|
#include <unistd.h>
|
2012-06-25 11:51:23 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
|
|
|
|
typedef int sys_socket_t;
|
|
|
|
#define INVALID_SOCKET (-1)
|
|
|
|
#define SOCKET_ERROR (-1)
|
|
|
|
|
2012-09-10 14:33:30 +00:00
|
|
|
#if defined(__APPLE__) && defined(SO_NKE) && !defined(SO_NOADDRERR)
|
|
|
|
/* ancient Mac OS X SDKs 10.2 and older are missing socklen_t */
|
|
|
|
typedef int socklen_t; /* defining as signed int to match the old api */
|
|
|
|
#endif /* ancient OSX SDKs */
|
|
|
|
|
2012-06-25 11:51:23 +00:00
|
|
|
#define SOCKETERRNO errno
|
|
|
|
#define ioctlsocket ioctl
|
|
|
|
#define closesocket close
|
|
|
|
#define selectsocket select
|
|
|
|
#define IOCTLARG_P(x) /* (char *) */ x
|
|
|
|
|
|
|
|
#define NET_EWOULDBLOCK EWOULDBLOCK
|
|
|
|
#define NET_ECONNREFUSED ECONNREFUSED
|
|
|
|
|
|
|
|
#define socketerror(x) strerror((x))
|
|
|
|
|
|
|
|
/* Verify that we defined HAVE_SA_LEN correctly: */
|
|
|
|
COMPILE_TIME_ASSERT(sockaddr, offsetof(struct sockaddr, sa_family) == SA_FAM_OFFSET);
|
|
|
|
|
|
|
|
#endif /* end of unix stuff */
|
|
|
|
|
|
|
|
|
|
|
|
/* amiga includes and compatibility macros */
|
|
|
|
#if defined(PLATFORM_AMIGA) /* Amiga bsdsocket.library */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <proto/exec.h>
|
2010-06-21 10:55:21 +00:00
|
|
|
#include <proto/socket.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
|
|
|
|
typedef int sys_socket_t;
|
|
|
|
#define INVALID_SOCKET (-1)
|
|
|
|
#define SOCKET_ERROR (-1)
|
|
|
|
|
2012-06-25 11:51:23 +00:00
|
|
|
#if !defined(__AROS__)
|
2010-06-21 10:55:21 +00:00
|
|
|
typedef int socklen_t;
|
2012-06-25 11:51:23 +00:00
|
|
|
#endif
|
|
|
|
typedef unsigned int in_addr_t; /* u_int32_t */
|
|
|
|
|
2010-06-21 10:55:21 +00:00
|
|
|
#define SOCKETERRNO Errno()
|
|
|
|
#define ioctlsocket IoctlSocket
|
|
|
|
#define closesocket CloseSocket
|
2012-06-25 11:51:23 +00:00
|
|
|
#define selectsocket(_N,_R,_W,_E,_T) \
|
|
|
|
WaitSelect((_N),(_R),(_W),(_E),(_T),NULL)
|
|
|
|
#define IOCTLARG_P(x) (char *) x
|
2010-06-21 10:55:21 +00:00
|
|
|
|
2011-01-12 20:10:34 +00:00
|
|
|
#define NET_EWOULDBLOCK EWOULDBLOCK
|
|
|
|
#define NET_ECONNREFUSED ECONNREFUSED
|
|
|
|
|
2010-06-21 10:55:21 +00:00
|
|
|
#define socketerror(x) strerror((x))
|
2012-06-25 11:51:23 +00:00
|
|
|
/* there is h_errno but no hstrerror() */
|
|
|
|
#define hstrerror(x) strerror((x))
|
2010-06-21 10:55:21 +00:00
|
|
|
|
2010-08-14 20:55:39 +00:00
|
|
|
/* Verify that we defined HAVE_SA_LEN correctly: */
|
|
|
|
COMPILE_TIME_ASSERT(sockaddr, offsetof(struct sockaddr, sa_family) == SA_FAM_OFFSET);
|
2010-08-09 12:20:39 +00:00
|
|
|
|
2012-06-25 11:51:23 +00:00
|
|
|
#endif /* end of amiga bsdsocket.library stuff */
|
2010-06-21 10:55:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* windows includes and compatibility macros */
|
|
|
|
#if defined(PLATFORM_WINDOWS)
|
|
|
|
|
|
|
|
/* NOTE: winsock[2].h already includes windows.h */
|
|
|
|
#if !defined(_USE_WINSOCK2)
|
|
|
|
#include <winsock.h>
|
|
|
|
#else
|
|
|
|
#include <winsock2.h>
|
|
|
|
#include <ws2tcpip.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* there is no in_addr_t on windows: define it as
|
|
|
|
the type of the S_addr of in_addr structure */
|
|
|
|
typedef u_long in_addr_t; /* uint32_t */
|
|
|
|
|
|
|
|
/* on windows, socklen_t is to be a winsock2 thing */
|
|
|
|
#if !defined(IP_MSFILTER_SIZE)
|
|
|
|
typedef int socklen_t;
|
|
|
|
#endif /* socklen_t type */
|
|
|
|
|
|
|
|
typedef SOCKET sys_socket_t;
|
|
|
|
|
2012-06-25 11:51:23 +00:00
|
|
|
#define selectsocket select
|
|
|
|
#define IOCTLARG_P(x) /* (u_long *) */ x
|
|
|
|
|
2010-06-21 10:55:21 +00:00
|
|
|
#define SOCKETERRNO WSAGetLastError()
|
2011-01-12 20:10:34 +00:00
|
|
|
#define NET_EWOULDBLOCK WSAEWOULDBLOCK
|
|
|
|
#define NET_ECONNREFUSED WSAECONNREFUSED
|
2010-06-21 10:55:21 +00:00
|
|
|
/* must #include "wsaerror.h" for this : */
|
|
|
|
#define socketerror(x) __WSAE_StrError((x))
|
|
|
|
|
2010-08-09 12:20:39 +00:00
|
|
|
/* Verify that we defined HAVE_SA_LEN correctly: */
|
2010-08-14 20:55:39 +00:00
|
|
|
COMPILE_TIME_ASSERT(sockaddr, offsetof(struct sockaddr, sa_family) == SA_FAM_OFFSET);
|
2010-08-09 12:20:39 +00:00
|
|
|
|
2010-06-21 10:55:21 +00:00
|
|
|
#endif /* end of windows stuff */
|
|
|
|
|
|
|
|
|
|
|
|
/* macros which may still be missing */
|
|
|
|
|
|
|
|
#if !defined(INADDR_NONE)
|
|
|
|
#define INADDR_NONE ((in_addr_t) 0xffffffff)
|
|
|
|
#endif /* INADDR_NONE */
|
|
|
|
|
|
|
|
#if !defined(INADDR_LOOPBACK)
|
|
|
|
#define INADDR_LOOPBACK ((in_addr_t) 0x7f000001) /* 127.0.0.1 */
|
|
|
|
#endif /* INADDR_LOOPBACK */
|
|
|
|
|
|
|
|
|
|
|
|
#if !defined(MAXHOSTNAMELEN)
|
|
|
|
/* SUSv2 guarantees that `Host names are limited to 255 bytes'.
|
|
|
|
POSIX 1003.1-2001 guarantees that `Host names (not including
|
|
|
|
the terminating NUL) are limited to HOST_NAME_MAX bytes'. */
|
|
|
|
#define MAXHOSTNAMELEN 256
|
|
|
|
#endif /* MAXHOSTNAMELEN */
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* __NET_SYS_H__ */
|
|
|
|
|