ObjFW
src
socket.h
1
/*
2
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017
3
* Jonathan Schleifer <js@heap.zone>
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
#include "objfw-defs.h"
18
19
#ifndef OF_HAVE_SOCKETS
20
# error No sockets available!
21
#endif
22
23
#include <stdbool.h>
24
25
#import "platform.h"
26
27
#ifdef OF_HAVE_SYS_SOCKET_H
28
# ifdef OF_MORPHOS
29
# define BOOL EXEC_BOOL
30
# endif
31
# include <sys/socket.h>
32
# ifdef OF_MORPHOS
33
# undef BOOL
34
# endif
35
#endif
36
#ifdef OF_HAVE_NETINET_IN_H
37
# include <netinet/in.h>
38
#endif
39
#ifdef OF_HAVE_NETINET_TCP_H
40
# include <netinet/tcp.h>
41
#endif
42
43
#include "platform.h"
44
45
#ifdef OF_WINDOWS
46
# ifdef __MINGW32__
47
# include <_mingw.h>
48
# ifdef __MINGW64_VERSION_MAJOR
49
# include <winsock2.h>
50
# endif
51
# endif
52
# include <windows.h>
53
# include <ws2tcpip.h>
54
#endif
55
56
#ifdef OF_MORPHOS
57
typedef
long
socklen_t;
58
59
struct
sockaddr_storage {
60
uint8_t ss_len;
61
uint8_t ss_family;
62
char
ss_data[2 +
sizeof
(
struct
in_addr) + 8];
63
};
64
#endif
65
66
#ifdef OF_MORPHOS_IXEMUL
67
typedef
int
socklen_t;
68
69
struct
sockaddr_storage {
70
uint8_t ss_len;
71
uint8_t ss_family;
72
char
ss_data[2 +
sizeof
(
struct
in_addr) + 8];
73
};
74
#endif
75
76
#ifdef OF_WII
77
# define BOOL OGC_BOOL
78
# include <network.h>
79
# undef BOOL
80
81
struct
sockaddr_storage {
82
u8 ss_len;
83
u8 ss_family;
84
u8 ss_data[14];
85
};
86
#endif
87
88
#ifdef OF_PSP
89
# include <stdint.h>
90
91
struct
sockaddr_storage {
92
uint8_t ss_len;
93
sa_family_t ss_family;
94
in_port_t ss_data1;
95
struct
in_addr ss_data2;
96
int8_t ss_data3[8];
97
};
98
#endif
99
100
#import "macros.h"
101
102
OF_ASSUME_NONNULL_BEGIN
103
104
#ifndef OF_WINDOWS
105
typedef
int
of_socket_t;
106
#else
107
typedef
SOCKET of_socket_t;
108
#endif
109
110
#ifdef __cplusplus
111
extern
"C"
{
112
#endif
113
extern
bool
of_socket_init(
void
);
114
extern
int
of_socket_errno(
void
);
115
# ifndef OF_WII
116
extern
int
of_getsockname(of_socket_t socket,
struct
sockaddr *restrict address,
117
socklen_t *restrict address_len);
118
# endif
119
#ifdef __cplusplus
120
}
121
#endif
122
123
OF_ASSUME_NONNULL_END
Generated by
1.8.13