ObjFW
Loading...
Searching...
No Matches
OFSocket+Private.h
1/*
2 * Copyright (c) 2008-2026 Jonathan Schleifer <js@nil.im>
3 *
4 * All rights reserved.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License version 3.0 only,
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13 * version 3.0 for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * version 3.0 along with this program. If not, see
17 * <https://www.gnu.org/licenses/>.
18 */
19
20#include "config.h"
21
22#include "unistd_wrapper.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#import "OFSocket.h"
32
33#ifndef INADDR_NONE
34# define INADDR_NONE ((in_addr_t)-1)
35#endif
36
37#ifndef SOMAXCONN
38/*
39 * Use 16 as everything > 17 fails on Nintendo 3DS and 16 is a less arbitrary
40 * number than 17.
41 */
42# define SOMAXCONN 16
43#endif
44
45#ifndef SOCK_CLOEXEC
46# define SOCK_CLOEXEC 0
47#endif
48
49#if defined(OF_AMIGAOS)
50# ifdef OF_MORPHOS
51# include <proto/socket.h>
52# else
53# include <proto/bsdsocket.h>
54# endif
55# include <sys/filio.h>
56# define closesocket(sock) CloseSocket(sock)
57# define ioctlsocket(fd, req, arg) IoctlSocket(fd, req, arg)
58# define hstrerror(err) "unknown (no hstrerror)"
59# define SOCKET_ERROR -1
60# ifdef OF_HAVE_THREADS
61# define SocketBase ((struct Library *)OFTLSKeyGet(_OFSocketBaseKey))
62# ifdef OF_AMIGAOS4
63# define ISocket ((struct SocketIFace *)OFTLSKeyGet(_OFSocketInterfaceKey))
64# endif
65# endif
66# ifdef OF_MORPHOS
67typedef uint32_t in_addr_t;
68# endif
69#elif !defined(OF_WINDOWS) && !defined(OF_WII)
70# define closesocket(sock) close(sock)
71# define ioctlsocket(...) ioctl(__VA_ARGS__)
72#endif
73
74#ifdef OF_WII
75# define accept(sock, addr, addrlen) net_accept(sock, addr, addrlen)
76# define bind(sock, addr, addrlen) net_bind(sock, addr, addrlen)
77# define closesocket(sock) net_close(sock)
78# define connect(sock, addr, addrlen) \
79 net_connect(sock, (struct sockaddr *)addr, addrlen)
80# define fcntl(fd, cmd, flags) net_fcntl(fd, cmd, flags)
81# define h_errno 0
82# define hstrerror(err) "unknown (no hstrerror)"
83# define ioctlsocket(...) net_ioctl(__VA_ARGS__)
84# define listen(sock, backlog) net_listen(sock, backlog)
85# define poll(fds, nfds, timeout) net_poll(fds, nfds, timeout)
86# define recv(sock, buf, len, flags) net_recv(sock, buf, len, flags)
87# define recvfrom(sock, buf, len, flags, addr, addrlen) \
88 net_recvfrom(sock, buf, len, flags, addr, addrlen)
89# define select(nfds, readfds, writefds, errorfds, timeout) \
90 net_select(nfds, readfds, writefds, errorfds, timeout)
91# define send(sock, buf, len, flags) net_send(sock, buf, len, flags)
92# define sendto(sock, buf, len, flags, addr, addrlen) \
93 net_sendto(sock, buf, len, flags, (struct sockaddr *)(addr), addrlen)
94# define setsockopt(sock, level, name, value, len) \
95 net_setsockopt(sock, level, name, value, len)
96# define socket(domain, type, proto) net_socket(domain, type, proto)
97typedef u32 in_addr_t;
98typedef u32 nfds_t;
99#endif
100
101OF_ASSUME_NONNULL_BEGIN
102
103#ifdef __cplusplus
104extern "C" {
105#endif
106extern bool _OFSocketInit(void) OF_VISIBILITY_INTERNAL;
107#if defined(OF_HAVE_THREADS) && defined(OF_AMIGAOS)
108extern void _OFSocketDeinit(void) OF_VISIBILITY_INTERNAL;
109#endif
110extern int _OFSocketErrNo(void) OF_VISIBILITY_INTERNAL;
111#if !defined(OF_WII) && !defined(OF_NINTENDO_3DS)
112extern int _OFGetSockName(OFSocketHandle sock, struct sockaddr *restrict addr,
113 socklen_t *restrict addrLen) OF_VISIBILITY_INTERNAL;
114#endif
115
116#if defined(OF_HAVE_THREADS) && defined(OF_AMIGAOS)
117extern OFTLSKey _OFSocketBaseKey OF_VISIBILITY_INTERNAL;
118# ifdef OF_AMIGAOS4
119extern OFTLSKey _OFSocketInterfaceKey OF_VISIBILITY_INTERNAL;
120# endif
121#endif
122#ifdef __cplusplus
123}
124#endif
125
126OF_ASSUME_NONNULL_END