| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
#ifndef __MYSOCKET_H |
|---|
| 8 |
#define __MYSOCKET_H |
|---|
| 9 |
|
|---|
| 10 |
#include "copyrite.h" |
|---|
| 11 |
#include "config.h" |
|---|
| 12 |
#include "confmagic.h" |
|---|
| 13 |
|
|---|
| 14 |
#ifdef WIN32 |
|---|
| 15 |
#ifndef FD_SETSIZE |
|---|
| 16 |
#define FD_SETSIZE 256 |
|---|
| 17 |
#endif |
|---|
| 18 |
#include <winsock.h> |
|---|
| 19 |
#include <io.h> |
|---|
| 20 |
#undef EINTR |
|---|
| 21 |
#define EINTR WSAEINTR |
|---|
| 22 |
#define EWOULDBLOCK WSAEWOULDBLOCK |
|---|
| 23 |
#define EINPROGRESS WSAEINPROGRESS |
|---|
| 24 |
#define ETIMEDOUT WSAETIMEDOUT |
|---|
| 25 |
#define EAFNOSUPPORT WSAEAFNOSUPPORT |
|---|
| 26 |
#define ENOSPC 28 |
|---|
| 27 |
#define MAXHOSTNAMELEN 32 |
|---|
| 28 |
#pragma comment( lib, "wsock32.lib") |
|---|
| 29 |
#pragma comment( lib, "winmm.lib") |
|---|
| 30 |
#pragma comment( lib, "advapi32.lib") |
|---|
| 31 |
#endif |
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
#ifndef MAXSOCKADDR |
|---|
| 37 |
#define MAXSOCKADDR 128 |
|---|
| 38 |
#endif |
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
struct hostname_info { |
|---|
| 43 |
const char *hostname; |
|---|
| 44 |
const char *port; |
|---|
| 45 |
}; |
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
union sockaddr_u { |
|---|
| 49 |
struct sockaddr addr; |
|---|
| 50 |
char data[MAXSOCKADDR]; |
|---|
| 51 |
}; |
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
typedef unsigned short Port_t; |
|---|
| 55 |
|
|---|
| 56 |
struct hostname_info *hostname_convert(struct sockaddr *host, int len); |
|---|
| 57 |
struct hostname_info *ip_convert(struct sockaddr *host, int len); |
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
int make_socket |
|---|
| 62 |
(Port_t port, int socktype, union sockaddr_u *addr, socklen_t * len, |
|---|
| 63 |
const char *host); |
|---|
| 64 |
|
|---|
| 65 |
int make_socket_conn(const char *host, int socktype, |
|---|
| 66 |
struct sockaddr *myiterface, socklen_t myilen, Port_t port, |
|---|
| 67 |
bool nonb); |
|---|
| 68 |
int wait_for_connect(int, int); |
|---|
| 69 |
void make_nonblocking(int s); |
|---|
| 70 |
void make_blocking(int s); |
|---|
| 71 |
void set_keepalive(int s); |
|---|
| 72 |
|
|---|
| 73 |
#ifndef WIN32 |
|---|
| 74 |
#define closesocket(s) close(s) |
|---|
| 75 |
#else |
|---|
| 76 |
extern BOOL GetErrorMessage(const DWORD dwError, LPTSTR lpszError, const UINT |
|---|
| 77 |
nMaxError); |
|---|
| 78 |
#endif |
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
#ifndef HAS_GETHOSTBYNAME2 |
|---|
| 82 |
#define gethostbyname2(host, type) gethostbyname((host)) |
|---|
| 83 |
#endif |
|---|
| 84 |
|
|---|
| 85 |
#ifndef HAS_INET_PTON |
|---|
| 86 |
int inet_pton(int, const char *, void *); |
|---|
| 87 |
const char *inet_ntop(int, const void *, char *, size_t); |
|---|
| 88 |
#endif |
|---|
| 89 |
|
|---|
| 90 |
#ifndef HAS_GETADDRINFO |
|---|
| 91 |
|
|---|
| 92 |
* Everything here really belongs in <netdb.h>. |
|---|
| 93 |
* These defines are separate for now, to avoid having to modify the |
|---|
| 94 |
* system's header. |
|---|
| 95 |
*/ |
|---|
| 96 |
|
|---|
| 97 |
struct addrinfo { |
|---|
| 98 |
int ai_flags; |
|---|
| 99 |
int ai_family; |
|---|
| 100 |
int ai_socktype; |
|---|
| 101 |
int ai_protocol; |
|---|
| 102 |
size_t ai_addrlen; |
|---|
| 103 |
char *ai_canonname; |
|---|
| 104 |
struct sockaddr *ai_addr; |
|---|
| 105 |
struct addrinfo *ai_next; |
|---|
| 106 |
}; |
|---|
| 107 |
|
|---|
| 108 |
struct addrinfo; |
|---|
| 109 |
|
|---|
| 110 |
#define AI_PASSIVE 1 |
|---|
| 111 |
#define AI_CANONNAME 2 |
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
#define EAI_ADDRFAMILY 1 |
|---|
| 115 |
#define EAI_AGAIN 2 |
|---|
| 116 |
#define EAI_BADFLAGS 3 |
|---|
| 117 |
#define EAI_FAIL 4 |
|---|
| 118 |
#define EAI_FAMILY 5 |
|---|
| 119 |
#define EAI_MEMORY 6 |
|---|
| 120 |
#define EAI_NODATA 7 |
|---|
| 121 |
#define EAI_NONAME 8 |
|---|
| 122 |
#define EAI_SERVICE 9 |
|---|
| 123 |
#define EAI_SOCKTYPE 10 |
|---|
| 124 |
#define EAI_SYSTEM 11 |
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
int getaddrinfo(const char *hostname, const char *servname, |
|---|
| 128 |
const struct addrinfo *hintsp, struct addrinfo **result); |
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
void freeaddrinfo(struct addrinfo *old); |
|---|
| 132 |
|
|---|
| 133 |
#endif |
|---|
| 134 |
|
|---|
| 135 |
#ifndef HAS_GAI_STRERROR |
|---|
| 136 |
const char *gai_strerror(int errval); |
|---|
| 137 |
#endif |
|---|
| 138 |
|
|---|
| 139 |
#ifndef HAS_GETNAMEINFO |
|---|
| 140 |
#ifndef __APPLE__ |
|---|
| 141 |
|
|---|
| 142 |
#define NI_MAXHOST 1025 |
|---|
| 143 |
#define NI_MAXSERV 32 |
|---|
| 144 |
|
|---|
| 145 |
#define NI_NOFQDN 1 |
|---|
| 146 |
#define NI_NUMERICHOST 2 |
|---|
| 147 |
#define NI_NAMEREQD 4 |
|---|
| 148 |
#define NI_NUMERICSERV 8 |
|---|
| 149 |
#define NI_DGRAM 16 |
|---|
| 150 |
#endif |
|---|
| 151 |
|
|---|
| 152 |
int getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, |
|---|
| 153 |
size_t hostlen, char *serv, size_t servlen, int flags); |
|---|
| 154 |
#endif |
|---|
| 155 |
|
|---|
| 156 |
#endif |
|---|