|
|
1.1 ! root 1: /* sockwrap.h */ ! 2: ! 3: /* Berkley/WinSock socket API wrappers */ ! 4: ! 5: /* $Id: sockwrap.h,v 1.30 2006/05/31 03:07:54 rswindell Exp $ */ ! 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: * * ! 11: * Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html * ! 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: ! 101: #define EPROTOTYPE (WSAEPROTOTYPE-WSABASEERR) ! 102: #define ENOPROTOOPT (WSAENOPROTOOPT-WSABASEERR) ! 103: #define EPROTONOSUPPORT (WSAEPROTONOSUPPORT-WSABASEERR) ! 104: #define ESOCKTNOSUPPORT (WSAESOCKTNOSUPPORT-WSABASEERR) ! 105: #define EOPNOTSUPP (WSAEOPNOTSUPP-WSABASEERR) ! 106: #define EPFNOSUPPORT (WSAEPFNOSUPPORT-WSABASEERR) ! 107: #define EAFNOSUPPORT (WSAEAFNOSUPPORT-WSABASEERR) ! 108: ! 109: #undef EADDRINUSE ! 110: #define EADDRINUSE (WSAEADDRINUSE-WSABASEERR) ! 111: #undef EADDRNOTAVAIL ! 112: #define EADDRNOTAVAIL (WSAEADDRNOTAVAIL-WSABASEERR) ! 113: #undef ECONNABORTED ! 114: #define ECONNABORTED (WSAECONNABORTED-WSABASEERR) ! 115: #undef ECONNRESET ! 116: #define ECONNRESET (WSAECONNRESET-WSABASEERR) ! 117: #undef ENOBUFS ! 118: #define ENOBUFS (WSAENOBUFS-WSABASEERR) ! 119: #undef EISCONN ! 120: #define EISCONN (WSAEISCONN-WSABASEERR) ! 121: #undef ENOTCONN ! 122: #define ENOTCONN (WSAENOTCONN-WSABASEERR) ! 123: #undef ESHUTDOWN ! 124: #define ESHUTDOWN (WSAESHUTDOWN-WSABASEERR) ! 125: #undef ETIMEDOUT ! 126: #define ETIMEDOUT (WSAETIMEDOUT-WSABASEERR) ! 127: #undef ECONNREFUSED ! 128: #define ECONNREFUSED (WSAECONNREFUSED-WSABASEERR) ! 129: #undef EINPROGRESS ! 130: #define EINPROGRESS (WSAEINPROGRESS-WSABASEERR) ! 131: ! 132: #define s_addr S_un.S_addr ! 133: ! 134: #define socklen_t int ! 135: ! 136: static int wsa_error; ! 137: #define ERROR_VALUE ((wsa_error=WSAGetLastError())>0 ? wsa_error-WSABASEERR : wsa_error) ! 138: #define sendsocket(s,b,l) send(s,b,l,0) ! 139: ! 140: #else /* BSD sockets */ ! 141: ! 142: /* WinSock-isms */ ! 143: #define HOSTENT struct hostent ! 144: #define IN_ADDR struct in_addr ! 145: #define SOCKADDR struct sockaddr ! 146: #define SOCKADDR_IN struct sockaddr_in ! 147: #define LINGER struct linger ! 148: #define SOCKET int ! 149: #define SOCKET_ERROR -1 ! 150: #define INVALID_SOCKET (SOCKET)(~0) ! 151: #define closesocket close ! 152: #define ioctlsocket ioctl ! 153: #define ERROR_VALUE errno ! 154: #define sendsocket write /* FreeBSD send() is broken */ ! 155: ! 156: #ifdef __WATCOMC__ ! 157: #define socklen_t int ! 158: #endif ! 159: ! 160: #endif /* __unix__ */ ! 161: ! 162: #ifdef __cplusplus ! 163: extern "C" { ! 164: #endif ! 165: ! 166: socket_option_t* ! 167: getSocketOptionList(void); ! 168: int getSocketOptionByName(const char* name, int* level); ! 169: ! 170: int sendfilesocket(int sock, int file, long *offset, long count); ! 171: int recvfilesocket(int sock, int file, long *offset, long count); ! 172: BOOL socket_check(SOCKET sock, BOOL* rd_p, BOOL* wr_p, DWORD timeout); ! 173: int retry_bind(SOCKET s, const struct sockaddr *addr, socklen_t addrlen ! 174: ,uint retries, uint wait_secs, const char* prot ! 175: ,int (*lprintf)(int level, char *fmt, ...)); ! 176: ! 177: #ifdef __cplusplus ! 178: } ! 179: #endif ! 180: ! 181: #ifndef SHUT_RDWR ! 182: #define SHUT_RDWR 2 /* for shutdown() */ ! 183: #endif ! 184: ! 185: #ifndef IPPORT_HTTP ! 186: #define IPPORT_HTTP 80 ! 187: #endif ! 188: #ifndef IPPORT_FTP ! 189: #define IPPORT_FTP 21 ! 190: #endif ! 191: #ifndef IPPORT_TELNET ! 192: #define IPPORT_TELNET 23 ! 193: #endif ! 194: #ifndef IPPORT_SMTP ! 195: #define IPPORT_SMTP 25 ! 196: #endif ! 197: #ifndef IPPORT_POP3 ! 198: #define IPPORT_POP3 110 ! 199: #endif ! 200: ! 201: #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.