more abstraction in network.* and input.*, first display stuff in ivac.*
[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
33 #define MAX_LISTEN_QUEUE 32
34
35 /* net specific variables */
36 typedef struct s_connection {
37   int fd;
38   char ip[IP_DIGITS];
39   in_port_t port;
40   unsigned char status;
41   unsigned short cap; /* capabilities */
42 } t_connection;
43
44 typedef struct s_net {
45   int l_fd; /* listen file descriptor */
46   in_port_t l_port;
47   unsigned short cap;
48   /* limited connections by now -- replaced by list management later */
49   int c_count;
50   t_connection connection[MAX_CONNECTIONS];
51   unsigned int sendmask; /* 32 bits for maximum of 32 connections */
52 } t_net;
53
54 /* function prototypes */
55 int network_init(t_net *net);
56 int network_shutdown(t_net *net);
57 int network_set_listen_port(t_net *net,in_port_t port);
58 int network_manage_connection(t_net *net);
59 int network_manage_incoming(t_net *net);
60 int network_send(int fd,unsigned char *data,int datasize);
61 int network_receive(int fd,unsigned char *data,int datasize);
62
63 #endif