20#include "objfw-defs.h"
22#ifndef OF_HAVE_SOCKETS
23# error No sockets available!
29#if defined(OF_HAVE_THREADS) && defined(OF_AMIGAOS)
33#ifdef OF_HAVE_SYS_SOCKET_H
34# include <sys/socket.h>
36#ifdef OF_HAVE_NETINET_IN_H
37# include <netinet/in.h>
39#ifdef OF_HAVE_NETINET_TCP_H
40# include <netinet/tcp.h>
42#ifdef OF_HAVE_SYS_UN_H
45#ifdef OF_HAVE_AFUNIX_H
48#ifdef OF_HAVE_NETIPX_IPX_H
49# include <netipx/ipx.h>
51#if defined(OF_HAVE_NETAT_APPLETALK_H)
52# include <netat/appletalk.h>
53#elif defined(OF_HAVE_NETATALK_AT_H)
54# include <netatalk/at.h>
63# ifdef OF_HAVE_APPLETALK
78OF_ASSUME_NONNULL_BEGIN
83typedef int OFSocketHandle;
84static const OFSocketHandle OFInvalidSocketHandle = -1;
86typedef SOCKET OFSocketHandle;
87static const OFSocketHandle OFInvalidSocketHandle = INVALID_SOCKET;
91typedef short sa_family_t;
95typedef u8 sa_family_t;
99typedef long socklen_t;
100typedef u_char sa_family_t;
101typedef u_short in_port_t;
126 sa_family_t sin6_family;
128 uint32_t sin6_flowinfo;
132 uint32_t sin6_scope_id;
136#if !defined(OF_HAVE_UNIX_SOCKETS) && !defined(OF_MORPHOS) && !defined(OF_MINT)
138 sa_family_t sun_family;
144# define IPX_NODE_LEN 6
146#if !defined(OF_HAVE_IPX)
148 sa_family_t sipx_family;
149 uint32_t sipx_network;
150 unsigned char sipx_node[IPX_NODE_LEN];
154#elif defined(OF_WINDOWS)
155# define IPX_NODE_LEN 6
156# define sipx_family sa_family
157# define sipx_network sa_netnum
158# define sipx_node sa_nodenum
159# define sipx_port sa_socket
160#elif defined(OF_FREEBSD)
161# define sipx_network sipx_addr.x_net.c_net
162# define sipx_node sipx_addr.x_host.c_host
165#ifndef OF_HAVE_APPLETALK
167 sa_family_t sat_family;
174# define sat_port sat_socket
176# define sat_net sat_addr.s_net
177# define sat_node sat_addr.s_node
193 struct sockaddr_in in;
194 struct sockaddr_in6 in6;
195 struct sockaddr_un un;
196 struct sockaddr_ipx ipx;
197 struct sockaddr_at at;
198#ifdef OF_HAVE_SOCKADDR_STORAGE
203 struct sockaddr_storage storage;
260 const unsigned char node[_Nonnull IPX_NODE_LEN], uint16_t port);
272 uint8_t node, uint8_t port);
364 const unsigned char node[_Nonnull IPX_NODE_LEN]);
373 unsigned char node[_Nonnull IPX_NODE_LEN]);
446extern bool _OFSocketInit(
void) OF_VISIBILITY_HIDDEN;
447#if defined(OF_HAVE_THREADS) && defined(OF_AMIGAOS) && !defined(OF_MORPHOS)
448extern void _OFSocketDeinit(
void) OF_VISIBILITY_HIDDEN;
450extern int _OFSocketErrNo(
void) OF_VISIBILITY_HIDDEN;
451#if !defined(OF_WII) && !defined(OF_NINTENDO_3DS)
452extern int _OFGetSockName(OFSocketHandle sock,
struct sockaddr *restrict addr,
453 socklen_t *restrict addrLen) OF_VISIBILITY_HIDDEN;
456#if defined(OF_HAVE_THREADS) && defined(OF_AMIGAOS) && !defined(OF_MORPHOS)
457extern OFTLSKey _OFSocketBaseKey OF_VISIBILITY_HIDDEN;
459extern OFTLSKey _OFSocketInterfaceKey OF_VISIBILITY_HIDDEN;
void OFSocketAddressSetAppleTalkPort(OFSocketAddress *address, uint8_t port)
Sets the AppleTalk port of the specified OFSocketAddress.
Definition OFSocket.m:1181
void OFSocketAddressSetAppleTalkNetwork(OFSocketAddress *address, uint16_t network)
Sets the AppleTalk network of the specified OFSocketAddress.
Definition OFSocket.m:1137
uint8_t OFSocketAddressAppleTalkNode(const OFSocketAddress *address)
Gets the AppleTalk node of the specified OFSocketAddress.
Definition OFSocket.m:1172
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:615
OFString * OFSocketAddressUNIXPath(const OFSocketAddress *address)
Gets the UNIX socket path of the specified OFSocketAddress.
Definition OFSocket.m:1056
OFSocketAddress OFSocketAddressParseIPv4(OFString *IP, uint16_t port)
Parses the specified IPv4 and port into an OFSocketAddress.
Definition OFSocket.m:368
void OFSocketAddressSetIPXPort(OFSocketAddress *address, uint16_t port)
Sets the IPX port of the specified OFSocketAddress.
Definition OFSocket.m:1119
uint32_t OFSocketAddressIPXNetwork(const OFSocketAddress *address)
Returns the IPX network of the specified OFSocketAddress.
Definition OFSocket.m:1086
void OFSocketAddressSetAppleTalkNode(OFSocketAddress *address, uint8_t node)
Sets the AppleTalk node of the specified OFSocketAddress.
Definition OFSocket.m:1163
uint16_t OFSocketAddressAppleTalkNetwork(const OFSocketAddress *address)
Returns the AppleTalk network of the specified OFSocketAddress.
Definition OFSocket.m:1150
void OFSocketAddressSetIPXNetwork(OFSocketAddress *address, uint32_t network)
Sets the IPX network of the specified OFSocketAddress.
Definition OFSocket.m:1075
void OFSocketAddressSetIPPort(OFSocketAddress *address, uint16_t port)
Sets the IP port of the specified OFSocketAddress.
Definition OFSocket.m:1028
uint16_t OFSocketAddressIPPort(const OFSocketAddress *address)
Returns the IP port of the specified OFSocketAddress.
Definition OFSocket.m:1043
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:639
uint16_t OFSocketAddressIPXPort(const OFSocketAddress *address)
Returns the IPX port of the specified OFSocketAddress.
Definition OFSocket.m:1128
OFSocketAddress OFSocketAddressParseIPv6(OFString *IP, uint16_t port)
Parses the specified IPv6 and port into an OFSocketAddress.
Definition OFSocket.m:470
bool OFSocketAddressEqual(const OFSocketAddress *address1, const OFSocketAddress *address2)
Compares two OFSocketAddress for equality.
Definition OFSocket.m:664
unsigned long OFSocketAddressHash(const OFSocketAddress *address)
Returns the hash for the specified OFSocketAddress.
Definition OFSocket.m:771
OFString * OFSocketAddressDescription(const OFSocketAddress *address)
Returns a description for the specified OFSocketAddress.
Definition OFSocket.m:999
OFSocketAddress OFSocketAddressParseIP(OFString *IP, uint16_t port)
Parses the specified IP (either v4 or v6) and port into an OFSocketAddress.
Definition OFSocket.m:569
OFString * OFSocketAddressString(const OFSocketAddress *address)
Converts the specified OFSocketAddress to a string.
Definition OFSocket.m:980
OFSocketAddressFamily
A socket address family.
Definition OFSocket.h:107
@ OFSocketAddressFamilyAny
Definition OFSocket.h:121
@ OFSocketAddressFamilyIPX
Definition OFSocket.h:117
@ OFSocketAddressFamilyUNIX
Definition OFSocket.h:115
@ OFSocketAddressFamilyAppleTalk
Definition OFSocket.h:119
@ OFSocketAddressFamilyIPv6
Definition OFSocket.h:113
@ OFSocketAddressFamilyIPv4
Definition OFSocket.h:111
@ OFSocketAddressFamilyUnknown
Definition OFSocket.h:109
uint8_t OFSocketAddressAppleTalkPort(const OFSocketAddress *address)
Returns the AppleTalk port of the specified OFSocketAddress.
Definition OFSocket.m:1190
OFSocketAddress OFSocketAddressMakeUNIX(OFString *path)
Creates a UNIX socket address from the specified path.
Definition OFSocket.m:583
void OFSocketAddressGetIPXNode(const OFSocketAddress *address, unsigned char node[IPX_NODE_LEN])
Gets the IPX node of the specified OFSocketAddress.
Definition OFSocket.m:1109
void OFSocketAddressSetIPXNode(OFSocketAddress *address, const unsigned char node[IPX_NODE_LEN])
Sets the IPX node of the specified OFSocketAddress.
Definition OFSocket.m:1099
A class for handling strings.
Definition OFString.h:139
A struct which represents a host / port pair for a socket.
Definition OFSocket.h:186