1 /* network.h -- network headers */
10 #include <sys/types.h>
11 #include <sys/socket.h>
14 /* net specific includes */
15 #include <netinet/in.h>
16 #include <arpa/inet.h>
19 #define MAX_CONNECTIONS 32
20 #define MAX_NIC_DEVICE 32
23 #define C_IN_USE (1<<0)
24 #define C_INFO_A (1<<1)
25 #define C_SOCKET (1<<2)
26 #define C_ESTABL (1<<3)
27 #define C_HANGUP (1<<4)
29 #define SEND_N_MAX 128
34 #define N_E_NO_INFO -3
36 #define N_E_CONNECT -5
41 #define N_UDP_WRONG_SENDER -9
43 #define MAX_LISTEN_QUEUE 32
45 /* net specific variables */
46 typedef struct s_connection {
51 unsigned short cap; /* capabilities */
54 typedef struct s_net {
55 int l_fd; /* fd for tcp conn */
56 int l_udp_fd; /* fd for udp data receive */
57 int s_udp_fd; /* fd for udp data send */
58 in_port_t l_port; /* tcp port */
59 int l_udp_port; /* udp listen port */
61 /* limited connections by now -- replaced by list management later */
63 t_connection connection[MAX_CONNECTIONS];
64 unsigned int sendmask; /* 32 bits for maximum of 32 connections */
65 char nic[MAX_NIC_DEVICE];
68 /* function prototypes */
69 int network_init(t_net *net);
70 int network_shutdown(t_net *net);
71 int network_set_listen_port(t_net *net,in_port_t port);
72 int network_manage_connection(t_net *net);
73 int network_connect(t_net *net,int channel);
74 int network_close(t_net *net,int channel);
75 int network_close_all(t_net *net);
76 int network_set_connection_info(t_net *net,int channel,char *ip,int port);
77 int network_select(t_net *net,int channel);
78 int network_deselect(t_net *net,int channel);
79 int network_manage_incoming(t_net *net);
80 int network_send(int fd,unsigned char *data,int datasize);
81 int network_receive(int fd,unsigned char *data,int datasize);
82 int network_udp_listen_init(t_net *net);
83 int network_udp_receive(t_net *net,int channel, unsigned char *data,int count);
84 int network_udp_send(t_net *net,int channel, unsigned char *data,int size);
85 int network_udp_shutdown(t_net *net);