-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnet.h
46 lines (34 loc) · 899 Bytes
/
net.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef _NET_H
#define _NET_H
extern int is_running;
extern time_t g_now;
typedef struct sockaddr_storage IP;
typedef struct sockaddr_in IP4;
typedef struct sockaddr_in6 IP6;
// Callback for event loop
typedef void net_callback(int revents, int fd);
// Create a socket and bind to interface
int net_socket(
const char name[],
const char ifname[],
const int protocol,
const int af
);
// Create a socket and bind to address/interface
int net_bind(
const char name[],
const char addr[],
const int port,
const char ifname[],
const int protocol
);
int net_set_nonblocking(int fd);
// Add callback with file descriptor to listen for packets
void net_add_handler(int fd, net_callback *callback);
// Remove callback
void net_remove_handler(int fd, net_callback *callback);
// Start loop for all network events
void net_loop(void);
// Close sockets
void net_free(void);
#endif // _NET_H