From 9a530c03732051934d0f0cc96be7658e90e9d5c2 Mon Sep 17 00:00:00 2001 From: ultramage Date: Sun, 29 Apr 2007 14:34:02 +0000 Subject: * Ladmin fixes - Added vs8 project file for ladmin - Replaced all occurences of printf in ladmin.c with ShowMessage - Fixed ladmin working with ips using the wrong byte orer * Fixed @jumpto displaying the incorrect player name * Added more safeguards to socket.c against socket ids out of range git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@10409 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/common/socket.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'src/common/socket.c') diff --git a/src/common/socket.c b/src/common/socket.c index f406a0eea..73b0fb06b 100644 --- a/src/common/socket.c +++ b/src/common/socket.c @@ -249,12 +249,12 @@ int connect_client(int listen_fd) return -1; } - if ( fd >= FD_SETSIZE ) - { //More connections than we can handle! - ShowError("accept failed. Received socket #%d is greater than can we handle! Increase the value of FD_SETSIZE (currently %d) for your OS to fix this!\n", fd, FD_SETSIZE); + if ( fd >= FD_SETSIZE ) { //Not enough capacity for this socket + ShowError("connect_client: New socket #%d is greater than can we handle! Increase the value of FD_SETSIZE (currently %d) for your OS to fix this!\n", fd, FD_SETSIZE); closesocket(fd); return -1; } + setsocketopts(fd); set_nonblocking(fd, 1); @@ -265,11 +265,9 @@ int connect_client(int listen_fd) } #endif + if( fd_max <= fd ) fd_max = fd + 1; FD_SET(fd,&readfds); - if( fd_max <= fd ) - fd_max = fd + 1; - create_session(fd, recv_to_fifo, send_from_fifo, default_func_parse); session[fd]->client_addr = ntohl(client_address.sin_addr.s_addr); session[fd]->rdata_tick = last_tick; @@ -290,6 +288,12 @@ int make_listen_bind(uint32 ip, uint16 port) exit(1); } + if ( fd >= FD_SETSIZE ) { //Not enough capacity for this socket + ShowError("make_listen_bind: New socket #%d is greater than can we handle! Increase the value of FD_SETSIZE (currently %d) for your OS to fix this!\n", fd, FD_SETSIZE); + closesocket(fd); + return -1; + } + setsocketopts(fd); set_nonblocking(fd, 1); @@ -314,7 +318,7 @@ int make_listen_bind(uint32 ip, uint16 port) } if(fd_max <= fd) fd_max = fd + 1; - FD_SET(fd, &readfds ); + FD_SET(fd, &readfds); create_session(fd, connect_client, null_send, null_parse); @@ -334,6 +338,12 @@ int make_connection(uint32 ip, uint16 port) return -1; } + if ( fd >= FD_SETSIZE ) { //Not enough capacity for this socket + ShowError("make_connection: New socket #%d is greater than can we handle! Increase the value of FD_SETSIZE (currently %d) for your OS to fix this!\n", fd, FD_SETSIZE); + closesocket(fd); + return -1; + } + setsocketopts(fd); server_address.sin_family = AF_INET; @@ -351,8 +361,7 @@ int make_connection(uint32 ip, uint16 port) //Now the socket can be made non-blocking. [Skotlex] set_nonblocking(fd, 1); - if (fd_max <= fd) - fd_max = fd + 1; + if (fd_max <= fd) fd_max = fd + 1; FD_SET(fd,&readfds); create_session(fd, recv_to_fifo, send_from_fifo, default_func_parse); -- cgit v1.2.3-60-g2f50