|
ginnOS
The reference: libc, the libraries and the kernel
|
IPv4 sockets: TCP (SOCK_STREAM), UDP (SOCK_DGRAM) and ICMP echo (SOCK_DGRAM with IPPROTO_ICMP, for ping, as Linux's ping sockets). More...
Go to the source code of this file.
Data Structures | |
| struct | ksockaddr_in_t |
Macros | |
| #define | AF_INET 2 |
| #define | SOCK_DGRAM 2 |
| #define | IPPROTO_IP 0 |
| #define | IPPROTO_ICMP 1 |
| #define | IPPROTO_TCP 6 |
| #define | IPPROTO_UDP 17 |
| #define | SO_REUSEADDR 2 |
| #define | SO_TYPE 3 |
| #define | SO_ERROR 4 |
| #define | SO_BROADCAST 6 |
| #define | SO_SNDBUF 7 |
| #define | SO_RCVBUF 8 |
| #define | SO_KEEPALIVE 9 |
| #define | TCP_NODELAY 1 |
| #define | TCP_KEEPCNT 6 |
| #define | FIONREAD 0x541B |
| #define | MSG_PEEK 0x0002 |
| #define | MSG_TRUNC 0x0020 |
| #define | SHUT_RD 0 |
| #define | SHUT_WR 1 |
| #define | SHUT_RDWR 2 |
| #define | INET_RECEIVE_MAX (64 * 1024) |
| #define | INET_PORT_FIRST 49152 |
Typedefs | |
| typedef struct inet_socket | inet_socket_t |
Functions | |
| int32_t | inet_socket_create (uint32_t type, uint32_t protocol, uint32_t flags, struct file **out) |
| make a new socket and its open file. | |
| inet_socket_t * | inet_socket_of (struct file *file) |
| the socket of an open file, or NULL if the file is not an IPv4 socket. | |
| int32_t | inet_socket_bind (inet_socket_t *s, const ksockaddr_in_t *addr) |
| give a socket a local address and port (port 0: one not in use). | |
| int32_t | inet_socket_connect (struct file *file, const ksockaddr_in_t *addr) |
| a datagram socket: set the address datagrams go to and the only one they come from; AF_UNSPEC (family 0) takes the connection away. | |
| int32_t | inet_socket_listen (inet_socket_t *s, uint32_t backlog) |
| a stream socket takes connections. | |
| int32_t | inet_socket_accept (struct file *file, uint32_t flags, struct file **out, ksockaddr_in_t *peer) |
| take the next connection of a listening stream socket (blocks unless the file is non-blocking). | |
| int32_t | inet_socket_send (struct file *file, const kiovec_t *iov, uint32_t iov_count, const ksockaddr_in_t *to, uint32_t flags) |
| send one datagram from user memory, or data on a stream (as much as fits; it blocks for room unless the file is non-blocking). | |
| int32_t | inet_socket_receive (struct file *file, const kiovec_t *iov, uint32_t iov_count, ksockaddr_in_t *from, uint32_t flags, bool dontwait, uint32_t *full) |
| receive one datagram into user memory (blocks unless the file is non-blocking or dontwait). | |
| int32_t | inet_socket_name (inet_socket_t *s, bool peer, ksockaddr_in_t *out) |
| the local address (peer false) or the connected one (peer true). | |
| int32_t | inet_socket_set_option (inet_socket_t *s, int32_t level, int32_t name, int32_t value) |
| setsockopt and getsockopt (an int value). | |
| int32_t | inet_socket_get_option (inet_socket_t *s, int32_t level, int32_t name, int32_t *value) |
| int32_t | inet_socket_shutdown (inet_socket_t *s, int32_t how) |
| shutdown: SHUT_RD, SHUT_WR or SHUT_RDWR. | |
| bool | inet_socket_deliver_udp (uint32_t dst, uint16_t dst_port, uint32_t src, uint16_t src_port, const uint8_t *data, uint32_t length) |
| give a received UDP datagram to the socket it is for (net_lock held). | |
| void | inet_socket_deliver_echo (uint32_t src, uint16_t id, const uint8_t *message, uint32_t length) |
| give a received echo reply to the ICMP socket with its identifier (net_lock held). | |
IPv4 sockets: TCP (SOCK_STREAM), UDP (SOCK_DGRAM) and ICMP echo (SOCK_DGRAM with IPPROTO_ICMP, for ping, as Linux's ping sockets).
a TCP socket has a tcp_conn_t (tcp.h): its connection, or its listener. a datagram socket keeps the datagrams it receives in a queue, up to INET_RECEIVE_MAX bytes; more are dropped. an ICMP socket sends an echo request that the program writes (type, code, then the data), with the identifier set to the socket's port and the checksum filled in, and it receives the echo replies with that identifier.
the layouts below are the user ABI (<netinet/in.h> and <sys/socket.h> in libc); they are the same as Linux's.
| #define AF_INET 2 |
| #define SOCK_DGRAM 2 |
| #define IPPROTO_IP 0 |
| #define IPPROTO_ICMP 1 |
| #define IPPROTO_TCP 6 |
| #define IPPROTO_UDP 17 |
| #define SO_REUSEADDR 2 |
| #define SO_TYPE 3 |
| #define SO_ERROR 4 |
| #define SO_BROADCAST 6 |
| #define SO_SNDBUF 7 |
| #define SO_RCVBUF 8 |
| #define SO_KEEPALIVE 9 |
| #define TCP_NODELAY 1 |
| #define TCP_KEEPCNT 6 |
| #define FIONREAD 0x541B |
| #define MSG_PEEK 0x0002 |
| #define MSG_TRUNC 0x0020 |
| #define SHUT_RD 0 |
| #define SHUT_WR 1 |
| #define SHUT_RDWR 2 |
| #define INET_RECEIVE_MAX (64 * 1024) |
| #define INET_PORT_FIRST 49152 |
| typedef struct inet_socket inet_socket_t |
make a new socket and its open file.
| type | SOCK_STREAM or SOCK_DGRAM. |
| protocol | 0, or IPPROTO_TCP for a stream; IPPROTO_UDP or IPPROTO_ICMP (ping) for datagrams. |
| flags | O_NONBLOCK or 0. |
| inet_socket_t * inet_socket_of | ( | struct file * | file | ) |
the socket of an open file, or NULL if the file is not an IPv4 socket.
| int32_t inet_socket_bind | ( | inet_socket_t * | s, |
| const ksockaddr_in_t * | addr ) |
give a socket a local address and port (port 0: one not in use).
| int32_t inet_socket_connect | ( | struct file * | file, |
| const ksockaddr_in_t * | addr ) |
a datagram socket: set the address datagrams go to and the only one they come from; AF_UNSPEC (family 0) takes the connection away.
a stream: connect (blocks for the handshake unless the file is non-blocking).
| int32_t inet_socket_listen | ( | inet_socket_t * | s, |
| uint32_t | backlog ) |
a stream socket takes connections.
| int32_t inet_socket_accept | ( | struct file * | file, |
| uint32_t | flags, | ||
| struct file ** | out, | ||
| ksockaddr_in_t * | peer ) |
take the next connection of a listening stream socket (blocks unless the file is non-blocking).
| flags | O_NONBLOCK or 0, for the new file. |
| peer | receives the address of the other end. |
| int32_t inet_socket_send | ( | struct file * | file, |
| const kiovec_t * | iov, | ||
| uint32_t | iov_count, | ||
| const ksockaddr_in_t * | to, | ||
| uint32_t | flags ) |
send one datagram from user memory, or data on a stream (as much as fits; it blocks for room unless the file is non-blocking).
| to | where it goes, or NULL for the connected address (a stream does not use it). |
| flags | MSG_DONTWAIT. |
| int32_t inet_socket_receive | ( | struct file * | file, |
| const kiovec_t * | iov, | ||
| uint32_t | iov_count, | ||
| ksockaddr_in_t * | from, | ||
| uint32_t | flags, | ||
| bool | dontwait, | ||
| uint32_t * | full ) |
receive one datagram into user memory (blocks unless the file is non-blocking or dontwait).
a datagram longer than the buffers is cut; the rest of it is gone. a stream gives the bytes it has (0 at the end of the stream; -ECONNRESET once after a reset).
| from | receives the sender (may be NULL). |
| flags | MSG_PEEK: leave it in the queue. |
| full | receives the datagram's whole length (may be NULL). |
| int32_t inet_socket_name | ( | inet_socket_t * | s, |
| bool | peer, | ||
| ksockaddr_in_t * | out ) |
the local address (peer false) or the connected one (peer true).
| int32_t inet_socket_set_option | ( | inet_socket_t * | s, |
| int32_t | level, | ||
| int32_t | name, | ||
| int32_t | value ) |
setsockopt and getsockopt (an int value).
| int32_t inet_socket_get_option | ( | inet_socket_t * | s, |
| int32_t | level, | ||
| int32_t | name, | ||
| int32_t * | value ) |
| int32_t inet_socket_shutdown | ( | inet_socket_t * | s, |
| int32_t | how ) |
shutdown: SHUT_RD, SHUT_WR or SHUT_RDWR.
| bool inet_socket_deliver_udp | ( | uint32_t | dst, |
| uint16_t | dst_port, | ||
| uint32_t | src, | ||
| uint16_t | src_port, | ||
| const uint8_t * | data, | ||
| uint32_t | length ) |
give a received UDP datagram to the socket it is for (net_lock held).