16 #include "objfw-defs.h"
18 #ifndef OF_HAVE_SOCKETS
19 # error No sockets available!
25 #if defined(OF_HAVE_THREADS) && defined(OF_AMIGAOS)
29 #ifdef OF_HAVE_SYS_SOCKET_H
30 # include <sys/socket.h>
32 #ifdef OF_HAVE_NETINET_IN_H
33 # include <netinet/in.h>
35 #ifdef OF_HAVE_NETINET_TCP_H
36 # include <netinet/tcp.h>
38 #ifdef OF_HAVE_SYS_UN_H
41 #ifdef OF_HAVE_AFUNIX_H
44 #ifdef OF_HAVE_NETIPX_IPX_H
45 # include <netipx/ipx.h>
47 #if defined(OF_HAVE_NETAT_APPLETALK_H)
48 # include <netat/appletalk.h>
49 #elif defined(OF_HAVE_NETATALK_AT_H)
50 # include <netatalk/at.h>
55 # include <ws2tcpip.h>
59 # ifdef OF_HAVE_APPLETALK
60 # include <atalkwsh.h>
74 OF_ASSUME_NONNULL_BEGIN
79 typedef int OFSocketHandle;
80 static const OFSocketHandle OFInvalidSocketHandle = -1;
82 typedef SOCKET OFSocketHandle;
83 static const OFSocketHandle OFInvalidSocketHandle = INVALID_SOCKET;
87 typedef short sa_family_t;
91 typedef u8 sa_family_t;
95 typedef long socklen_t;
96 typedef u_char sa_family_t;
97 typedef u_short in_port_t;
121 struct sockaddr_in6 {
122 sa_family_t sin6_family;
124 uint32_t sin6_flowinfo;
128 uint32_t sin6_scope_id;
132 #if !defined(OF_HAVE_UNIX_SOCKETS) && !defined(OF_MORPHOS) && !defined(OF_MINT)
134 sa_family_t sun_family;
140 # define IPX_NODE_LEN 6
142 #if !defined(OF_HAVE_IPX)
143 struct sockaddr_ipx {
144 sa_family_t sipx_family;
145 uint32_t sipx_network;
146 unsigned char sipx_node[IPX_NODE_LEN];
150 #elif defined(OF_WINDOWS)
151 # define IPX_NODE_LEN 6
152 # define sipx_family sa_family
153 # define sipx_network sa_netnum
154 # define sipx_node sa_nodenum
155 # define sipx_port sa_socket
156 #elif defined(OF_FREEBSD)
157 # define sipx_network sipx_addr.x_net.c_net
158 # define sipx_node sipx_addr.x_host.c_host
161 #ifndef OF_HAVE_APPLETALK
163 sa_family_t sat_family;
170 # define sat_port sat_socket
172 # define sat_net sat_addr.s_net
173 # define sat_node sat_addr.s_node
189 struct sockaddr_in in;
190 struct sockaddr_in6 in6;
191 struct sockaddr_un un;
192 struct sockaddr_ipx ipx;
193 struct sockaddr_at at;
194 #ifdef OF_HAVE_SOCKADDR_STORAGE
199 struct sockaddr_storage storage;
256 const unsigned char node[_Nonnull IPX_NODE_LEN], uint16_t port);
268 uint8_t node, uint8_t port);
349 const unsigned char node[_Nonnull IPX_NODE_LEN]);
358 unsigned char node[_Nonnull IPX_NODE_LEN]);
431 extern bool OFSocketInit(
void);
432 #if defined(OF_HAVE_THREADS) && defined(OF_AMIGAOS) && !defined(OF_MORPHOS)
433 extern void OFSocketDeinit(
void);
435 extern int OFSocketErrNo(
void);
436 #if !defined(OF_WII) && !defined(OF_NINTENDO_3DS)
437 extern int OFGetSockName(OFSocketHandle sock,
struct sockaddr *restrict addr,
438 socklen_t *restrict addrLen);
441 #if defined(OF_HAVE_THREADS) && defined(OF_AMIGAOS) && !defined(OF_MORPHOS)
442 extern OFTLSKey OFSocketBaseKey;
444 extern OFTLSKey OFSocketInterfaceKey;
451 OF_ASSUME_NONNULL_END
void OFSocketAddressSetAppleTalkPort(OFSocketAddress *address, uint8_t port)
Sets the AppleTalk port of the specified OFSocketAddress.
Definition: OFSocket.m:1147
void OFSocketAddressSetAppleTalkNetwork(OFSocketAddress *address, uint16_t network)
Sets the AppleTalk network of the specified OFSocketAddress.
Definition: OFSocket.m:1103
uint8_t OFSocketAddressAppleTalkNode(const OFSocketAddress *address)
Gets the AppleTalk node of the specified OFSocketAddress.
Definition: OFSocket.m:1138
OFSocketAddress OFSocketAddressMakeIPX(uint32_t network, const unsigned char node[IPX_NODE_LEN], uint16_t port)
Creates an IPX address for the specified network, node and port.
Definition: OFSocket.m:610
OFSocketAddress OFSocketAddressParseIPv4(OFString *IP, uint16_t port)
Parses the specified IPv4 and port into an OFSocketAddress.
Definition: OFSocket.m:363
void OFSocketAddressSetIPXPort(OFSocketAddress *address, uint16_t port)
Sets the IPX port of the specified OFSocketAddress.
Definition: OFSocket.m:1085
uint32_t OFSocketAddressIPXNetwork(const OFSocketAddress *address)
Returns the IPX network of the specified OFSocketAddress.
Definition: OFSocket.m:1052
void OFSocketAddressSetAppleTalkNode(OFSocketAddress *address, uint8_t node)
Sets the AppleTalk node of the specified OFSocketAddress.
Definition: OFSocket.m:1129
uint16_t OFSocketAddressAppleTalkNetwork(const OFSocketAddress *address)
Returns the AppleTalk network of the specified OFSocketAddress.
Definition: OFSocket.m:1116
OFString * OFSocketAddressString(const OFSocketAddress *address)
Converts the specified OFSocketAddress to a string.
Definition: OFSocket.m:975
void OFSocketAddressSetIPXNetwork(OFSocketAddress *address, uint32_t network)
Sets the IPX network of the specified OFSocketAddress.
Definition: OFSocket.m:1041
void OFSocketAddressSetIPPort(OFSocketAddress *address, uint16_t port)
Sets the IP port of the specified OFSocketAddress.
Definition: OFSocket.m:994
uint16_t OFSocketAddressIPPort(const OFSocketAddress *address)
Returns the IP port of the specified OFSocketAddress.
Definition: OFSocket.m:1009
OFSocketAddress OFSocketAddressMakeAppleTalk(uint16_t network, uint8_t node, uint8_t port)
Creates an AppleTalk address for the specified network, node and port.
Definition: OFSocket.m:634
uint16_t OFSocketAddressIPXPort(const OFSocketAddress *address)
Returns the IPX port of the specified OFSocketAddress.
Definition: OFSocket.m:1094
OFSocketAddress OFSocketAddressParseIPv6(OFString *IP, uint16_t port)
Parses the specified IPv6 and port into an OFSocketAddress.
Definition: OFSocket.m:465
bool OFSocketAddressEqual(const OFSocketAddress *address1, const OFSocketAddress *address2)
Compares two OFSocketAddress for equality.
Definition: OFSocket.m:659
unsigned long OFSocketAddressHash(const OFSocketAddress *address)
Returns the hash for the specified OFSocketAddress.
Definition: OFSocket.m:766
OFSocketAddress OFSocketAddressParseIP(OFString *IP, uint16_t port)
Parses the specified IP (either v4 or v6) and port into an OFSocketAddress.
Definition: OFSocket.m:564
OFSocketAddressFamily
A socket address family.
Definition: OFSocket.h:103
@ OFSocketAddressFamilyAny
Definition: OFSocket.h:117
@ OFSocketAddressFamilyIPX
Definition: OFSocket.h:113
@ OFSocketAddressFamilyUNIX
Definition: OFSocket.h:111
@ OFSocketAddressFamilyAppleTalk
Definition: OFSocket.h:115
@ OFSocketAddressFamilyIPv6
Definition: OFSocket.h:109
@ OFSocketAddressFamilyIPv4
Definition: OFSocket.h:107
@ OFSocketAddressFamilyUnknown
Definition: OFSocket.h:105
uint8_t OFSocketAddressAppleTalkPort(const OFSocketAddress *address)
Returns the AppleTalk port of the specified OFSocketAddress.
Definition: OFSocket.m:1156
OFSocketAddress OFSocketAddressMakeUNIX(OFString *path)
Creates a UNIX socket address from the specified path.
Definition: OFSocket.m:578
void OFSocketAddressGetIPXNode(const OFSocketAddress *address, unsigned char node[IPX_NODE_LEN])
Gets the IPX node of the specified OFSocketAddress.
Definition: OFSocket.m:1075
OFString * OFSocketAddressUNIXPath(const OFSocketAddress *address)
Gets the UNIX socket path of the specified OFSocketAddress.
Definition: OFSocket.m:1022
void OFSocketAddressSetIPXNode(OFSocketAddress *address, const unsigned char node[IPX_NODE_LEN])
Sets the IPX node of the specified OFSocketAddress.
Definition: OFSocket.m:1065
A class for handling strings.
Definition: OFString.h:135
A struct which represents a host / port pair for a socket.
Definition: OFSocket.h:182