2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2004-12-04 17:54:56 +00:00
|
|
|
#ifndef NETWORK_CORE_H
|
|
|
|
#define NETWORK_CORE_H
|
|
|
|
|
|
|
|
// Network stuff has many things that needs to be included
|
|
|
|
// by default. All those things are in this file.
|
|
|
|
|
|
|
|
// =============================
|
|
|
|
// Include standard stuff per OS
|
|
|
|
|
2005-05-14 23:48:39 +00:00
|
|
|
#ifdef ENABLE_NETWORK
|
|
|
|
|
2004-12-04 17:54:56 +00:00
|
|
|
// Windows stuff
|
|
|
|
#if defined(WIN32)
|
2004-12-23 22:31:46 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#include <winsock2.h>
|
|
|
|
#include <ws2tcpip.h>
|
2004-12-23 20:23:05 +00:00
|
|
|
|
2005-03-14 19:27:19 +00:00
|
|
|
#if !(defined(__MINGW32__) || defined(__CYGWIN__))
|
2004-12-23 22:31:46 +00:00
|
|
|
// Windows has some different names for some types..
|
|
|
|
typedef SSIZE_T ssize_t;
|
2005-02-07 20:36:41 +00:00
|
|
|
typedef int socklen_t;
|
2004-12-23 22:31:46 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define GET_LAST_ERROR() WSAGetLastError()
|
|
|
|
#define EWOULDBLOCK WSAEWOULDBLOCK
|
2004-12-04 17:54:56 +00:00
|
|
|
// Windows has some different names for some types..
|
|
|
|
typedef unsigned long in_addr_t;
|
|
|
|
typedef INTERFACE_INFO IFREQ;
|
|
|
|
#endif // WIN32
|
|
|
|
|
|
|
|
// UNIX stuff
|
|
|
|
#if defined(UNIX)
|
|
|
|
# define SOCKET int
|
|
|
|
# define INVALID_SOCKET -1
|
|
|
|
typedef struct ifreq IFREQ;
|
|
|
|
# if !defined(__MORPHOS__) && !defined(__AMIGA__)
|
|
|
|
# define ioctlsocket ioctl
|
|
|
|
# if !defined(BEOS_NET_SERVER)
|
|
|
|
# define closesocket close
|
|
|
|
# endif
|
|
|
|
# define GET_LAST_ERROR() (errno)
|
|
|
|
# endif
|
|
|
|
// Need this for FIONREAD on solaris
|
|
|
|
# define BSD_COMP
|
|
|
|
|
|
|
|
// Includes needed for UNIX-like systems
|
|
|
|
# include <unistd.h>
|
|
|
|
# include <sys/ioctl.h>
|
|
|
|
# if defined(__BEOS__) && defined(BEOS_NET_SERVER)
|
|
|
|
# include <be/net/socket.h>
|
|
|
|
# include <be/kernel/OS.h> // snooze()
|
|
|
|
# include <be/net/netdb.h>
|
|
|
|
typedef unsigned long in_addr_t;
|
|
|
|
# define INADDR_NONE INADDR_BROADCAST
|
|
|
|
# else
|
|
|
|
# include <sys/socket.h>
|
|
|
|
# include <netinet/in.h>
|
|
|
|
# include <netinet/tcp.h>
|
|
|
|
# include <arpa/inet.h>
|
|
|
|
# include <net/if.h>
|
2005-02-28 22:33:31 +00:00
|
|
|
// According to glibc/NEWS, <ifaddrs.h> appeared in glibc-2.3.
|
2005-05-14 22:42:33 +00:00
|
|
|
# if !defined(__sgi__) && !defined(SUNOS) && !defined(__MORPHOS__) && !defined(__BEOS__) \
|
2005-04-13 18:36:29 +00:00
|
|
|
&& !(defined(__GLIBC__) && (__GLIBC__ <= 2) && (__GLIBC_MINOR__ <= 2)) && !defined(__dietlibc__)
|
2005-02-28 22:33:31 +00:00
|
|
|
// If for any reason ifaddrs.h does not exist on your system, comment out
|
|
|
|
// the following two lines and an alternative way will be used to fetch
|
|
|
|
// the list of IPs from the system.
|
2004-12-18 17:31:02 +00:00
|
|
|
# include <ifaddrs.h>
|
|
|
|
# define HAVE_GETIFADDRS
|
2005-02-28 22:33:31 +00:00
|
|
|
# endif
|
|
|
|
# if defined(SUNOS) || defined(__MORPHOS__) || defined(__BEOS__)
|
2004-12-18 17:31:02 +00:00
|
|
|
# define INADDR_NONE 0xffffffff
|
2005-02-28 22:33:31 +00:00
|
|
|
# endif
|
2005-01-17 13:13:11 +00:00
|
|
|
# if defined(__BEOS__) && !defined(BEOS_NET_SERVER)
|
|
|
|
// needed on Zeta
|
|
|
|
# include <sys/sockio.h>
|
|
|
|
# endif
|
2004-12-04 17:54:56 +00:00
|
|
|
# endif // BEOS_NET_SERVER
|
2004-12-23 19:23:56 +00:00
|
|
|
|
2005-05-14 23:48:39 +00:00
|
|
|
# if !defined(__BEOS__) && defined(__GLIBC__) && (__GLIBC__ <= 2) && (__GLIBC_MINOR__ <= 1)
|
2004-12-23 19:23:56 +00:00
|
|
|
typedef uint32_t in_addr_t;
|
2005-02-28 22:33:31 +00:00
|
|
|
# endif
|
2004-12-23 19:23:56 +00:00
|
|
|
|
2004-12-04 17:54:56 +00:00
|
|
|
# include <errno.h>
|
|
|
|
# include <sys/time.h>
|
|
|
|
# include <netdb.h>
|
|
|
|
#endif // UNIX
|
|
|
|
|
2005-03-06 12:26:38 +00:00
|
|
|
#ifdef __BEOS__
|
2005-03-06 16:23:32 +00:00
|
|
|
typedef int socklen_t;
|
2005-03-06 12:26:38 +00:00
|
|
|
#endif
|
|
|
|
|
2004-12-23 14:46:16 +00:00
|
|
|
// OS/2 stuff
|
|
|
|
#if defined(__OS2__)
|
|
|
|
# define SOCKET int
|
|
|
|
# define INVALID_SOCKET -1
|
|
|
|
typedef struct ifreq IFREQ;
|
|
|
|
# define ioctlsocket ioctl
|
|
|
|
# define closesocket close
|
2004-12-27 10:40:04 +00:00
|
|
|
# define GET_LAST_ERROR() (sock_errno())
|
2004-12-23 14:46:16 +00:00
|
|
|
|
|
|
|
// Includes needed for OS/2 systems
|
|
|
|
# include <types.h>
|
|
|
|
# include <unistd.h>
|
|
|
|
# include <sys/ioctl.h>
|
|
|
|
# include <sys/socket.h>
|
|
|
|
# include <netinet/in.h>
|
|
|
|
# include <netinet/tcp.h>
|
|
|
|
# include <arpa/inet.h>
|
|
|
|
# include <net/if.h>
|
|
|
|
# include <errno.h>
|
|
|
|
# include <sys/time.h>
|
|
|
|
# include <netdb.h>
|
|
|
|
# include <nerrno.h>
|
2004-12-27 10:40:04 +00:00
|
|
|
# define INADDR_NONE 0xffffffff
|
2004-12-23 14:46:16 +00:00
|
|
|
|
2005-03-15 12:21:59 +00:00
|
|
|
typedef int socklen_t;
|
2004-12-23 14:46:16 +00:00
|
|
|
typedef unsigned long in_addr_t;
|
|
|
|
#endif // OS/2
|
|
|
|
|
2004-12-04 17:54:56 +00:00
|
|
|
// MorphOS and Amiga stuff
|
|
|
|
#if defined(__MORPHOS__) || defined(__AMIGA__)
|
|
|
|
# include <exec/types.h>
|
|
|
|
# include <proto/exec.h> // required for Open/CloseLibrary()
|
|
|
|
# if defined(__MORPHOS__)
|
2004-12-22 21:12:36 +00:00
|
|
|
# include <sys/filio.h> // FIO* defines
|
|
|
|
# include <sys/sockio.h> // SIO* defines
|
2005-02-08 15:42:28 +00:00
|
|
|
# include <netinet/in.h>
|
2004-12-04 17:54:56 +00:00
|
|
|
# else // __AMIGA__
|
|
|
|
# include <proto/socket.h>
|
|
|
|
# endif
|
|
|
|
|
|
|
|
// Make the names compatible
|
|
|
|
# define closesocket(s) CloseSocket(s)
|
|
|
|
# define GET_LAST_ERROR() Errno()
|
|
|
|
# define ioctlsocket(s,request,status) IoctlSocket((LONG)s,(ULONG)request,(char*)status)
|
2004-12-22 21:12:36 +00:00
|
|
|
# define ioctl ioctlsocket
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2004-12-22 21:12:36 +00:00
|
|
|
typedef unsigned int in_addr_t;
|
2005-02-08 15:42:28 +00:00
|
|
|
typedef long socklen_t;
|
2004-12-22 21:12:36 +00:00
|
|
|
extern struct Library *SocketBase;
|
|
|
|
|
|
|
|
# ifdef __AMIGA__
|
|
|
|
// for usleep() implementation
|
|
|
|
extern struct Device *TimerBase;
|
|
|
|
extern struct MsgPort *TimerPort;
|
|
|
|
extern struct timerequest *TimerRequest;
|
|
|
|
# endif
|
2004-12-04 17:54:56 +00:00
|
|
|
#endif // __MORPHOS__ || __AMIGA__
|
|
|
|
|
2005-02-07 09:56:16 +00:00
|
|
|
static inline bool SetNonBlocking(int d)
|
|
|
|
{
|
2005-03-09 11:49:34 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
u_long nonblocking = 1;
|
|
|
|
#else
|
2005-02-07 09:56:16 +00:00
|
|
|
int nonblocking = 1;
|
2005-03-09 11:49:34 +00:00
|
|
|
#endif
|
2005-02-07 09:56:16 +00:00
|
|
|
#if defined(__BEOS__) && defined(BEOS_NET_SERVER)
|
|
|
|
return setsockopt(d, SOL_SOCKET, SO_NONBLOCK, &nonblocking, sizeof(nonblocking)) == 0;
|
|
|
|
#else
|
|
|
|
return ioctlsocket(d, FIONBIO, &nonblocking) == 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool SetNoDelay(int d)
|
|
|
|
{
|
|
|
|
// XXX should this be done at all?
|
|
|
|
#if !defined(BEOS_NET_SERVER) // not implemented on BeOS net_server
|
|
|
|
int b = 1;
|
|
|
|
// The (const char*) cast is needed for windows
|
|
|
|
return setsockopt(d, IPPROTO_TCP, TCP_NODELAY, (const char*)&b, sizeof(b)) == 0;
|
|
|
|
#else
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2005-05-14 23:48:39 +00:00
|
|
|
#endif /* ENABLE_NETWORK */
|
|
|
|
|
|
|
|
#endif /* NETWORK_CORE_H */
|