ObjFW
socket.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 #import "objfw-defs.h"
18 
19 #ifndef OF_HAVE_SOCKETS
20 # error No sockets available!
21 #endif
22 
23 #include <stdbool.h>
24 
25 #ifdef OF_HAVE_SYS_SOCKET_H
26 # include <sys/socket.h>
27 #endif
28 #ifdef OF_HAVE_NETINET_IN_H
29 # include <netinet/in.h>
30 #endif
31 #ifdef OF_HAVE_NETINET_TCP_H
32 # include <netinet/tcp.h>
33 #endif
34 
35 #ifdef _WIN32
36 # ifdef __MINGW32__
37 # include <_mingw.h>
38 # ifdef __MINGW64_VERSION_MAJOR
39 # include <winsock2.h>
40 # endif
41 # endif
42 # include <windows.h>
43 # include <ws2tcpip.h>
44 #endif
45 
46 #ifdef __wii__
47 # define BOOL OGC_BOOL
48 # include <network.h>
49 # undef BOOL
50 
51 struct sockaddr_storage {
52  u8 ss_len;
53  u8 ss_family;
54  u8 ss_data[14];
55 };
56 #endif
57 
58 #ifdef _PSP
59 # include <stdint.h>
60 
61 struct sockaddr_storage {
62  uint8_t ss_len;
63  sa_family_t ss_family;
64  in_port_t ss_data1;
65  struct in_addr ss_data2;
66  int8_t ss_data3[8];
67 };
68 #endif
69 
70 #import "macros.h"
71 
72 OF_ASSUME_NONNULL_BEGIN
73 
74 #ifndef _WIN32
75 typedef int of_socket_t;
76 #else
77 typedef SOCKET of_socket_t;
78 #endif
79 
80 #ifdef __cplusplus
81 extern "C" {
82 #endif
83 extern bool of_socket_init(void);
84 extern int of_socket_errno(void);
85 # ifndef __wii__
86 extern int of_getsockname(of_socket_t socket, struct sockaddr *restrict address,
87  socklen_t *restrict address_len);
88 # endif
89 #ifdef __cplusplus
90 }
91 #endif
92 
93 OF_ASSUME_NONNULL_END