version 1.8 | | version 1.9 |
---|
| | |
| | |
/* | | /* |
* static char *rcsid_init_c = | | * static char *rcsid_init_c = |
* "$Id: init.c,v 1.8 2001/04/06 00:43:12 michtoen Exp $"; | | * "$Id: init.c,v 1.9 2001/04/06 19:07:59 michtoen Exp $"; |
*/ | | */ |
| | |
/* | | /* |
| | |
#ifndef __CEXTRACT__ | | #ifndef __CEXTRACT__ |
#include <sproto.h> | | #include <sproto.h> |
#endif | | #endif |
#ifndef WIN32 //---win32 exclude include files | | #ifndef WIN32 /* ---win32 exclude include files */ |
#include <sys/types.h> | | #include <sys/types.h> |
#include <sys/time.h> | | #include <sys/time.h> |
#include <sys/socket.h> | | #include <sys/socket.h> |
#include <netinet/in.h> | | #include <netinet/in.h> |
#include <netdb.h> | | #include <netdb.h> |
#endif // win32 | | #endif /* win32 */ |
| | |
#ifdef HAVE_UNISTD_H | | #ifdef HAVE_UNISTD_H |
#include <unistd.h> | | #include <unistd.h> |
| | |
int oldbufsize; | | int oldbufsize; |
int buflen=sizeof(int); | | int buflen=sizeof(int); |
| | |
#ifdef WIN32 // ***WIN32 SOCKET: init win32 non blocking socket | | #ifdef WIN32 /* ***WIN32 SOCKET: init win32 non blocking socket */ |
int temp = 1; | | int temp = 1; |
| | |
if(ioctlsocket(ns->fd, FIONBIO , &temp) == -1) | | if(ioctlsocket(ns->fd, FIONBIO , &temp) == -1) |
| | |
if (fcntl(ns->fd, F_SETFL, O_NDELAY)==-1) { | | if (fcntl(ns->fd, F_SETFL, O_NDELAY)==-1) { |
LOG(llevError,"InitConnection: Error on fcntl.\n"); | | LOG(llevError,"InitConnection: Error on fcntl.\n"); |
} | | } |
#endif // end win32 | | #endif /* end win32 */ |
| | |
if (getsockopt(ns->fd,SOL_SOCKET,SO_SNDBUF, (char*)&oldbufsize, &buflen)==-1) | | if (getsockopt(ns->fd,SOL_SOCKET,SO_SNDBUF, (char*)&oldbufsize, &buflen)==-1) |
oldbufsize=0; | | oldbufsize=0; |
| | |
struct protoent *protox; | | struct protoent *protox; |
struct linger linger_opt; | | struct linger linger_opt; |
| | |
#ifdef WIN32 // ***win32 - we init a windows socket | | #ifdef WIN32 /* ***win32 - we init a windows socket */ |
WSADATA w; | | WSADATA w; |
| | |
socket_info.max_filedescriptor = 1; // used in select, ignored in winsockets | | socket_info.max_filedescriptor = 1; /* used in select, ignored in winsockets */ |
WSAStartup (0x0101,&w); // this setup all socket stuuf | | WSAStartup (0x0101,&w); /* this setup all socket stuff */ |
// ill include no error tests here, winsocket 1.1 should always work | | /* ill include no error tests here, winsocket 1.1 should always work */ |
// except some old win95 versions without tcp/ip stack | | /* except some old win95 versions without tcp/ip stack */ |
#else // non windows | | #else /* non windows */ |
| | |
#ifdef HAVE_SYSCONF | | #ifdef HAVE_SYSCONF |
socket_info.max_filedescriptor = sysconf(_SC_OPEN_MAX); | | socket_info.max_filedescriptor = sysconf(_SC_OPEN_MAX); |
| | |
"Unable to find usable function to get max filedescriptors"; | | "Unable to find usable function to get max filedescriptors"; |
# endif | | # endif |
#endif | | #endif |
#endif // win32 | | #endif /* win32 */ |
| | |
socket_info.timeout.tv_sec = 0; | | socket_info.timeout.tv_sec = 0; |
socket_info.timeout.tv_usec = 0; | | socket_info.timeout.tv_usec = 0; |
| | |
*/ | | */ |
#if defined(__osf__) || defined(hpux) || defined(sgi) || defined(NeXT) || \ | | #if defined(__osf__) || defined(hpux) || defined(sgi) || defined(NeXT) || \ |
defined(__sun__) || defined(linux) || defined(SVR4) || defined(__FreeBSD__) || \ | | defined(__sun__) || defined(linux) || defined(SVR4) || defined(__FreeBSD__) || \ |
defined(__OpenBSD__) || defined(WIN32) // ---win32 add this here | | defined(__OpenBSD__) || defined(WIN32) /* ---win32 add this here */ |
{ | | { |
char tmp =1; | | char tmp =1; |
| | |
| | |
if (bind(init_sockets[0].fd,(struct sockaddr *)&insock,sizeof(insock)) == (-1)) { | | if (bind(init_sockets[0].fd,(struct sockaddr *)&insock,sizeof(insock)) == (-1)) { |
perror("error on bind command"); | | perror("error on bind command"); |
LOG(llevError,"error on bind command\n"); | | LOG(llevError,"error on bind command\n"); |
#ifdef WIN32 // ***win32: close() -> closesocket() | | #ifdef WIN32 /* ***win32: close() -> closesocket() */ |
shutdown(init_sockets[0].fd,SD_BOTH); | | shutdown(init_sockets[0].fd,SD_BOTH); |
closesocket(init_sockets[0].fd); | | closesocket(init_sockets[0].fd); |
#else | | #else |
close(init_sockets[0].fd); | | close(init_sockets[0].fd); |
#endif // win32 | | #endif /* win32 */ |
exit(-1); | | exit(-1); |
} | | } |
if (listen(init_sockets[0].fd,5) == (-1)) { | | if (listen(init_sockets[0].fd,5) == (-1)) { |
perror("error on listen"); | | perror("error on listen"); |
LOG(llevError,"error on listen\n"); | | LOG(llevError,"error on listen\n"); |
#ifdef WIN32 // ***win32: close() -> closesocket() | | #ifdef WIN32 /* ***win32: close() -> closesocket() */ |
shutdown(init_sockets[0].fd,SD_BOTH); | | shutdown(init_sockets[0].fd,SD_BOTH); |
closesocket(init_sockets[0].fd); | | closesocket(init_sockets[0].fd); |
#else | | #else |
close(init_sockets[0].fd); | | close(init_sockets[0].fd); |
#endif // win32 | | #endif /* win32 */ |
exit(-1); | | exit(-1); |
} | | } |
init_sockets[0].status=Ns_Add; | | init_sockets[0].status=Ns_Add; |
| | |
| | |
void free_newsocket(NewSocket *ns) | | void free_newsocket(NewSocket *ns) |
{ | | { |
#ifdef WIN32 // ***win32: closesocket in windows style | | #ifdef WIN32 /* ***win32: closesocket in windows style */ |
shutdown(ns->fd,SD_BOTH); | | shutdown(ns->fd,SD_BOTH); |
if (closesocket(ns->fd)) { | | if (closesocket(ns->fd)) { |
#else | | #else |
if (close(ns->fd)) { | | if (close(ns->fd)) { |
#endif // win32 | | #endif /* win32 */ |
| | |
#ifdef ESRV_DEBUG | | #ifdef ESRV_DEBUG |
LOG(llevDebug,"Error closing socket %d\n", ns->fd); | | LOG(llevDebug,"Error closing socket %d\n", ns->fd); |