|
AquilaOS documentation
How it works, and its code
|
System calls on sockets: making them, binding, listening, accepting and connecting, sending and receiving, their names and options. More...
#include "syscalls.h"Go to the source code of this file.
Data Structures | |
| union | ksockaddr |
Functions | |
| long | sys_socket (int domain, int type, int protocol) |
| Implements socket(): makes a socket, open on a new descriptor. | |
| static int | sockaddr_copyin (union ksockaddr *k, const struct sockaddr *uaddr, socklen_t len) |
| Copies an address of len bytes from user memory. | |
| static int | sockaddr_room (socklen_t *ulen, socklen_t *klen) |
| Reads how much room the user's buffer has for an address going out, into *klen, at most the kernel copy's size. | |
| static int | sockaddr_copyout (struct sockaddr *uaddr, socklen_t *ulen, const union ksockaddr *k, socklen_t klen, socklen_t room) |
| Copies an address out to user memory, as much of it as fits in room, and sets *ulen to its full size klen. | |
| long | sys_accept (int fd, const struct sockaddr *addr, socklen_t *len) |
| Implements accept(): takes a connection from a listening socket, open on a new descriptor. | |
| long | sys_bind (int fd, const struct sockaddr *addr, socklen_t len) |
| Implements bind(): gives a socket its local address. | |
| long | sys_connect (int fd, const struct sockaddr *addr, socklen_t len) |
| Implements connect(): connects a socket to a peer. | |
| long | sys_listen (int fd, int backlog) |
| Implements listen(): makes a socket accept connections. | |
| long | sys_send (struct aquila_socket_io_args *us) |
| Implements send() and sendto(). | |
| long | sys_recv (struct aquila_socket_io_args *us) |
| Implements recv() and recvfrom(). | |
| static long | socket_name (int fd, struct sockaddr *addr, socklen_t *len, int peer) |
| Gets a socket's local address or its peer's, for getsockname() and getpeername(), and copies it out. | |
| long | sys_getsockname (int fd, struct sockaddr *addr, socklen_t *len) |
| Implements getsockname(): a socket's local address. | |
| long | sys_getpeername (int fd, struct sockaddr *addr, socklen_t *len) |
| Implements getpeername(): the address of a socket's peer. | |
| long | sys_getsockopt (int fd, int level, int name, void *val, socklen_t *len) |
| Implements getsockopt(): reads a socket option. | |
| long | sys_setsockopt (int fd, int level, int name, const void *val, socklen_t len) |
| Implements setsockopt(): sets a socket option. | |
| long | sys_shutdown (int fd, int how) |
| Implements shutdown(): shuts down reading, writing or both on a socket, which stays open. | |
System calls on sockets: making them, binding, listening, accepting and connecting, sending and receiving, their names and options.
The work is done by net/socket.c and the domains' code; these calls copy the arguments in and the results out.
Definition in file sys_net.c.
|
static |
Copies an address of len bytes from user memory.
Returns 0, -EINVAL if it's too big, or -EFAULT.
Definition at line 58 of file sys_net.c.
References sockaddr_copyin().
Referenced by sockaddr_copyin(), sys_bind(), sys_connect(), and sys_send().
|
static |
Copies an address out to user memory, as much of it as fits in room, and sets *ulen to its full size klen.
Returns 0 or -EFAULT.
Definition at line 79 of file sys_net.c.
References MIN, and sockaddr_copyout().
Referenced by sockaddr_copyout(), socket_name(), sys_accept(), and sys_recv().
|
static |
Reads how much room the user's buffer has for an address going out, into *klen, at most the kernel copy's size.
Returns 0 or -EFAULT.
Definition at line 68 of file sys_net.c.
References MIN, and sockaddr_room().
Referenced by sockaddr_room(), socket_name(), sys_accept(), and sys_recv().
|
static |
Gets a socket's local address or its peer's, for getsockname() and getpeername(), and copies it out.
Definition at line 365 of file sys_net.c.
References fd_file(), memset(), ksockaddr::sa, sockaddr_copyout(), sockaddr_room(), socket_getname(), and socket_name().
Referenced by socket_name(), sys_getpeername(), and sys_getsockname().
| long sys_accept | ( | int | fd, |
| const struct sockaddr * | addr, | ||
| socklen_t * | len ) |
Implements accept(): takes a connection from a listening socket, open on a new descriptor.
| fd | the listening socket |
| addr | where to put the peer's address, or NULL |
| len | the room at addr, set to the address's size |
Definition at line 97 of file sys_net.c.
References curproc, fd_file(), file_new(), kfree(), LOG_DEBUG, memset(), NULL, proc_fd_close(), proc_fd_get(), proc_fd_install(), proc_fd_release(), ksockaddr::sa, sockaddr_copyout(), sockaddr_room(), socket_accept(), and sys_accept().
Referenced by sys_accept().
| long sys_bind | ( | int | fd, |
| const struct sockaddr * | addr, | ||
| socklen_t | len ) |
Implements bind(): gives a socket its local address.
| fd | the socket |
| addr | the address |
| len | its size |
Definition at line 161 of file sys_net.c.
References fd_file(), LOG_DEBUG, memset(), ksockaddr::sa, sockaddr_copyin(), socket_bind(), and sys_bind().
Referenced by sys_bind().
| long sys_connect | ( | int | fd, |
| const struct sockaddr * | addr, | ||
| socklen_t | len ) |
Implements connect(): connects a socket to a peer.
| fd | the socket |
| addr | the peer's address |
| len | its size |
Definition at line 192 of file sys_net.c.
References fd_file(), LOG_DEBUG, memset(), ksockaddr::sa, sockaddr_copyin(), socket_connect(), and sys_connect().
Referenced by sys_connect().
| long sys_getpeername | ( | int | fd, |
| struct sockaddr * | addr, | ||
| socklen_t * | len ) |
Implements getpeername(): the address of a socket's peer.
| fd | the socket |
| addr | where to put the address |
| len | the room at addr, set to the address's size |
Definition at line 412 of file sys_net.c.
References LOG_DEBUG, socket_name(), and sys_getpeername().
Referenced by sys_getpeername().
| long sys_getsockname | ( | int | fd, |
| struct sockaddr * | addr, | ||
| socklen_t * | len ) |
Implements getsockname(): a socket's local address.
| fd | the socket |
| addr | where to put the address |
| len | the room at addr, set to the address's size |
Definition at line 398 of file sys_net.c.
References LOG_DEBUG, socket_name(), and sys_getsockname().
Referenced by sys_getsockname().
| long sys_getsockopt | ( | int | fd, |
| int | level, | ||
| int | name, | ||
| void * | val, | ||
| socklen_t * | len ) |
Implements getsockopt(): reads a socket option.
| fd | the socket |
| level | SOL_SOCKET, or a protocol's level |
| name | the option |
| val | where to put its value |
| len | the room at val, set to the value's size |
Definition at line 429 of file sys_net.c.
References fd_file(), LOG_DEBUG, memset(), MIN, socket_getsockopt(), and sys_getsockopt().
Referenced by sys_getsockopt().
| long sys_listen | ( | int | fd, |
| int | backlog ) |
Implements listen(): makes a socket accept connections.
| fd | the socket |
| backlog | how many connections may wait to be accepted |
Definition at line 221 of file sys_net.c.
References fd_file(), LOG_DEBUG, socket_listen(), and sys_listen().
Referenced by sys_listen().
| long sys_recv | ( | struct aquila_socket_io_args * | us | ) |
Implements recv() and recvfrom().
| us | the arguments, in user memory: the socket, the buffer, the flags, and where recvfrom() puts the sender's address |
Definition at line 313 of file sys_net.c.
References fd_file(), fd::flags, iobuf_init(), LOG_DEBUG, memset(), NULL, ksockaddr::sa, sockaddr_copyout(), sockaddr_room(), socket_recv(), sys_recv(), and uaccess_check().
Referenced by sys_recv().
| long sys_send | ( | struct aquila_socket_io_args * | us | ) |
Implements send() and sendto().
A send on a connection that can't send anymore also raises SIGPIPE, unless MSG_NOSIGNAL is set.
| us | the arguments, in user memory: the socket, the data, the flags, and sendto()'s destination |
Definition at line 249 of file sys_net.c.
References curproc, fd_file(), fd::flags, iobuf_init(), LOG_DEBUG, memset(), NULL, ksockaddr::sa, signal_proc_send(), sockaddr_copyin(), socket_send(), sys_send(), and uaccess_check().
Referenced by sys_send().
| long sys_setsockopt | ( | int | fd, |
| int | level, | ||
| int | name, | ||
| const void * | val, | ||
| socklen_t | len ) |
Implements setsockopt(): sets a socket option.
| fd | the socket |
| level | SOL_SOCKET, or a protocol's level |
| name | the option |
| val | its value |
| len | the value's size |
Definition at line 470 of file sys_net.c.
References fd_file(), LOG_DEBUG, MIN, socket_setsockopt(), and sys_setsockopt().
Referenced by sys_setsockopt().
| long sys_shutdown | ( | int | fd, |
| int | how ) |
Implements shutdown(): shuts down reading, writing or both on a socket, which stays open.
| fd | the socket |
| how | SHUT_RD, SHUT_WR or SHUT_RDWR |
Definition at line 501 of file sys_net.c.
References fd_file(), LOG_DEBUG, socket_shutdown_dir(), and sys_shutdown().
Referenced by sys_shutdown().
| long sys_socket | ( | int | domain, |
| int | type, | ||
| int | protocol ) |
Implements socket(): makes a socket, open on a new descriptor.
| domain | AF_UNIX or AF_INET |
| type | SOCK_STREAM or SOCK_DGRAM |
| protocol | the protocol, or 0 for the type's default |
Definition at line 19 of file sys_net.c.
References curproc, file_new(), kfree(), LOG_DEBUG, proc_fd_get(), proc_fd_install(), proc_fd_release(), socket_create(), and sys_socket().
Referenced by sys_socket().