use poll() instead of select()
[rofl0r-microsocks.git] / server.h
blob5acf664992b907e25b9012c958fef5c1569ee7da
1 #ifndef SERVER_H
2 #define SERVER_H
4 #undef _POSIX_C_SOURCE
5 #define _POSIX_C_SOURCE 200809L
7 #include <sys/socket.h>
8 #include <netdb.h>
9 #include <netinet/in.h>
11 #pragma RcB2 DEP "server.c"
13 union sockaddr_union {
14 struct sockaddr_in v4;
15 struct sockaddr_in6 v6;
18 #define SOCKADDR_UNION_AF(PTR) (PTR)->v4.sin_family
20 #define SOCKADDR_UNION_LENGTH(PTR) ( \
21 ( SOCKADDR_UNION_AF(PTR) == AF_INET ) ? sizeof((PTR)->v4) : ( \
22 ( SOCKADDR_UNION_AF(PTR) == AF_INET6 ) ? sizeof((PTR)->v6) : 0 ) )
24 #define SOCKADDR_UNION_ADDRESS(PTR) ( \
25 ( SOCKADDR_UNION_AF(PTR) == AF_INET ) ? (void*) &(PTR)->v4.sin_addr : ( \
26 ( SOCKADDR_UNION_AF(PTR) == AF_INET6 ) ? (void*) &(PTR)->v6.sin6_addr : (void*) 0 ) )
28 #define SOCKADDR_UNION_PORT(PTR) ( \
29 ( SOCKADDR_UNION_AF(PTR) == AF_INET ) ? (PTR)->v4.sin_port : ( \
30 ( SOCKADDR_UNION_AF(PTR) == AF_INET6 ) ? (PTR)->v6.sin6_port : 0 ) )
32 struct client {
33 union sockaddr_union addr;
34 int fd;
37 struct server {
38 int fd;
41 int resolve(const char *host, unsigned short port, struct addrinfo** addr);
42 int resolve_sa(const char *host, unsigned short port, union sockaddr_union *res);
43 int bindtoip(int fd, union sockaddr_union *bindaddr);
45 int server_waitclient(struct server *server, struct client* client);
46 int server_setup(struct server *server, const char* listenip, unsigned short port);
48 #endif