X-Git-Url: https://hackdaworld.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fnetwork.h;fp=src%2Fnetwork.h;h=274811ebfbc9286296130b4fa8ceb882a67fa39b;hb=c8c162c2b1f82f32160bcaa4159ea8735a8582c5;hp=0000000000000000000000000000000000000000;hpb=4546108a81317af1135683e85b9340715e585339;p=my-code%2Fivac.git diff --git a/src/network.h b/src/network.h new file mode 100644 index 0000000..274811e --- /dev/null +++ b/src/network.h @@ -0,0 +1,73 @@ +/* network.h -- network headers */ + +#ifndef NETWORK_H +#define NETWORK_H + +/* includes */ +#include +#include +#include +#include +#include +#include + +/* net specific includes */ +#include +#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 CHAR_N_UNAME 32 + +#define SEND_N_MAX 128 +#define SEND_N_NAME 'n' +#define SEND_N_G_CAP 'g' +#define SEND_N_AV_CAP 'c' + +#define N_SUCCESS 1 +#define N_ERROR -1 + +#define MAX_LISTEN_QUEUE 32 + +/* net specific variables */ +typedef struct s_connection { + int fd; + char name[CHAR_N_UNAME]; + 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 struct 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; + +/* function prototypes */ +int network_init(t_net *net); +int network_shutdown(t_net *net); +int network_set_listen_port(t_net *net,in_port_t port); +int network_manage_connection(t_net *net); +int network_manage_incoming(t_net *net); +int network_send(int fd,unsigned char *data,int datasize); +int network_receive(int fd,unsigned char *data,int datasize); +int send_info(int channel,t_net *net,char *name); +int receive_info(int channel,t_net *net); + +#endif