ObjFW
socket_helpers.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015
3  * Jonathan Schleifer <js@webkeks.org>
4  *
5  * All rights reserved.
6  *
7  * This file is part of ObjFW. It may be distributed under the terms of the
8  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
9  * the packaging of this file.
10  *
11  * Alternatively, it may be distributed under the terms of the GNU General
12  * Public License, either version 2 or 3, which can be found in the file
13  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
14  * file.
15  */
16 
17 /* Work around __block being used by glibc */
18 #ifdef __GLIBC__
19 # undef __USE_XOPEN
20 #endif
21 
22 #include <unistd.h>
23 
24 #ifdef HAVE_ARPA_INET_H
25 # include <arpa/inet.h>
26 #endif
27 #ifdef HAVE_NETDB_H
28 # include <netdb.h>
29 #endif
30 
31 #ifndef INVALID_SOCKET
32 # define INVALID_SOCKET -1
33 #endif
34 
35 #ifdef HAVE_GETADDRINFO
36 # ifndef AI_NUMERICSERV
37 # define AI_NUMERICSERV 0
38 # endif
39 # ifndef AI_NUMERICHOST
40 # define AI_NUMERICHOST 0
41 # endif
42 #endif
43 
44 #ifndef INADDR_NONE
45 # define INADDR_NONE ((in_addr_t)-1)
46 #endif
47 
48 #ifndef SOMAXCONN
49 # define SOMAXCONN 32
50 #endif
51 
52 #ifndef SOCK_CLOEXEC
53 # define SOCK_CLOEXEC 0
54 #endif
55 
56 #ifdef _WIN32
57 # define close(sock) closesocket(sock)
58 #endif
59 
60 #ifdef _PSP
61 /* PSP defines AF_INET6, even though sockaddr_in6 is missing */
62 # undef AF_INET6
63 #endif
64 
65 #ifdef __wii__
66 # define accept(sock, addr, addrlen) net_accept(sock, addr, addrlen)
67 # define bind(sock, addr, addrlen) net_bind(sock, addr, addrlen)
68 # define close(sock) net_close(sock)
69 # define connect(sock, addr, addrlen) net_connect(sock, addr, addrlen)
70 # define gethostbyname(name) net_gethostbyname(name)
71 # define listen(sock, backlog) net_listen(sock, backlog)
72 # define poll(fds, nfds, timeout) net_poll(fds, nfds, timeout)
73 # define recv(sock, buf, len, flags) net_recv(sock, buf, len, flags)
74 # define recvfrom(sock, buf, len, flags, addr, addrlen) \
75  net_recvfrom(sock, buf, len, flags, addr, addrlen)
76 # define send(sock, buf, len, flags) net_send(sock, buf, len, flags)
77 # define sendto(sock, buf, len, flags, addr, addrlen) \
78  net_sendto(sock, buf, len, flags, addr, addrlen)
79 # define setsockopt(sock, level, name, value, len) \
80  net_setsockopt(sock, level, name, value, len)
81 # define socket(domain, type, proto) net_socket(domain, type, proto)
82 typedef u32 in_addr_t;
83 typedef u32 nfds_t;
84 #endif