25a9891522eeca8b64295d819ae7f3bbcb99fd71
[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 SEND_N_MAX 128
29
30 #define N_SUCCESS 1
31 #define N_ERROR -1
32 #define N_E_IN_USE -2
33 #define N_E_NO_INFO -3
34 #define N_E_CLOSE -4
35 #define N_E_CONNECT -5
36 #define N_E_NC -6
37 #define N_E_ACCEPT -7
38 #define N_E_MAXC -8
39
40 #define MAX_LISTEN_QUEUE 32
41
42 /* net specific variables */
43 typedef struct s_connection {
44   int fd;
45   char ip[IP_DIGITS];
46   in_port_t port;
47   unsigned char status;
48   unsigned short cap; /* 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 short cap;
55   /* limited connections by now -- replaced by list management later */
56   int c_count;
57   t_connection connection[MAX_CONNECTIONS];
58   unsigned int sendmask; /* 32 bits for maximum of 32 connections */
59 } t_net;
60
61 /* function prototypes */
62 int network_init(t_net *net);
63 int network_shutdown(t_net *net);
64 int network_set_listen_port(t_net *net,in_port_t port);
65 int network_manage_connection(t_net *net);
66 int network_connect(t_net *net,int channel);
67 int network_close(t_net *net,int channel);
68 int network_close_all(t_net *net);
69 int network_set_connection_info(t_net *net,int channel,char *ip,int port);
70 int network_select(t_net *net,int channel);
71 int network_deselect(t_net *net,int channel);
72 int network_manage_incoming(t_net *net);
73 int network_send(int fd,unsigned char *data,int datasize);
74 int network_receive(int fd,unsigned char *data,int datasize);
75
76 #endif