summaryrefslogtreecommitdiff
path: root/src/common
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
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')
-rw-r--r--src/common/buffer.h18
-rw-r--r--src/common/socket.c49
-rw-r--r--src/common/socket.h1
3 files changed, 68 insertions, 0 deletions
diff --git a/src/common/buffer.h b/src/common/buffer.h
new file mode 100644
index 000000000..294233595
--- /dev/null
+++ b/src/common/buffer.h
@@ -0,0 +1,18 @@
+#ifndef _BUFFER_H_
+#define _BUFFER_H_
+
+// Full credit for this goes to Shinomori [Ajarn]
+
+#ifdef __GNUC__ // GCC has variable length arrays
+
+#define CREATE_BUFFER(name, type, size) type name[size]
+#define DELETE_BUFFER(name)
+
+#else // others don't, so we emulate them
+
+#define CREATE_BUFFER(name, type, size) type *name=(type*)aCalloc(size,sizeof(type))
+#define DELETE_BUFFER(name) aFree(name);name=NULL
+
+#endif
+
+#endif \ No newline at end of file
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;
diff --git a/src/common/socket.h b/src/common/socket.h
index 68b204862..7ee7b7689 100644
--- a/src/common/socket.h
+++ b/src/common/socket.h
@@ -88,6 +88,7 @@ extern int fd_max;
// Function prototype declaration
int make_listen_port(int);
+int make_listen_bind(long,int);
int make_connection(long,int);
int delete_session(int);
int realloc_fifo(int fd,int rfifo_size,int wfifo_size);