From 8d7f26cc0f2b37194cc262c915fa76e68b49f420 Mon Sep 17 00:00:00 2001 From: hackbard Date: Tue, 4 May 2004 10:43:22 +0000 Subject: [PATCH] bugfixed inet_{aton,ntoa} usage + implemented network_manage_incoming function --- src/inet.c | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/inet.c b/src/inet.c index 99f83d1..4f02370 100644 --- a/src/inet.c +++ b/src/inet.c @@ -8,7 +8,7 @@ int network_init(t_ivac *ivac) { - sockaddr_in addr; + struct sockaddr_in addr; puts("[ivac] inet: initializing network ..."); @@ -32,7 +32,7 @@ int network_init(t_ivac *ivac) { return ERROR; } - printf("[ivac] inet: listen on %s port %d.\n",inet_ntoa(addr.sin_addr.s_addr) + printf("[ivac] inet: listen on %s port %d.\n",inet_ntoa(addr.sin_addr) ,ivac->net.l_port); return SUCCESS; @@ -41,7 +41,7 @@ int network_init(t_ivac *ivac) { int network_manage_connection(t_ivac *ivac) { int i; - sockaddr_in addr; + struct sockaddr_in addr; for(i=0;inet.connection[i].port); - addr.sin_addr_s_addr=inet_aton(ivac->net.connection[i].ip); + if(!inet_aton(ivac->net.connection[i].ip,&(addr.sin_addr))) { + perror("[ivac] inet.c: inet_aton call"); + return ERROR; + } if(connect(ivac->net.connection[i].fd,(struct sockaddr *)&addr, sizeof(struct sockaddr))==-1) { @@ -87,6 +90,31 @@ int network_manage_connection(t_ivac *ivac) { return SUCCESS; } + +int network_manage_incoming(t_ivac *ivac) { + + int i; + struct sockaddr_in addr; + int len; + + for(i=0;inet.connection[i].status&C_IN_USE) { + if((ivac->net.connection[i].fd=accept(ivac->net.l_fd, + (struct sockaddr *)&addr, + &len))==-1) { + perror("[ivac] inet.c: accept call"); + return ERROR; + } + strncpy(ivac->net.connection[i].ip,inet_ntoa(addr.sin_addr),IP_DIGITS); + ivac->net.connection[i].port=ntohs(addr.sin_port); + ivac->net.connection[i].status=C_IN_USE|C_INFO_A|C_SOCKET|C_ESTABL; + return i; + } + } + + puts("[ivac] inet: maximum connections reached"); + return ERROR; +} int network_send(int fd,unsigned char *data,int datasize) { -- 2.39.2