2020-06-15 14:18:57 +00:00
|
|
|
#ifndef COSMOPOLITAN_LIBC_SOCK_SOCK_H_
|
|
|
|
#define COSMOPOLITAN_LIBC_SOCK_SOCK_H_
|
2020-08-25 11:23:25 +00:00
|
|
|
#include "libc/bits/bswap.h"
|
2021-06-16 02:52:02 +00:00
|
|
|
#include "libc/calls/struct/sigset.h"
|
|
|
|
#include "libc/calls/struct/timespec.h"
|
2022-06-26 01:17:31 +00:00
|
|
|
#include "libc/sock/struct/linger.h"
|
|
|
|
#include "libc/sock/struct/msghdr.h"
|
|
|
|
#include "libc/sock/struct/pollfd.h"
|
|
|
|
#include "libc/sock/struct/sockaddr.h"
|
2020-06-15 14:18:57 +00:00
|
|
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
|
|
|
COSMOPOLITAN_C_START_
|
|
|
|
/*───────────────────────────────────────────────────────────────────────────│─╗
|
|
|
|
│ cosmopolitan § system api » berkeley sockets ─╬─│┼
|
|
|
|
╚────────────────────────────────────────────────────────────────────────────│*/
|
|
|
|
|
|
|
|
#define INET_ADDRSTRLEN 22
|
|
|
|
|
|
|
|
#define htons(u16) bswap_16(u16)
|
|
|
|
#define ntohs(u16) bswap_16(u16)
|
|
|
|
#define htonl(u32) bswap_32(u32)
|
|
|
|
#define ntohl(u32) bswap_32(u32)
|
|
|
|
|
2021-04-23 17:45:19 +00:00
|
|
|
struct ip_mreq {
|
|
|
|
struct in_addr imr_multiaddr; /* IP multicast address of group */
|
|
|
|
struct in_addr imr_interface; /* local IP address of interface */
|
2021-04-02 02:38:11 +00:00
|
|
|
};
|
|
|
|
|
2021-06-24 17:53:27 +00:00
|
|
|
/*
|
|
|
|
* Structure used in SIOCGIFCONF request.
|
|
|
|
* Used to retrieve interface configuration
|
|
|
|
* for machine (useful for programs which
|
|
|
|
* must know all networks accessible).
|
|
|
|
*/
|
|
|
|
struct ifconf {
|
2021-06-24 19:31:26 +00:00
|
|
|
uint64_t ifc_len; /* size of buffer */
|
2021-06-24 17:53:27 +00:00
|
|
|
union {
|
|
|
|
char *ifcu_buf;
|
|
|
|
struct ifreq *ifcu_req;
|
|
|
|
} ifc_ifcu;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Shortcuts to the ifconf buffer or ifreq array */
|
2021-06-24 19:31:26 +00:00
|
|
|
#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
|
|
|
|
#define ifc_req ifc_ifcu.ifcu_req /* array of structures */
|
2021-06-24 17:53:27 +00:00
|
|
|
|
2021-06-24 19:31:26 +00:00
|
|
|
#define IFHWADDRLEN 6
|
|
|
|
#define IF_NAMESIZE 16
|
|
|
|
#define IFNAMSIZ IF_NAMESIZE
|
2021-06-26 01:41:02 +00:00
|
|
|
|
2021-06-24 17:53:27 +00:00
|
|
|
struct ifreq {
|
|
|
|
union {
|
2021-06-24 19:31:26 +00:00
|
|
|
char ifrn_name[IFNAMSIZ]; /* Interface name, e.g. "en0". */
|
2021-06-24 17:53:27 +00:00
|
|
|
} ifr_ifrn;
|
|
|
|
union {
|
2021-06-24 19:31:26 +00:00
|
|
|
struct sockaddr ifru_addr; /* SIOCGIFADDR */
|
|
|
|
struct sockaddr ifru_dstaddr; /* SIOCGIFDSTADDR */
|
|
|
|
struct sockaddr ifru_netmask; /* SIOCGIFNETMASK */
|
|
|
|
struct sockaddr ifru_broadaddr; /* SIOCGIFBRDADDR */
|
|
|
|
short ifru_flags; /* SIOCGIFFLAGS */
|
|
|
|
char ifru_pad[24]; /* ifru_map is the largest, just pad */
|
2021-06-24 17:53:27 +00:00
|
|
|
} ifr_ifru;
|
|
|
|
};
|
|
|
|
|
2022-07-08 13:29:24 +00:00
|
|
|
#define ifr_name ifr_ifrn.ifrn_name /* interface name */
|
|
|
|
#define ifr_addr ifr_ifru.ifru_addr /* address */
|
|
|
|
#define ifr_netmask ifr_ifru.ifru_netmask /* netmask */
|
2021-06-24 19:31:26 +00:00
|
|
|
#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
|
2022-07-08 13:29:24 +00:00
|
|
|
#define ifr_dstaddr ifr_ifru.ifru_dstaddr /* destination address */
|
|
|
|
#define ifr_flags ifr_ifru.ifru_flags /* flags */
|
2021-06-24 17:53:27 +00:00
|
|
|
|
2021-06-24 19:31:26 +00:00
|
|
|
#define _IOT_ifreq _IOT(_IOTS(char), IFNAMSIZ, _IOTS(char), 16, 0, 0)
|
|
|
|
#define _IOT_ifreq_short _IOT(_IOTS(char), IFNAMSIZ, _IOTS(short), 1, 0, 0)
|
|
|
|
#define _IOT_ifreq_int _IOT(_IOTS(char), IFNAMSIZ, _IOTS(int), 1, 0, 0)
|
2021-06-24 17:53:27 +00:00
|
|
|
|
2020-06-15 14:18:57 +00:00
|
|
|
const char *inet_ntop(int, const void *, char *, uint32_t);
|
2021-02-21 06:52:46 +00:00
|
|
|
int inet_aton(const char *, struct in_addr *);
|
|
|
|
int inet_pton(int, const char *, void *);
|
|
|
|
uint32_t inet_addr(const char *);
|
|
|
|
char *inet_ntoa(struct in_addr);
|
2020-06-15 14:18:57 +00:00
|
|
|
int parseport(const char *);
|
2021-06-24 19:31:26 +00:00
|
|
|
uint32_t *GetHostIps(void);
|
2020-06-15 14:18:57 +00:00
|
|
|
|
Introduce --strace flag for system call tracing
This is similar to the --ftrace (c function call trace) flag, except
it's less noisy since it only logs system calls to stderr. Having this
flag is valuable because (1) system call tracing tells us a lot about
the behavior of complex programs and (2) it's usually very hard to get
system call tracing on various operating systems, e.g. strace, ktrace,
dtruss, truss, nttrace, etc. Especially on Apple platforms where even
with the special boot trick, debuggers still aren't guaranteed to work.
make -j8 o//examples
o//examples/hello.com --strace
This is enabled by default in MODE=, MODE=opt, and MODE=dbg. In MODE=dbg
extra information will be printed.
make -j8 MODE=dbg o/dbg/examples
o/dbg/examples/hello.com --strace |& less
This change also changes:
- Rename IsText() → _istext()
- Rename IsUtf8() → _isutf8()
- Fix madvise() on Windows NT
- Fix empty string case of inet_ntop()
- vfork() wrapper now saves and restores errno
- Update xsigaction() to yoink syscall support
2022-03-19 01:07:28 +00:00
|
|
|
int socket(int, int, int);
|
|
|
|
int accept(int, void *, uint32_t *);
|
|
|
|
int accept4(int, void *, uint32_t *, int);
|
2020-09-07 04:39:00 +00:00
|
|
|
int bind(int, const void *, uint32_t);
|
|
|
|
int connect(int, const void *, uint32_t);
|
2020-06-15 14:18:57 +00:00
|
|
|
int listen(int, int);
|
|
|
|
int shutdown(int, int);
|
Introduce --strace flag for system call tracing
This is similar to the --ftrace (c function call trace) flag, except
it's less noisy since it only logs system calls to stderr. Having this
flag is valuable because (1) system call tracing tells us a lot about
the behavior of complex programs and (2) it's usually very hard to get
system call tracing on various operating systems, e.g. strace, ktrace,
dtruss, truss, nttrace, etc. Especially on Apple platforms where even
with the special boot trick, debuggers still aren't guaranteed to work.
make -j8 o//examples
o//examples/hello.com --strace
This is enabled by default in MODE=, MODE=opt, and MODE=dbg. In MODE=dbg
extra information will be printed.
make -j8 MODE=dbg o/dbg/examples
o/dbg/examples/hello.com --strace |& less
This change also changes:
- Rename IsText() → _istext()
- Rename IsUtf8() → _isutf8()
- Fix madvise() on Windows NT
- Fix empty string case of inet_ntop()
- vfork() wrapper now saves and restores errno
- Update xsigaction() to yoink syscall support
2022-03-19 01:07:28 +00:00
|
|
|
int getsockname(int, void *, uint32_t *);
|
|
|
|
int getpeername(int, void *, uint32_t *);
|
|
|
|
ssize_t send(int, const void *, size_t, int);
|
2020-06-15 14:18:57 +00:00
|
|
|
ssize_t recv(int, void *, size_t, int);
|
Introduce --strace flag for system call tracing
This is similar to the --ftrace (c function call trace) flag, except
it's less noisy since it only logs system calls to stderr. Having this
flag is valuable because (1) system call tracing tells us a lot about
the behavior of complex programs and (2) it's usually very hard to get
system call tracing on various operating systems, e.g. strace, ktrace,
dtruss, truss, nttrace, etc. Especially on Apple platforms where even
with the special boot trick, debuggers still aren't guaranteed to work.
make -j8 o//examples
o//examples/hello.com --strace
This is enabled by default in MODE=, MODE=opt, and MODE=dbg. In MODE=dbg
extra information will be printed.
make -j8 MODE=dbg o/dbg/examples
o/dbg/examples/hello.com --strace |& less
This change also changes:
- Rename IsText() → _istext()
- Rename IsUtf8() → _isutf8()
- Fix madvise() on Windows NT
- Fix empty string case of inet_ntop()
- vfork() wrapper now saves and restores errno
- Update xsigaction() to yoink syscall support
2022-03-19 01:07:28 +00:00
|
|
|
ssize_t recvmsg(int, struct msghdr *, int);
|
2020-06-15 14:18:57 +00:00
|
|
|
ssize_t recvfrom(int, void *, size_t, uint32_t, void *, uint32_t *);
|
Introduce --strace flag for system call tracing
This is similar to the --ftrace (c function call trace) flag, except
it's less noisy since it only logs system calls to stderr. Having this
flag is valuable because (1) system call tracing tells us a lot about
the behavior of complex programs and (2) it's usually very hard to get
system call tracing on various operating systems, e.g. strace, ktrace,
dtruss, truss, nttrace, etc. Especially on Apple platforms where even
with the special boot trick, debuggers still aren't guaranteed to work.
make -j8 o//examples
o//examples/hello.com --strace
This is enabled by default in MODE=, MODE=opt, and MODE=dbg. In MODE=dbg
extra information will be printed.
make -j8 MODE=dbg o/dbg/examples
o/dbg/examples/hello.com --strace |& less
This change also changes:
- Rename IsText() → _istext()
- Rename IsUtf8() → _isutf8()
- Fix madvise() on Windows NT
- Fix empty string case of inet_ntop()
- vfork() wrapper now saves and restores errno
- Update xsigaction() to yoink syscall support
2022-03-19 01:07:28 +00:00
|
|
|
ssize_t sendmsg(int, const struct msghdr *, int);
|
2020-06-15 14:18:57 +00:00
|
|
|
ssize_t readv(int, const struct iovec *, int);
|
|
|
|
ssize_t writev(int, const struct iovec *, int);
|
|
|
|
ssize_t sendfile(int, int, int64_t *, size_t);
|
Introduce --strace flag for system call tracing
This is similar to the --ftrace (c function call trace) flag, except
it's less noisy since it only logs system calls to stderr. Having this
flag is valuable because (1) system call tracing tells us a lot about
the behavior of complex programs and (2) it's usually very hard to get
system call tracing on various operating systems, e.g. strace, ktrace,
dtruss, truss, nttrace, etc. Especially on Apple platforms where even
with the special boot trick, debuggers still aren't guaranteed to work.
make -j8 o//examples
o//examples/hello.com --strace
This is enabled by default in MODE=, MODE=opt, and MODE=dbg. In MODE=dbg
extra information will be printed.
make -j8 MODE=dbg o/dbg/examples
o/dbg/examples/hello.com --strace |& less
This change also changes:
- Rename IsText() → _istext()
- Rename IsUtf8() → _isutf8()
- Fix madvise() on Windows NT
- Fix empty string case of inet_ntop()
- vfork() wrapper now saves and restores errno
- Update xsigaction() to yoink syscall support
2022-03-19 01:07:28 +00:00
|
|
|
int getsockopt(int, int, int, void *, uint32_t *);
|
2020-09-07 04:39:00 +00:00
|
|
|
int setsockopt(int, int, int, const void *, uint32_t);
|
Introduce --strace flag for system call tracing
This is similar to the --ftrace (c function call trace) flag, except
it's less noisy since it only logs system calls to stderr. Having this
flag is valuable because (1) system call tracing tells us a lot about
the behavior of complex programs and (2) it's usually very hard to get
system call tracing on various operating systems, e.g. strace, ktrace,
dtruss, truss, nttrace, etc. Especially on Apple platforms where even
with the special boot trick, debuggers still aren't guaranteed to work.
make -j8 o//examples
o//examples/hello.com --strace
This is enabled by default in MODE=, MODE=opt, and MODE=dbg. In MODE=dbg
extra information will be printed.
make -j8 MODE=dbg o/dbg/examples
o/dbg/examples/hello.com --strace |& less
This change also changes:
- Rename IsText() → _istext()
- Rename IsUtf8() → _isutf8()
- Fix madvise() on Windows NT
- Fix empty string case of inet_ntop()
- vfork() wrapper now saves and restores errno
- Update xsigaction() to yoink syscall support
2022-03-19 01:07:28 +00:00
|
|
|
int socketpair(int, int, int, int[2]);
|
|
|
|
int poll(struct pollfd *, uint64_t, int32_t);
|
2020-06-15 14:18:57 +00:00
|
|
|
int ppoll(struct pollfd *, uint64_t, const struct timespec *,
|
Introduce --strace flag for system call tracing
This is similar to the --ftrace (c function call trace) flag, except
it's less noisy since it only logs system calls to stderr. Having this
flag is valuable because (1) system call tracing tells us a lot about
the behavior of complex programs and (2) it's usually very hard to get
system call tracing on various operating systems, e.g. strace, ktrace,
dtruss, truss, nttrace, etc. Especially on Apple platforms where even
with the special boot trick, debuggers still aren't guaranteed to work.
make -j8 o//examples
o//examples/hello.com --strace
This is enabled by default in MODE=, MODE=opt, and MODE=dbg. In MODE=dbg
extra information will be printed.
make -j8 MODE=dbg o/dbg/examples
o/dbg/examples/hello.com --strace |& less
This change also changes:
- Rename IsText() → _istext()
- Rename IsUtf8() → _isutf8()
- Fix madvise() on Windows NT
- Fix empty string case of inet_ntop()
- vfork() wrapper now saves and restores errno
- Update xsigaction() to yoink syscall support
2022-03-19 01:07:28 +00:00
|
|
|
const struct sigset *);
|
|
|
|
ssize_t sendto(int, const void *, size_t, uint32_t, const void *, uint32_t);
|
2020-06-15 14:18:57 +00:00
|
|
|
|
|
|
|
COSMOPOLITAN_C_END_
|
|
|
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
|
|
#endif /* COSMOPOLITAN_LIBC_SOCK_SOCK_H_ */
|