45 #include <sys/types.h>
47 #include <sys/socket.h>
48 #include <netinet/in.h>
56 #ifdef HAVE_ARPA_INET_H
57 #include <arpa/inet.h>
84 if (ioctlsocket(ns->
fd, FIONBIO , &temp) == -1)
85 LOG(
llevError,
"init_connection: Error on ioctlsocket.\n");
87 if (fcntl(ns->
fd, F_SETFL, O_NONBLOCK) == -1) {
92 if (getsockopt(ns->
fd, SOL_SOCKET, SO_SNDBUF, (
char *)&oldbufsize, &buflen) == -1)
94 if (oldbufsize < bufsize) {
96 LOG(
llevDebug,
"Default buffer size was %d bytes, will reset it to %d\n", oldbufsize, bufsize);
98 if (setsockopt(ns->
fd, SOL_SOCKET, SO_SNDBUF, (
char *)&bufsize,
sizeof(bufsize))) {
99 LOG(
llevError,
"init_connection: setsockopt unable to set output buf size to %d\n", bufsize);
102 buflen =
sizeof(oldbufsize);
103 getsockopt(ns->
fd, SOL_SOCKET, SO_SNDBUF, (
char *)&oldbufsize, &buflen);
105 LOG(
llevDebug,
"Socket buffer size now %d bytes\n", oldbufsize);
174 struct sockaddr_in insock;
175 struct protoent *protox;
176 struct linger linger_opt;
183 WSAStartup(0x0101, &w);
191 # ifdef HAVE_GETDTABLESIZE
194 "Unable to find usable function to get max filedescriptors";
199 socket_info.
timeout.tv_sec = 0;
200 socket_info.
timeout.tv_usec = 0;
216 protox = getprotobyname(
"tcp");
217 if (protox == NULL) {
221 init_sockets[0].
fd = socket(PF_INET, SOCK_STREAM, protox->p_proto);
222 if (init_sockets[0].fd == -1) {
226 insock.sin_family = AF_INET;
228 insock.sin_addr.s_addr = htonl(INADDR_ANY);
230 linger_opt.l_onoff = 0;
231 linger_opt.l_linger = 0;
232 if (setsockopt(init_sockets[0].fd, SOL_SOCKET, SO_LINGER, (
char *)&linger_opt,
sizeof(
struct linger))) {
239 #if defined(__osf__) || defined(hpux) || defined(sgi) || defined(NeXT) || \
240 defined(__sun__) || defined(__linux__) || defined(SVR4) || \
241 defined(__FreeBSD__) || defined(__OpenBSD__) || \
251 if (setsockopt(init_sockets[0].fd, SOL_SOCKET, SO_REUSEADDR, &tmp,
sizeof(tmp))) {
256 if (setsockopt(init_sockets[0].fd, SOL_SOCKET, SO_REUSEADDR, (
char *)NULL, 0)) {
261 if (bind(init_sockets[0].fd, (
struct sockaddr *)&insock,
sizeof(insock)) == (-1)) {
264 shutdown(init_sockets[0].fd, SD_BOTH);
265 closesocket(init_sockets[0].fd);
267 close(init_sockets[0].fd);
271 if (listen(init_sockets[0].fd, 5) == (-1)) {
274 shutdown(init_sockets[0].fd, SD_BOTH);
275 closesocket(init_sockets[0].fd);
277 close(init_sockets[0].fd);
293 LOG(
llevDebug,
"Freeing all new client/server information.\n");
307 shutdown(ns->
fd, SD_BOTH);
308 if (closesocket(ns->
fd)) {
void SockList_AddPrintf(SockList *sl, const char *format,...)
void free_player(player *pl)
void SockList_Init(SockList *sl)
void SockList_ResetRead(SockList *sl)
void free_newsocket(socket_struct *ns)
unsigned char buf[2+65536UL+1]
buffer_struct outputbuffer
#define DEFAULT_NUM_LOOK_OBJECTS
void free_all_newserver(void)
void SockList_Term(SockList *sl)
void SockList_AddString(SockList *sl, const char *data)
void free_socket_images(void)
void read_client_images(void)
char * strdup_local(const char *str)
uint32 supported_readables
void init_connection(socket_struct *ns, const char *from_ip)
socket_struct * init_sockets
void LOG(LogLevel logLevel, const char *format,...)
uint8 anims_sent[MAXANIMNUM]
void final_free_player(player *pl)
char * strerror_local(int errnum, char *buf, size_t size)
#define FREE_AND_CLEAR(xyz)
void Send_With_Handling(socket_struct *ns, SockList *sl)