oups .. added missing files, added Makefile + .cvsignore list
[my-code/ivac.git] / src / network.h
1 /* network.h -- network headers */
2
3 #ifndef NETWORK_H
4 #define NETWORK_H
5
6 /* includes */
7 #include <stdio.h>
8 #include <errno.h>
9 #include <string.h>
10 #include <sys/types.h>
11 #include <sys/socket.h>
12 #include <unistd.h>
13
14 /* net specific includes */
15 #include <netinet/in.h>
16 #include <arpa/inet.h>
17
18 /* defines */
19 #define MAX_CONNECTIONS 32
20
21 #define IP_DIGITS 16
22 #define C_IN_USE (1<<0)
23 #define C_INFO_A (1<<1)
24 #define C_SOCKET (1<<2)
25 #define C_ESTABL (1<<3)
26 #define C_HANGUP (1<<4)
27
28 #define CHAR_N_UNAME 32
29
30 #define SEND_N_MAX 128
31 #define SEND_N_NAME 'n'
32 #define SEND_N_G_CAP 'g'
33 #define SEND_N_AV_CAP 'c'
34
35 #define N_SUCCESS 1
36 #define N_ERROR -1
37
38 #define MAX_LISTEN_QUEUE 32
39
40 /* net specific variables */
41 typedef struct s_connection {
42   int fd;
43   char name[CHAR_N_UNAME];
44   char ip[IP_DIGITS];
45   in_port_t port;
46   unsigned char status;
47   unsigned char cap; /* general capabilities */
48   unsigned short avcap; /* audio/video capabilities */
49 } t_connection;
50
51 typedef struct s_net {
52   int l_fd; /* listen file descriptor */
53   in_port_t l_port;
54   unsigned char cap;
55   unsigned short avcap;
56   /* limited connections by now -- replaced by list management later */
57   int c_count;
58   t_connection connection[MAX_CONNECTIONS];
59   unsigned int sendmask; /* 32 bits for maximum of 32 connections */
60 } t_net;
61
62 /* function prototypes */
63 int network_init(t_net *net);
64 int network_shutdown(t_net *net);
65 int network_set_listen_port(t_net *net,in_port_t port);
66 int network_manage_connection(t_net *net);
67 int network_manage_incoming(t_net *net);
68 int network_send(int fd,unsigned char *data,int datasize);
69 int network_receive(int fd,unsigned char *data,int datasize);
70 int send_info(int channel,t_net *net,char *name);
71 int receive_info(int channel,t_net *net);
72
73 #endif