6 #if defined(WIN32) && !defined(__CYGWIN__)
14 #include <sys/types.h>
15 #include <sys/socket.h>
17 #include <netinet/in.h>
18 #include <arpa/inet.h>
21 #include <netinet/tcp.h>
23 #include <sys/ioctl.h>
25 #include <netinet/if_ether.h>
28 #define OPENSSL_NO_KRB5
29 #include <openssl/ssl.h>
46 #define SND_RCV_SOCKET_BUF_SIZE 65536
48 #define INADDR_NONE 0xffffffff
52 #if defined(WIN32) && !defined(__CYGWIN__)
54 #define WRITE(fd,buf,len) send(fd,buf,len,0)
55 #define READ(fd,buf,len) recv(fd,buf,len,0)
56 //#define WRITE(fd,buf,len) _write(_open_osfhandle(fd, 0),buf,len)
57 //#define READ(fd,buf,len) _read(_open_osfhandle(fd, 0),buf,len)
61 #define CLOSE(x) closesocket(x)
62 #define IOCTL(x,y,z) ioctlsocket((SOCKET)x,(long)y,(unsigned long *)z)
68 #define WRITE(ssl,buf,len) write(ssl, buf, len)
70 #define WRITE(fd,buf,len) write(fd, buf, len)
73 #define READ(fd,buf,len) read(fd, buf, len)
74 #define CLOSE(x) close(x)
75 #define IOCTL(x,y,z) ioctl(x, y, z)
79 SOCK CreateAndSetupTcpSocket(const int bufsize=SND_RCV_SOCKET_BUF_SIZE,
80 const bool nodelay=true,
81 const bool nonblocking=false);
83 SOCK CreateAndSetupUdpSocket(const int bufsize=SND_RCV_SOCKET_BUF_SIZE,
84 const bool nonblocking=false);
86 SOCK CreateAndSetupUnixDomainSocket(const int bufsize=SND_RCV_SOCKET_BUF_SIZE,
87 const bool nonblocking=false);
89 int SetNoDelaySocket(const SOCK fd, const bool nodelay=true);
91 int IsSocket(const SOCK fd);
92 int IsStreamSocket(const SOCK fd);
93 int IsDatagramSocket(const SOCK fd);
96 int IsVirtualSocket(const int fd);
99 int BindSocket(const SOCK mysocket, const int myport);
100 int BindSocket(const SOCK mysocket, const unsigned adx, const int myport);
101 int BindSocket(const SOCK mysocket, const char *host_or_ip, const int myport);
102 int BindSocket(const SOCK mysocket, const char *pathname);
104 int ListenSocket(const SOCK mysocket, const int max=SOMAXCONN);
106 int ConnectToHost(const SOCK mysocket, const int hostip, const int port);
107 int ConnectToHost(const SOCK mysocket, const char *host, const int port);
108 int ConnectToPath(const SOCK mysocket, const char *pathname);
111 int Send(const SOCK fd, SSL *ssl, const char *buf, const int len, bool sendall=true);
112 int Receive(const SOCK fd, SSL *ssl, char *buf, const int len, bool recvall=true);
114 int Send(const SOCK fd, const char *buf, const int len, bool sendall=true);
115 int Receive(const SOCK fd, char *buf, const int len, bool recvall=true);
119 int SendTo(const SOCK mysocket,
120 const unsigned ip, const int port,
121 const char *buf, const int len, bool sendall=true);
122 int ReceiveFrom(const SOCK mysocket,
123 const unsigned ip, const int port,
124 char *buf, const int len, const bool recvall=true);
125 int SendTo(const SOCK mysocket,
126 const char *host_or_ip, const int port,
127 const char *buf, const int len, const bool sendall=true);
128 int ReceiveFrom(const SOCK mysocket,
129 const char *host_or_ip, const int port,
130 char *buf, const int len, const bool recvall=true);
133 int JoinMulticastGroup(const SOCK mysocket, const char *IP);
134 int JoinMulticastGroup(const SOCK mysocket, const unsigned adx);
135 int LeaveMulticastGroup(const SOCK mysocket, const char *IP);
136 int LeaveMulticastGroup(const SOCK mysocket, const unsigned adx);
137 int SetMulticastTimeToLive(const SOCK mysocket, const unsigned char ttl);
141 unsigned long GetRemoteSockAddress(SOCK sock);
142 int GetRemoteSockAddress(SOCK sock, struct sockaddr * addr);
144 unsigned long GetLocalSockAddress(SOCK sock);
145 int GetLocalSockAddress(SOCK sock, struct sockaddr * addr);
146 int GetLocalMacAddress(const string dev_name, char * buf);
147 int GetLocalMacAddress(const char * dev_name, char * buf);
148 unsigned GetMyIPAddress();
149 unsigned ToIPAddress(const char *hostname);
150 void PrintIPAddress(const unsigned adx, FILE *out=stderr);
151 void IPToHostname(const unsigned ip, char *name, const int namesize);
152 int IsValidIPMulticastAddress(const unsigned ipadx);
155 int GetOpenTcpPorts(int ** ports);
156 int GetOpenUdpPorts(int ** ports);
157 int IsPortOpen(int port_num, int proto = TCP);
160 int SetSignalHandler(const int signum, void (*handler)(int), const bool oneshot=false);
161 int IgnoreSignal(const int signum);
162 int ListenToSignal(const int signum);
165 int GetLine(SOCK fd, SSL *ssl, string &s);
166 int PutLine(SOCK fd, SSL *ssl, const string &s);
169 int GetLine(SOCK fd, string &s);
170 int PutLine(SOCK fd, const string &s);