diff --git a/src/xpdev/sockwrap.c b/src/xpdev/sockwrap.c index 24a46e44717eda87889afa31cde3bc296e527670..227a1b300fddcb52dcbb8ab443b369eff8908fa5 100644 --- a/src/xpdev/sockwrap.c +++ b/src/xpdev/sockwrap.c @@ -46,6 +46,90 @@ #include "sockwrap.h" /* sendsocket */ #include "filewrap.h" /* filelength */ +static socket_option_t socket_options[] = { + { "TYPE", SOL_SOCKET, SO_TYPE }, + { "DEBUG", SOL_SOCKET, SO_DEBUG }, + { "LINGER", SOL_SOCKET, SO_LINGER }, + { "SNDBUF", SOL_SOCKET, SO_SNDBUF }, + { "RCVBUF", SOL_SOCKET, SO_RCVBUF }, + { "SNDLOWAT", SOL_SOCKET, SO_SNDLOWAT }, + { "RCVLOWAT", SOL_SOCKET, SO_RCVLOWAT }, + { "SNDTIMEO", SOL_SOCKET, SO_SNDTIMEO }, + { "RCVTIMEO", SOL_SOCKET, SO_RCVTIMEO }, + { "REUSEADDR", SOL_SOCKET, SO_REUSEADDR }, + { "KEEPALIVE", SOL_SOCKET, SO_KEEPALIVE }, + { "DONTROUTE", SOL_SOCKET, SO_DONTROUTE }, + { "BROADCAST", SOL_SOCKET, SO_BROADCAST }, + { "OOBINLINE", SOL_SOCKET, SO_OOBINLINE }, +#ifdef SO_ACCEPTCONN + { "ACCEPTCONN", SOL_SOCKET, SO_ACCEPTCONN }, +#endif + + /* IPPROTO-level socket options */ + { "TCP_NODELAY", IPPROTO_TCP, TCP_NODELAY }, + /* The following are platform-specific */ +#ifdef TCP_MAXSEG + { "TCP_MAXSEG", IPPROTO_TCP, TCP_MAXSEG }, +#endif +#ifdef TCP_CORK + { "TCP_CORK", IPPROTO_TCP, TCP_CORK }, +#endif +#ifdef TCP_KEEPIDLE + { "TCP_KEEPIDLE", IPPROTO_TCP, TCP_KEEPIDLE }, +#endif +#ifdef TCP_KEEPINTVL + { "TCP_KEEPINTVL", IPPROTO_TCP, TCP_KEEPINTVL }, +#endif +#ifdef TCP_KEEPCNT + { "TCP_KEEPCNT", IPPROTO_TCP, TCP_KEEPCNT }, +#endif +#ifdef TCP_SYNCNT + { "TCP_SYNCNT", IPPROTO_TCP, TCP_SYNCNT }, +#endif +#ifdef TCP_LINGER2 + { "TCP_LINGER2", IPPROTO_TCP, TCP_LINGER2 }, +#endif +#ifdef TCP_DEFER_ACCEPT + { "TCP_DEFER_ACCEPT", IPPROTO_TCP, TCP_DEFER_ACCEPT }, +#endif +#ifdef TCP_WINDOW_CLAMP + { "TCP_WINDOW_CLAMP", IPPROTO_TCP, TCP_WINDOW_CLAMP }, +#endif +#ifdef TCP_QUICKACK + { "TCP_QUICKACK", IPPROTO_TCP, TCP_QUICKACK }, +#endif +#ifdef TCP_NOPUSH + { "TCP_NOPUSH", IPPROTO_TCP, TCP_NOPUSH }, +#endif +#ifdef TCP_NOOPT + { "TCP_NOOPT", IPPROTO_TCP, TCP_NOOPT }, +#endif + { NULL } +}; + +int getSocketOptionByName(const char* name, int* level) +{ + int i; + + if(level!=NULL) + *level=SOL_SOCKET; /* default option level */ + for(i=0;socket_options[i].name;i++) { + if(stricmp(name,socket_options[i].name)==0) { + if(level!=NULL) + *level = socket_options[i].level; + return(socket_options[i].value); + } + } + if(!isdigit(*name)) /* unknown option name */ + return(-1); + return(strtol(name,NULL,0)); +} + +socket_option_t* getSocketOptionList(void) +{ + return(socket_options); +} + int sendfilesocket(int sock, int file, long *offset, long count) { char buf[1024*16]; diff --git a/src/xpdev/sockwrap.h b/src/xpdev/sockwrap.h index d4b7158c005471f5c082d9717afc60d9f409efa7..c38634e62d4792441e0d5855056170304c18f86e 100644 --- a/src/xpdev/sockwrap.h +++ b/src/xpdev/sockwrap.h @@ -8,7 +8,7 @@ * @format.tab-size 4 (Plain Text/Source Code File Header) * * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * * * - * Copyright 2004 Rob Swindell - http://www.synchro.net/copyright.html * + * Copyright 2005 Rob Swindell - http://www.synchro.net/copyright.html * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public License * @@ -77,6 +77,12 @@ #include <errno.h> /* errno */ +typedef struct { + char* name; + int level; + int value; +} socket_option_t; + /**********************************/ /* Socket Implementation-specific */ /**********************************/ @@ -152,6 +158,10 @@ static wsa_error; extern "C" { #endif +socket_option_t* + getSocketOptionList(void); +int getSocketOptionByName(const char* name, int* level); + int sendfilesocket(int sock, int file, long *offset, long count); int recvfilesocket(int sock, int file, long *offset, long count); BOOL socket_check(SOCKET sock, BOOL* rd_p, BOOL* wr_p, DWORD timeout);