|
|
1.1 root 1: /* sockwrap.h */
2:
3: /* Berkley/WinSock socket API wrappers */
4:
1.1.1.2 ! root 5: /* $Id: sockwrap.h,v 1.38 2010/05/24 01:13:52 rswindell Exp $ */
1.1 root 6:
7: /****************************************************************************
8: * @format.tab-size 4 (Plain Text/Source Code File Header) *
9: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
10: * *
1.1.1.2 ! root 11: * Copyright 2010 Rob Swindell - http://www.synchro.net/copyright.html *
1.1 root 12: * *
13: * This library is free software; you can redistribute it and/or *
14: * modify it under the terms of the GNU Lesser General Public License *
15: * as published by the Free Software Foundation; either version 2 *
16: * of the License, or (at your option) any later version. *
17: * See the GNU Lesser General Public License for more details: lgpl.txt or *
18: * http://www.fsf.org/copyleft/lesser.html *
19: * *
20: * Anonymous FTP access to the most recent released source is available at *
21: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
22: * *
23: * Anonymous CVS access to the development source and modification history *
24: * is available at cvs.synchro.net:/cvsroot/sbbs, example: *
25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login *
26: * (just hit return, no password is necessary) *
27: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src *
28: * *
29: * For Synchronet coding style and modification guidelines, see *
30: * http://www.synchro.net/source.html *
31: * *
32: * You are encouraged to submit any modifications (preferably in Unix diff *
33: * format) via e-mail to [email protected] *
34: * *
35: * Note: If this box doesn't appear square, then you need to fix your tabs. *
36: ****************************************************************************/
37:
38: #ifndef _SOCKWRAP_H
39: #define _SOCKWRAP_H
40:
41: #include "gen_defs.h" /* BOOL */
42:
43: /***************/
44: /* OS-specific */
45: /***************/
46: #if defined(_WIN32) /* Use WinSock */
47:
48: #ifndef _WINSOCKAPI_
49: #include <winsock2.h> /* socket/bind/etc. */
50: #include <mswsock.h> /* Microsoft WinSock2 extensions */
51: /* Let's agree on a standard WinSock symbol here, people */
52: #define _WINSOCKAPI_
53: #endif
54:
55: #elif defined __unix__ /* Unix-variant */
56:
57: #include <netdb.h> /* gethostbyname */
58: #include <sys/types.h> /* For u_int32_t on FreeBSD */
59: #include <netinet/in.h> /* IPPROTO_IP */
60: /* define _BSD_SOCKLEN_T_ in order to define socklen_t on darwin */
61: #ifdef __DARWIN__
62: #define _BSD_SOCKLEN_T_ int
63: #endif
64: #include <sys/socket.h> /* socket/bind/etc. */
65: #include <sys/time.h> /* struct timeval */
66: #include <arpa/inet.h> /* inet_ntoa */
67: #include <netinet/tcp.h> /* TCP_NODELAY */
68: #include <unistd.h> /* close */
69: #if defined(__solaris__)
70: #include <sys/filio.h> /* FIONBIO */
71: #define INADDR_NONE -1L
72: #else
73: #include <sys/ioctl.h> /* FIONBIO */
74: #endif
75:
76: #endif
77:
78: #include <errno.h> /* errno */
79:
80: typedef struct {
81: char* name;
82: int type; /* Supported socket types (or 0 for unspecified) */
83: int level;
84: int value;
85: } socket_option_t;
86:
87: /**********************************/
88: /* Socket Implementation-specific */
89: /**********************************/
90: #if defined(_WINSOCKAPI_)
91:
92: #undef EINTR
93: #define EINTR (WSAEINTR-WSABASEERR)
94: #undef ENOTSOCK
95: #define ENOTSOCK (WSAENOTSOCK-WSABASEERR)
96: #undef EMSGSIZE
97: #define EMSGSIZE (WSAEMSGSIZE-WSABASEERR)
98: #undef EWOULDBLOCK
99: #define EWOULDBLOCK (WSAEWOULDBLOCK-WSABASEERR)
100:
1.1.1.2 ! root 101: #ifndef EPROTOTYPE
1.1 root 102: #define EPROTOTYPE (WSAEPROTOTYPE-WSABASEERR)
1.1.1.2 ! root 103: #endif
! 104: #ifndef ENOPROTOOPT
1.1 root 105: #define ENOPROTOOPT (WSAENOPROTOOPT-WSABASEERR)
1.1.1.2 ! root 106: #endif
! 107: #ifndef EPROTONOSUPPORT
1.1 root 108: #define EPROTONOSUPPORT (WSAEPROTONOSUPPORT-WSABASEERR)
1.1.1.2 ! root 109: #endif
! 110: #ifndef ESOCKTNOSUPPORT
1.1 root 111: #define ESOCKTNOSUPPORT (WSAESOCKTNOSUPPORT-WSABASEERR)
1.1.1.2 ! root 112: #endif
! 113: #ifndef EOPNOTSUPP
1.1 root 114: #define EOPNOTSUPP (WSAEOPNOTSUPP-WSABASEERR)
1.1.1.2 ! root 115: #endif
! 116: #ifndef EPFNOSUPPORT
1.1 root 117: #define EPFNOSUPPORT (WSAEPFNOSUPPORT-WSABASEERR)
1.1.1.2 ! root 118: #endif
! 119: #ifndef EAFNOSUPPORT
1.1 root 120: #define EAFNOSUPPORT (WSAEAFNOSUPPORT-WSABASEERR)
1.1.1.2 ! root 121: #endif
1.1 root 122:
123: #undef EADDRINUSE
124: #define EADDRINUSE (WSAEADDRINUSE-WSABASEERR)
125: #undef EADDRNOTAVAIL
126: #define EADDRNOTAVAIL (WSAEADDRNOTAVAIL-WSABASEERR)
127: #undef ECONNABORTED
128: #define ECONNABORTED (WSAECONNABORTED-WSABASEERR)
129: #undef ECONNRESET
130: #define ECONNRESET (WSAECONNRESET-WSABASEERR)
131: #undef ENOBUFS
132: #define ENOBUFS (WSAENOBUFS-WSABASEERR)
133: #undef EISCONN
134: #define EISCONN (WSAEISCONN-WSABASEERR)
135: #undef ENOTCONN
136: #define ENOTCONN (WSAENOTCONN-WSABASEERR)
137: #undef ESHUTDOWN
138: #define ESHUTDOWN (WSAESHUTDOWN-WSABASEERR)
139: #undef ETIMEDOUT
140: #define ETIMEDOUT (WSAETIMEDOUT-WSABASEERR)
141: #undef ECONNREFUSED
142: #define ECONNREFUSED (WSAECONNREFUSED-WSABASEERR)
143: #undef EINPROGRESS
144: #define EINPROGRESS (WSAEINPROGRESS-WSABASEERR)
145:
1.1.1.2 ! root 146: /* for shutdown() */
! 147: #define SHUT_RD SD_RECEIVE
! 148: #define SHUT_WR SD_SEND
! 149: #define SHUT_RDWR SD_BOTH
! 150:
1.1 root 151: #define s_addr S_un.S_addr
152:
153: #define socklen_t int
154:
155: static int wsa_error;
156: #define ERROR_VALUE ((wsa_error=WSAGetLastError())>0 ? wsa_error-WSABASEERR : wsa_error)
157: #define sendsocket(s,b,l) send(s,b,l,0)
158:
159: #else /* BSD sockets */
160:
161: /* WinSock-isms */
162: #define HOSTENT struct hostent
163: #define IN_ADDR struct in_addr
164: #define SOCKADDR struct sockaddr
165: #define SOCKADDR_IN struct sockaddr_in
166: #define LINGER struct linger
167: #define SOCKET int
168: #define SOCKET_ERROR -1
169: #define INVALID_SOCKET (SOCKET)(~0)
170: #define closesocket close
171: #define ioctlsocket ioctl
172: #define ERROR_VALUE errno
173: #define sendsocket write /* FreeBSD send() is broken */
174:
175: #ifdef __WATCOMC__
176: #define socklen_t int
177: #endif
178:
179: #endif /* __unix__ */
180:
181: #ifdef __cplusplus
182: extern "C" {
183: #endif
184:
185: socket_option_t*
186: getSocketOptionList(void);
187: int getSocketOptionByName(const char* name, int* level);
188:
1.1.1.2 ! root 189: int sendfilesocket(int sock, int file, off_t* offset, off_t count);
! 190: int recvfilesocket(int sock, int file, off_t* offset, off_t count);
1.1 root 191: BOOL socket_check(SOCKET sock, BOOL* rd_p, BOOL* wr_p, DWORD timeout);
192: int retry_bind(SOCKET s, const struct sockaddr *addr, socklen_t addrlen
193: ,uint retries, uint wait_secs, const char* prot
1.1.1.2 ! root 194: ,int (*lprintf)(int level, const char *fmt, ...));
! 195: int nonblocking_connect(SOCKET, struct sockaddr*, size_t, unsigned timeout /* seconds */);
1.1 root 196:
197: #ifdef __cplusplus
198: }
199: #endif
200:
201: #ifndef IPPORT_HTTP
1.1.1.2 ! root 202: #define IPPORT_HTTP 80
1.1 root 203: #endif
204: #ifndef IPPORT_FTP
1.1.1.2 ! root 205: #define IPPORT_FTP 21
1.1 root 206: #endif
207: #ifndef IPPORT_TELNET
1.1.1.2 ! root 208: #define IPPORT_TELNET 23
1.1 root 209: #endif
210: #ifndef IPPORT_SMTP
1.1.1.2 ! root 211: #define IPPORT_SMTP 25
1.1 root 212: #endif
213: #ifndef IPPORT_POP3
1.1.1.2 ! root 214: #define IPPORT_POP3 110
1.1 root 215: #endif
1.1.1.2 ! root 216: #ifndef IPPORT_IDENT
! 217: #define IPPORT_IDENT 113
! 218: #endif
! 219: #ifndef IPPORT_SUBMISSION
! 220: #define IPPORT_SUBMISSION 587
! 221: #endif
! 222:
1.1 root 223:
224: #endif /* Don't add anything after this line */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.