|
miniOS
x86_64 hobby kernel with SMP, VFS, and POSIX process model
|
#include <stddef.h>#include <stdint.h>

Go to the source code of this file.
Classes | |
| struct | net_sock_rx_entry |
| One slot in the socket rx ring. More... | |
| struct | net_sock |
| Kernel socket state. More... | |
Macros | |
| #define | SOCK_PROTO_UDP 0 |
| #define | SOCK_PROTO_TCP 1 |
| #define | SOCK_PROTO_RAW 2 |
| #define | NET_SOCK_RX_BUF_SIZE 1500 |
| #define | NET_SOCK_POOL_SIZE 4 |
| #define | NET_SOCK_RX_RING_SLOTS 2 |
Typedefs | |
| typedef struct net_sock_rx_entry | net_sock_rx_entry_t |
| One slot in the socket rx ring. | |
| typedef struct net_sock | net_sock_t |
| Kernel socket state. | |
Functions | |
| static int | net_sock_has_data (const net_sock_t *s) |
| Returns non-zero when the socket rx ring has at least one entry ready. | |
| static int | net_sock_ring_full (const net_sock_t *s) |
| Returns non-zero when the socket rx ring is full (all slots occupied). | |
| net_sock_t * | net_sock_alloc (int proto) |
| Allocate a socket from the static pool. | |
| void | net_sock_free (net_sock_t *sock) |
| Free a socket slot back to the pool. Calls raw_remove/udp_remove/tcp_abort based on sock->proto before freeing the slot; sets sock->pcb=NULL before clearing in_use (UAF safety — prevents recv callbacks from firing on a freed slot). | |
| int | net_sock_recv (net_sock_t *sock, void *buf, size_t len, int flags) |
| Receive data from socket into buf. | |
| int | net_sock_send (net_sock_t *sock, const void *buf, size_t len, int flags) |
| Send data through socket. | |
| int | net_sock_close (net_sock_t *sock) |
| Close socket: remove lwIP PCB and free pool slot. | |
| #define NET_SOCK_POOL_SIZE 4 |
Max concurrent sockets (matches MEMP_NUM_*_PCB)
| #define NET_SOCK_RX_BUF_SIZE 1500 |
| #define NET_SOCK_RX_RING_SLOTS 2 |
Slots in the per-socket RAW rx ring
| #define SOCK_PROTO_RAW 2 |
Raw IP protocol selector for net_sock_alloc()
| #define SOCK_PROTO_TCP 1 |
TCP protocol selector for net_sock_alloc()
| #define SOCK_PROTO_UDP 0 |
UDP protocol selector for net_sock_alloc()
| typedef struct net_sock_rx_entry net_sock_rx_entry_t |
One slot in the socket rx ring.
Used for RAW sockets (2 slots) and by UDP/TCP (single-slot at index 0).
| typedef struct net_sock net_sock_t |
Kernel socket state.
One net_sock_t per open socket fd. Owns the lwIP PCB pointer and a 2-slot receive ring for RAW sockets (UDP/TCP use slot 0 only). No dynamic allocation beyond the static pool.
| net_sock_t * net_sock_alloc | ( | int | proto | ) |
Allocate a socket from the static pool.
| proto | SOCK_PROTO_UDP, SOCK_PROTO_TCP, or SOCK_PROTO_RAW |
Scans the pool for a free slot, zeroes it, and sets proto and in_use. Returns NULL if all NET_SOCK_POOL_SIZE slots are occupied.


| int net_sock_close | ( | net_sock_t * | sock | ) |
Close socket: remove lwIP PCB and free pool slot.
Close socket: remove lwIP PCB and free pool slot.


| void net_sock_free | ( | net_sock_t * | sock | ) |
Free a socket slot back to the pool. Calls raw_remove/udp_remove/tcp_abort based on sock->proto before freeing the slot; sets sock->pcb=NULL before clearing in_use (UAF safety — prevents recv callbacks from firing on a freed slot).
Free a socket slot back to the pool. Calls raw_remove/udp_remove/tcp_abort based on sock->proto before freeing the slot; sets sock->pcb=NULL before clearing in_use (UAF safety — prevents recv callbacks from firing on a freed slot).
D-04: call lwIP teardown BEFORE nulling pcb, so the raw/udp/tcp layer removes the pcb from its internal list. Then null pcb BEFORE clearing in_use so any recv callback that races cannot reach a freed slot.

|
inlinestatic |
Returns non-zero when the socket rx ring has at least one entry ready.

| int net_sock_recv | ( | net_sock_t * | sock, |
| void * | buf, | ||
| size_t | len, | ||
| int | flags ) |
Receive data from socket into buf.
Receive data from socket into buf.
Returns -1 immediately when PCB is NULL (socket not connected) or when the rx ring is empty. Copies min(slot->len, len) bytes on success and advances rx_head.


|
inlinestatic |
Returns non-zero when the socket rx ring is full (all slots occupied).

| int net_sock_send | ( | net_sock_t * | sock, |
| const void * | buf, | ||
| size_t | len, | ||
| int | flags ) |
Send data through socket.
Returns -1 when PCB is NULL (socket not connected). Actual lwIP send (udp_send/tcp_write) is implemented here for each protocol type.

