summaryrefslogtreecommitdiff
path: root/src/common/socket.c
diff options
context:
space:
mode:
author(no author) <(no author)@54d463be-8e91-2dee-dedb-b68131a5f0ec>2005-02-05 02:07:30 +0000
committer(no author) <(no author)@54d463be-8e91-2dee-dedb-b68131a5f0ec>2005-02-05 02:07:30 +0000
commitd8776648ff6e6b3cb4922025b12c9cc42974b4db (patch)
tree5d2de15f0f2057dc0d6fc034ccc4e76a0ee353c5 /src/common/socket.c
parentb91405aa5454bab5eeacd29d28a773812ef55b29 (diff)
downloadhercules-d8776648ff6e6b3cb4922025b12c9cc42974b4db.tar.gz
hercules-d8776648ff6e6b3cb4922025b12c9cc42974b4db.tar.bz2
hercules-d8776648ff6e6b3cb4922025b12c9cc42974b4db.tar.xz
hercules-d8776648ff6e6b3cb4922025b12c9cc42974b4db.zip
Servers can bind to single IP addresses now, and added buffer.(c/h)
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/branches/stable@1033 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/common/socket.c')
-rw-r--r--src/common/socket.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/common/socket.c b/src/common/socket.c
index 72e7e3f22..f43ca108c 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -270,6 +270,55 @@ int make_listen_port(int port)
return fd;
}
+int make_listen_bind(long ip,int port)
+{
+ struct sockaddr_in server_address;
+ int fd;
+ int result;
+
+ fd = socket( AF_INET, SOCK_STREAM, 0 );
+ if(fd_max<=fd) fd_max=fd+1;
+
+#ifdef _WIN32
+ {
+ unsigned long val = 1;
+ ioctlsocket(fd, FIONBIO, &val);
+ }
+#else
+ result = fcntl(fd, F_SETFL, O_NONBLOCK);
+#endif
+
+ setsocketopts(fd);
+
+ server_address.sin_family = AF_INET;
+ server_address.sin_addr.s_addr = ip;
+ server_address.sin_port = htons((unsigned short)port);
+
+ result = bind(fd, (struct sockaddr*)&server_address, sizeof(server_address));
+ if( result == -1 ) {
+ perror("bind");
+ exit(1);
+ }
+ result = listen( fd, 5 );
+ if( result == -1 ) { /* error */
+ perror("listen");
+ exit(1);
+ }
+
+ FD_SET(fd, &readfds );
+
+ CREATE(session[fd], struct socket_data, 1);
+
+ if(session[fd]==NULL){
+ printf("out of memory : make_listen_bind\n");
+ exit(1);
+ }
+ memset(session[fd],0,sizeof(*session[fd]));
+ session[fd]->func_recv = connect_client;
+
+ return fd;
+}
+
// Console Reciever [Wizputer]
int console_recieve(int i) {
int n;