libnx v4.9.0
Loading...
Searching...
No Matches
bsd.h
Go to the documentation of this file.
1/**
2 * @file bsd.h
3 * @brief BSD sockets (bsd:u/s) service IPC wrapper. Please use the standard <sys/socket.h> interface instead.
4 * @author plutoo
5 * @author TuxSH
6 * @copyright libnx Authors
7 */
8#pragma once
9#include <sys/socket.h> // for socklen_t
10#include <sys/select.h> // for fd_set
11#include <poll.h> // for struct pollfd, ndfs_t
12
13#include "../types.h"
14#include "../kernel/tmem.h"
15#include "../sf/service.h"
16
17/// Configuration structure for bsdInitalize
18typedef struct {
19 u32 version; ///< Observed 1 on [2.0.0+] LibAppletWeb, 2 on [3.0.0+].
20
21 void *tmem_buffer; ///< User-provided buffer to use as backing for transfer memory. If NULL, a buffer will be allocated automatically. Must be large enough and page-aligned.
22 size_t tmem_buffer_size; ///< Size of the user-provided transfer memory backing buffer. Must be large enough and page-aligned.
23
24 u32 tcp_tx_buf_size; ///< Size of the TCP transfer (send) buffer (initial or fixed).
25 u32 tcp_rx_buf_size; ///< Size of the TCP receive buffer (initial or fixed).
26 u32 tcp_tx_buf_max_size; ///< Maximum size of the TCP transfer (send) buffer. If it is 0, the size of the buffer is fixed to its initial value.
27 u32 tcp_rx_buf_max_size; ///< Maximum size of the TCP receive buffer. If it is 0, the size of the buffer is fixed to its initial value.
28
29 u32 udp_tx_buf_size; ///< Size of the UDP transfer (send) buffer (typically 0x2400 bytes).
30 u32 udp_rx_buf_size; ///< Size of the UDP receive buffer (typically 0xA500 bytes).
31
32 u32 sb_efficiency; ///< Number of buffers for each socket (standard values range from 1 to 8).
34
35extern __thread Result g_bsdResult; ///< Last Switch "result", per-thread
36extern __thread int g_bsdErrno; ///< Last errno, per-thread
37
38/// Fetch the default configuration for bsdInitialize.
40
41/// Initialize the BSD service.
42Result bsdInitialize(const BsdInitConfig *config, u32 num_sessions, u32 service_type);
43
44/// Exit the BSD service.
45void bsdExit(void);
46
47/// Gets the Service object for the actual BSD service session.
49
50/// Creates a socket.
51int bsdSocket(int domain, int type, int protocol);
52/// Like @ref bsdSocket but the newly created socket is immediately shut down.
53int bsdSocketExempt(int domain, int type, int protocol);
54int bsdOpen(const char *pathname, int flags);
55int bsdSelect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
56int bsdPoll(struct pollfd *fds, nfds_t nfds, int timeout);
57int bsdSysctl(const int *name, unsigned int namelen, void *oldp, size_t *oldlenp, const void *newp, size_t newlen);
58ssize_t bsdRecv(int sockfd, void *buf, size_t len, int flags);
59ssize_t bsdRecvFrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen);
60ssize_t bsdSend(int sockfd, const void* buf, size_t len, int flags);
61ssize_t bsdSendTo(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen);
62int bsdAccept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
63int bsdBind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
64int bsdConnect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
65int bsdGetPeerName(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
66int bsdGetSockName(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
67int bsdGetSockOpt(int sockfd, int level, int optname, void *optval, socklen_t *optlen);
68int bsdListen(int sockfd, int backlog);
69/// Made non-variadic for convenience.
70int bsdIoctl(int fd, int request, void *data);
71/// Made non-variadic for convenience.
72int bsdFcntl(int fd, int cmd, int flags);
73int bsdSetSockOpt(int sockfd, int level, int optname, const void *optval, socklen_t optlen);
74int bsdShutdown(int sockfd, int how);
75int bsdShutdownAllSockets(int how);
76ssize_t bsdWrite(int fd, const void *buf, size_t count);
77ssize_t bsdRead(int fd, void *buf, size_t count);
78int bsdClose(int fd);
79/// Duplicate a socket (bsd:s).
80int bsdDuplicateSocket(int sockfd);
81int bsdRecvMMsg(int sockfd, void *buf, size_t size, unsigned int vlen, int flags, struct timespec *timeout);
82int bsdSendMMsg(int sockfd, void *buf, size_t size, unsigned int vlen, int flags);
83
84// TODO: Reverse-engineer GetResourceStatistics.
Result bsdInitialize(const BsdInitConfig *config, u32 num_sessions, u32 service_type)
Initialize the BSD service.
int bsdDuplicateSocket(int sockfd)
Duplicate a socket (bsd:s).
int bsdFcntl(int fd, int cmd, int flags)
Made non-variadic for convenience.
Service * bsdGetServiceSession(void)
Gets the Service object for the actual BSD service session.
int bsdSocket(int domain, int type, int protocol)
Creates a socket.
const BsdInitConfig * bsdGetDefaultInitConfig(void)
Fetch the default configuration for bsdInitialize.
__thread int g_bsdErrno
Last errno, per-thread.
int bsdIoctl(int fd, int request, void *data)
Made non-variadic for convenience.
void bsdExit(void)
Exit the BSD service.
int bsdSocketExempt(int domain, int type, int protocol)
Like bsdSocket but the newly created socket is immediately shut down.
__thread Result g_bsdResult
Last Switch "result", per-thread.
Configuration structure for bsdInitalize.
Definition bsd.h:18
u32 udp_rx_buf_size
Size of the UDP receive buffer (typically 0xA500 bytes).
Definition bsd.h:30
u32 sb_efficiency
Number of buffers for each socket (standard values range from 1 to 8).
Definition bsd.h:32
u32 tcp_tx_buf_max_size
Maximum size of the TCP transfer (send) buffer. If it is 0, the size of the buffer is fixed to its in...
Definition bsd.h:26
size_t tmem_buffer_size
Size of the user-provided transfer memory backing buffer. Must be large enough and page-aligned.
Definition bsd.h:22
u32 udp_tx_buf_size
Size of the UDP transfer (send) buffer (typically 0x2400 bytes).
Definition bsd.h:29
u32 tcp_rx_buf_size
Size of the TCP receive buffer (initial or fixed).
Definition bsd.h:25
u32 version
Observed 1 on [2.0.0+] LibAppletWeb, 2 on [3.0.0+].
Definition bsd.h:19
void * tmem_buffer
User-provided buffer to use as backing for transfer memory. If NULL, a buffer will be allocated autom...
Definition bsd.h:21
u32 tcp_rx_buf_max_size
Maximum size of the TCP receive buffer. If it is 0, the size of the buffer is fixed to its initial va...
Definition bsd.h:27
u32 tcp_tx_buf_size
Size of the TCP transfer (send) buffer (initial or fixed).
Definition bsd.h:24
Service object structure.
Definition service.h:14
u32 Result
Function error code result type.
Definition types.h:44
uint32_t u32
32-bit unsigned integer.
Definition types.h:21