Overview
Aurora OS provides a simplified Berkeley sockets API for network communication. The implementation is built on top of a real TCP/IP stack with support for TCP connections and UDP datagrams.Network syscalls use file descriptors from the process fd table. Socket fds are marked with
flags = -1 to distinguish them from regular files.SYS_SOCKET
Create a network socket and return a file descriptor. Syscall Number: 24Parameters
Protocol family (e.g., AF_INET). Currently ignored; all sockets use IPv4.
Socket type (SOCK_STREAM for TCP, SOCK_DGRAM for UDP). Currently ignored.
Protocol number. Currently ignored; defaults to TCP.
Returns
- On success: file descriptor for the socket (0-31)
- On error: -1 (no free fd slots)
Behavior
Allocates a file descriptor and marks it as a socket:- Sets
in_use = 1 - Sets
vfs_node = 0(no VFS backing) - Sets
flags = -1to mark as socket - Sets
offset = 0(will store connection ID later)
Example
SYS_BIND
Bind a socket to a local address and port. Syscall Number: 25Parameters
Socket file descriptor
Port number to bind to (host byte order)
Returns
- On success: 0
- On error: -1 (invalid fd)
Behavior
The current implementation only binds the port number. The address is always 0.0.0.0 (all interfaces).
fd_entry.offset for later use by SYS_LISTEN.
Example
SYS_CONNECT
Connect a socket to a remote address and port. Syscall Number: 26Parameters
Socket file descriptor
Remote IPv4 address (network byte order)
Remote port number (host byte order)
Returns
- On success: 0
- On error: -1 (connection failed or invalid fd)
Behavior
- Validates the socket file descriptor
- Calls
tcp_connect()from the network stack:- Initiates TCP three-way handshake
- Allocates a connection ID
- Stores the connection ID in
fd_entry.offset - Returns 0 on successful connection
This is a blocking operation. The syscall waits for the TCP handshake to complete before returning.
Example
SYS_LISTEN
Listen for incoming connections on a bound socket. Syscall Number: 38Parameters
Socket file descriptor (must be bound via SYS_BIND)
Returns
- On success: 0
- On error: -1 (invalid fd or tcp_listen failed)
Behavior
- Retrieves the bound port from
fd_entry.offset - Calls
tcp_listen()to create a listening socket:- Registers the port in the TCP layer
- Allocates a listen connection ID
- Stores the listen connection ID in
fd_entry.offset
Aurora OS does not have a backlog parameter. The TCP layer manages incoming connections internally.
Example
SYS_ACCEPT
Accept an incoming connection on a listening socket. Syscall Number: 39Parameters
Listening socket file descriptor
Returns
- On success: new file descriptor for the accepted connection
- On error: -1 (invalid fd or no connections available)
Behavior
This is a blocking syscall. If no connections are pending, the process is blocked until a client connects.
- Retrieves the listen connection ID from
fd_entry.offset - Calls
tcp_accept_begin()to prepare for accepting - Calls
tcp_accept_result()to check for pending connections - If no connection available:
- Blocks the process (
state = PROC_BLOCKED) - Reschedules
- Retries after wakeup
- Blocks the process (
- Allocates a new file descriptor for the accepted connection
- Returns the new fd
Example - Simple Echo Server
SYS_SEND
Send data over a connected socket. Syscall Number: 27Parameters
Socket file descriptor (must be connected)
Buffer containing data to send
Number of bytes to send
Returns
- On success: number of bytes sent
- On error: -1 (invalid fd or connection error)
Behavior
- Retrieves the connection ID from
fd_entry.offset - Calls
tcp_send(conn_id, buf, len):- Segments data into TCP packets
- Transmits via the network stack
- Handles retransmission if needed
- Returns the number of bytes sent
Example
SYS_RECV
Receive data from a connected socket. Syscall Number: 28Parameters
Socket file descriptor (must be connected)
Buffer to store received data
Maximum number of bytes to receive (buffer size)
Returns
- On success: number of bytes received (may be less than len)
- On connection closed: 0
- On error: -1
Behavior
This is typically a blocking call. If no data is available, the implementation may block the process (behavior depends on TCP layer implementation).
- Retrieves the connection ID from
fd_entry.offset - Calls
tcp_recv(conn_id, buf, len):- Reads from the TCP receive buffer
- Copies up to
lenbytes to user buffer
- Returns the number of bytes copied
Example
Network Stack Integration
The syscall layer interfaces with the kernel network stack implemented in/kernel/src/net/:
TCP Functions
UDP Functions
UDP receive is not yet wired into the syscall interface. UDP sockets can send but not receive.