From 4344661d0612465223b516b4c1132260eeba34d1 Mon Sep 17 00:00:00 2001 From: hackbard Date: Wed, 5 May 2004 16:48:40 +0000 Subject: [PATCH] removed inet.* files, replaced by network.* files --- src/inet.c | 219 ----------------------------------------------------- src/inet.h | 55 -------------- 2 files changed, 274 deletions(-) delete mode 100644 src/inet.c delete mode 100644 src/inet.h diff --git a/src/inet.c b/src/inet.c deleted file mode 100644 index 4f02370..0000000 --- a/src/inet.c +++ /dev/null @@ -1,219 +0,0 @@ -/* inet.c -- network management stuff - * - * author: hackbard@hackdaworld.dyndns.org - * - */ - -#include "inet.h" - -int network_init(t_ivac *ivac) { - - struct sockaddr_in addr; - - puts("[ivac] inet: initializing network ..."); - - memset(ivac->net.connection,0,MAX_CONNECTIONS*sizeof(t_connection)); - ivac->net.c_count=0; - ivac->net.sendmask=0; - - if((ivac->net.l_fd=socket(AF_INET,SOCK_STREAM,0))==-1) { - perror("[ivac] inet.c: socket call"); - return ERROR; - } - - memset(&addr,0,sizeof(struct sockaddr)); - addr.sin_family=AF_INET; - addr.sin_port=htons(ivac->net.l_port); - addr.sin_addr.s_addr=INADDR_ANY; - - if(bind(ivac->net.l_fd,(struct sockaddr *)&addr, - sizeof(struct sockaddr))==-1) { - perror("[ivac] inet.c: bind call"); - return ERROR; - } - - printf("[ivac] inet: listen on %s port %d.\n",inet_ntoa(addr.sin_addr) - ,ivac->net.l_port); - - return SUCCESS; -} - -int network_manage_connection(t_ivac *ivac) { - - int i; - struct sockaddr_in addr; - - for(i=0;inet.connection[i].status&C_IN_USE) { - - if(ivac->net.connection[i].status&C_HANGUP) { - if(close(ivac->net.connection[i].fd)==-1) { - perror("[ivac] inet.c: close call"); - return ERROR; - } - ivac->net.connection[i].status=0; - } - - if(ivac->net.connection[i].status&C_INFO_A) { - - if(!ivac->net.connection[i].status&C_SOCKET) { - if((ivac->net.connection[i].fd=socket(AF_INET,SOCK_STREAM,0))==-1) { - perror("[ivac] inet.c: socket call"); - return ERROR; - } - } - - if(!ivac->net.connection[i].status&C_ESTABL) { - - memset(&addr,0,sizeof(struct sockaddr)); - addr.sin_family=AF_INET; - addr.sin_port=htons(ivac->net.connection[i].port); - 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) { - perror("[ivac] inet.c: connect call"); - return ERROR; - } - - } - - } - - } - - } - - 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) { - - int count,left; - - count=0; - left=datasize; - - while(left) { - if((count=write(fd,data+datasize-left,left))==-1) { - perror("[ivac] inet.c: write call"); - return ERROR; - } - left-=count; - } - - return SUCCESS; -} - -int network_receive(int fd,unsigned char *data,int datasize) { - - int count,retval; - - retval=1; - count=0; - - while(retval) { - if((retval=read(fd,data+count,datasize-count))==-1) { - perror("[ivac] inet.c: read call"); - return ERROR; - } - count+=retval; - } - - return count; -} - -int send_info(int fd,t_ivac *ivac) { - - char data[SEND_I_MAX]; - int size; - - size=strlen(ivac->name); - - data[0]=SEND_I_NAME; - data[1]=size; - strncpy(data+2,ivac->name,size); - size+=2; - - data[size+1]=SEND_I_CAP; - data[size+2]=sizeof(unsigned char); - data[size+3]=ivac->net.cap; - size+=(sizeof(unsigned char)+2); - - data[size+1]=SEND_I_AVCAP; - data[size+2]=sizeof(unsigned short); - data[size+2+sizeof(unsigned short)]; - size+=(sizeof(unsigned short)+2); - - if(network_send(fd,data,size)==ERROR) { - puts("[ivac] inet.c: send_info failed"); - return ERROR; - } - - return SUCCESS; -} - -int receive_info(int i,t_ivac *ivac) { - - char data[CHAR_USERNAME+2]; - int count,length; - - if((length=network_receive(ivac->net.connection[i].fd, - data,SEND_I_MAX))==ERROR) { - puts("[ivac] inet.c: receive_info failed"); - return ERROR; - } - - while(length-count) { - switch(data[count]) { - case SEND_I_NAME: - strncpy(ivac->net.connection[i].name,data[count+2],data[count+1]); - ivac->net.connection[i].name[data[count+2]]='\0'; - count+=(data[count+2]+2); - break; - case SEND_I_G_CAP: - ivac->net.connection[i].cap=data[count+4]; - count+=(sizeof(unsigned char)+2); - break; - case SEND_I_AV_CAP: - ivac->net.connection[i].avcap=data[count+3]<<8; - ivac->net.connection[i].avcap|=data[count+4]; - count+=(sizeof(unsigned short)+2); - break; - default: - puts("[ivac] inet.c: receive_info, unknown character"); - return ERROR; - } - } - - return SUCCESS; -} diff --git a/src/inet.h b/src/inet.h deleted file mode 100644 index e7c48b7..0000000 --- a/src/inet.h +++ /dev/null @@ -1,55 +0,0 @@ -/* inet.h -- inet headers */ - -#ifndef INET_H -#define INET_H - -/* includes */ -#include "ivac.h" -#include -#include -#include -#include -#include - -/* net specific includes */ -#include - -/* defines */ -#define MAX_CONNECTIONS 32 - -#define IP_DIGITS 16 -#define C_IN_USE (1<<0) -#define C_INFO_A (1<<1) -#define C_SOCKET (1<<2) -#define C_ESTABL (1<<3) -#define C_HANGUP (1<<4) - -#define SEND_I_MAX 128 -#define SEND_I_NAME 'n' -#define SEND_I_G_CAP 'g' -#define SEND_I_AV_CAP 'c' - -/* net specific variables */ -typedef s_connection { - int fd; - char name[CHAR_USERNAME]; - char ip[IP_DIGITS]; - in_port_t port; - unsigned char status; - unsigned char cap; /* general capabilities */ - unsigned short avcap; /* audio/video capabilities */ -} t_connection; - -typedef s_net { - int l_fd; /* listen file descriptor */ - in_port_t l_port; - unsigned char cap; - unsigned short avcap; - /* limited connections by now -- replaced by list management later */ - int c_count; - t_connection connection[MAX_CONNECTIONS]; - unsigned int sendmask; /* 32 bits for maximum of 32 connections */ -} t_net; - -#endif - -- 2.39.2