version 1.38 | | version 1.39 |
---|
| | |
/* | | /* |
* static char *rcsid_init_c = | | * static char *rcsid_init_c = |
* "$Id: init.c,v 1.38 2005/08/27 22:10:14 akirschbaum Exp $"; | | * "$Id: init.c,v 1.39 2005/09/04 16:58:13 akirschbaum Exp $"; |
*/ | | */ |
| | |
/* | | /* |
| | |
} | | } |
init_sockets[0].fd = socket(PF_INET, SOCK_STREAM, protox->p_proto); | | init_sockets[0].fd = socket(PF_INET, SOCK_STREAM, protox->p_proto); |
if (init_sockets[0].fd == -1) { | | if (init_sockets[0].fd == -1) { |
perror("Error create new client server socket."); | | LOG(llevError, "Cannot create socket: %s\n", strerror_local(errno)); |
LOG(llevError, "Error creating socket on port\n"); | | |
exit(-1); | | exit(-1); |
} | | } |
insock.sin_family = AF_INET; | | insock.sin_family = AF_INET; |
| | |
linger_opt.l_linger = 0; | | linger_opt.l_linger = 0; |
if(setsockopt(init_sockets[0].fd,SOL_SOCKET,SO_LINGER,(char *) &linger_opt, | | if(setsockopt(init_sockets[0].fd,SOL_SOCKET,SO_LINGER,(char *) &linger_opt, |
sizeof(struct linger))) { | | sizeof(struct linger))) { |
perror("error on setsockopt LINGER"); | | LOG(llevError, "Cannot setsockopt(SO_LINGER): %s\n", strerror_local(errno)); |
LOG(llevError, "Error on setsockopt LINGER\n"); | | |
} | | } |
/* Would be nice to have an autoconf check for this. It appears that | | /* Would be nice to have an autoconf check for this. It appears that |
* these functions are both using the same calling syntax, just one | | * these functions are both using the same calling syntax, just one |
| | |
#endif | | #endif |
| | |
if(setsockopt(init_sockets[0].fd,SOL_SOCKET,SO_REUSEADDR, &tmp, sizeof(tmp))) { | | if(setsockopt(init_sockets[0].fd,SOL_SOCKET,SO_REUSEADDR, &tmp, sizeof(tmp))) { |
perror("error on setsockopt REUSEADDR"); | | LOG(llevError, "Cannot setsockopt(SO_REUSEADDR): %s\n", strerror_local(errno)); |
LOG(llevError,"error on setsockopt REUSEADDR\n"); | | |
} | | } |
} | | } |
#else | | #else |
if(setsockopt(init_sockets[0].fd,SOL_SOCKET,SO_REUSEADDR,(char *)NULL,0)) { | | if(setsockopt(init_sockets[0].fd,SOL_SOCKET,SO_REUSEADDR,(char *)NULL,0)) { |
perror("error on setsockopt REUSEADDR"); | | LOG(llevError, "Cannot setsockopt(SO_REUSEADDR): %s\n", strerror_local(errno)); |
LOG(llevError,"error on setsockopt REUSEADDR\n"); | | |
} | | } |
#endif | | #endif |
| | |
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"); | | LOG(llevError, "Cannot bind socket to port %d: %s\n", ntohs(insock.sin_port), strerror_local(errno)); |
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); |
| | |
exit(-1); | | exit(-1); |
} | | } |
if (listen(init_sockets[0].fd,5) == (-1)) { | | if (listen(init_sockets[0].fd,5) == (-1)) { |
perror("error on listen"); | | LOG(llevError, "Cannot listen on socket: %s\n", strerror_local(errno)); |
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); |