Paraslash Audio Streaming | |
About News Download Documentation Development |
exported symbols from net.c More...
Macros | |
#define | SOL_DCCP 269 |
Linux socket level. More... | |
#define | MAX_HOSTLEN 256 |
The maximum length of the host component in an URL. More... | |
#define | BACKLOG 10 |
Functions to support listening sockets. More... | |
#define | DCCP_MAX_HOST_CCIDS 20 |
Functions and definitions to support IPPROTO_DCCP . More... | |
Functions | |
struct flowopts * | flowopt_new (void) |
Allocate and initialize a flowopt queue. More... | |
void | flowopt_add (struct flowopts *fo, int level, int opt, const char *name, const void *val, int len) |
Append new socket option to flowopt queue. More... | |
void | flowopt_cleanup (struct flowopts *fo) |
Deallocate all resources of a flowopts structure. More... | |
char * | parse_cidr (const char *cidr, char *addr, ssize_t addrlen, int32_t *netmask) |
Functions to parse and validate (parts of) URLs. More... | |
char * | parse_url (const char *url, char *host, ssize_t hostlen, int32_t *port) |
Parse and validate URL string. More... | |
__malloc char * | format_url (const char *url, int default_port) |
Pretty-print a host/port pair. More... | |
const char * | stringify_port (int port, const char *transport) |
Stringify port number, resolve into service name where defined. More... | |
int | lookup_address (unsigned l4type, bool passive, const char *host, int port_number, struct addrinfo **result) |
Resolve an IPv4/IPv6 address. More... | |
int | makesock (unsigned l4type, bool passive, const char *host, uint16_t port_number, struct flowopts *fo) |
Generic socket creation (passive and active sockets). More... | |
int | makesock_addrinfo (unsigned l4type, bool passive, struct addrinfo *ai, struct flowopts *fo) |
Create an active or passive socket. More... | |
void | extract_v4_addr (const struct sockaddr_storage *ss, struct in_addr *ia) |
Extract IPv4 or IPv6-mapped-IPv4 address from sockaddr_storage. More... | |
bool | sockaddr_equal (const struct sockaddr *sa1, const struct sockaddr *sa2) |
Compare the address part of IPv4/6 addresses. More... | |
int | para_listen (unsigned l4type, const char *addr, uint16_t port) |
Create a passive / listening socket. More... | |
int | para_listen_simple (unsigned l4type, uint16_t port) |
Create a socket which listens on all network addresses. More... | |
char * | remote_name (int sockfd) |
Pretty-printing of IPv4/6 socket addresses. More... | |
int | generic_max_transport_msg_size (int sockfd) |
Determining maximum payload (packet) size. More... | |
int | recv_bin_buffer (int fd, char *buf, size_t size) |
Receive data from a file descriptor. More... | |
int | recv_buffer (int fd, char *buf, size_t size) |
Receive and write terminating NULL byte. More... | |
int | para_accept (int fd, void *addr, socklen_t size, int *new_fd) |
Wrapper around the accept system call. More... | |
int | create_local_socket (const char *name) |
Create a socket for local communication and listen on it. More... | |
int | connect_local_socket (const char *name) |
Prepare, create, and connect to a Unix domain socket for local communication. More... | |
int | recv_cred_buffer (int, char *, size_t) |
Receive a buffer and the Unix credentials of the sending process. More... | |
ssize_t | send_cred_buffer (int, char *) |
Send a buffer and the credentials of the current process to a socket. More... | |
int | dccp_available_ccids (uint8_t **ccid_array) |
Probe the list of DCCP CCIDs configured on this host. More... | |
exported symbols from net.c
#define SOL_DCCP 269 |
Linux socket level.
#define MAX_HOSTLEN 256 |
The maximum length of the host component in an URL.
#define BACKLOG 10 |
Functions to support listening sockets.
How many pending connections queue of a listening server will hold.
#define DCCP_MAX_HOST_CCIDS 20 |
Functions and definitions to support IPPROTO_DCCP
.
Hardcoded maximum number of separate CCID modules compiled into a host.
struct flowopts* flowopt_new | ( | void | ) |
Allocate and initialize a flowopt queue.
References alloc().
void flowopt_add | ( | struct flowopts * | fo, |
int | lev, | ||
int | opt, | ||
const char * | name, | ||
const void * | val, | ||
int | len | ||
) |
Append new socket option to flowopt queue.
fo | The flowopt queue to append to. |
lev | Level at which opt resides. |
opt | New option to add. |
name | Stringified name of opt. |
val | The value to set opt to. |
len | Length of val. |
References alloc(), and para_strdup().
void flowopt_cleanup | ( | struct flowopts * | fo | ) |
Deallocate all resources of a flowopts structure.
fo | A pointer as returned from flowopt_new(). |
It's OK to pass NULL
here in which case the function does nothing.
References list_for_each_entry_safe.
char* parse_cidr | ( | const char * | cidr, |
char * | addr, | ||
ssize_t | addrlen, | ||
int32_t * | netmask | ||
) |
Functions to parse and validate (parts of) URLs.
Functions to parse and validate (parts of) URLs.
cidr | Address in CIDR notation |
addr | Copy of the IPv4 address part of cidr |
addrlen | Size of addr in bytes |
netmask | Value of the netmask part in cidr or the default of 32 if not specified. |
References para_atoi32().
char* parse_url | ( | const char * | url, |
char * | host, | ||
ssize_t | hostlen, | ||
int32_t * | port | ||
) |
Parse and validate URL string.
The URL syntax is loosely based on RFC 3986, supporting one of
Native IPv6 addresses must be enclosed in square brackets, since otherwise there is an ambiguity with the port separator ‘:’. The 'port' part is always considered to be a number; if absent, it is set to -1, to indicate that a default port is to be used.
The following are valid examples:
url | The URL string to take apart. |
host | To return the copied host part of url. |
hostlen | The maximum length of host. |
port | To return the port number (if any) of url. |
NULL
if failed. If NULL
is returned, host and port are undefined. If no port number was present in url, port is set to -1.References para_atoi32().
Referenced by format_url(), and para_listen().
__malloc char* format_url | ( | const char * | url, |
int | default_port | ||
) |
Pretty-print a host/port pair.
url | NULL, or any string accepted by parse_url(). |
default_port | Applies if url has no port. |
If the url argument is NULL, the function returns the string 0.0.0.0:default_port. Otherwise it calls parse_url() to check the syntax of the input string given by url. On errors the string "?" is returned. Otherwise, if url contains a port, a copy of url is returned. If no port was supplied, a colon and the default port are appended to url.
References make_message(), MAX_HOSTLEN, para_strdup(), and parse_url().
Referenced by generic_com_on(), and generic_sender_status().
const char* stringify_port | ( | int | port, |
const char * | transport | ||
) |
Stringify port number, resolve into service name where defined.
port | 2-byte port number, in host-byte-order. |
transport | Transport protocol name (e.g. "udp", "tcp"), or NULL. |
Referenced by generic_sender_status().
int lookup_address | ( | unsigned | l4type, |
bool | passive, | ||
const char * | host, | ||
int | port_number, | ||
struct addrinfo ** | result | ||
) |
Resolve an IPv4/IPv6 address.
l4type | The layer-4 type (IPPROTO_xxx ). |
passive | Whether AI_PASSIVE should be included as hint. |
host | Remote or local hostname or IPv/6 address string. |
port_number | Used to set the port in each returned address structure. |
result | addrinfo structures are returned here. |
The interpretation of host depends on the value of passive. On a passive socket host is interpreted as an interface IPv4/6 address (can be left NULL). On an active socket, host is the peer DNS name or IPv4/6 address to connect to.
Referenced by makesock().
int makesock | ( | unsigned | l4type, |
bool | passive, | ||
const char * | host, | ||
uint16_t | port_number, | ||
struct flowopts * | fo | ||
) |
Generic socket creation (passive and active sockets).
Generic socket creation (passive and active sockets).
l4type | The layer-4 type (IPPROTO_xxx ). |
passive | Whether this is a passive or active socket. |
host | Passed to lookup_address(). |
port_number | Passed to lookup_address(). |
fo | Passed to makesock_addrinfo(). |
This creates a ready-made IPv4/v6 socket structure after looking up the necessary parameters. The function first calls lookup_address() and passes the address information to makesock_addrinfo() to create and initialize the socket.
References lookup_address(), makesock_addrinfo(), and PARA_NOTICE_LOG.
Referenced by dccp_available_ccids(), and para_listen().
int makesock_addrinfo | ( | unsigned | l4type, |
bool | passive, | ||
struct addrinfo * | ai, | ||
struct flowopts * | fo | ||
) |
Create an active or passive socket.
l4type | IPPROTO_TCP , IPPROTO_UDP , or IPPROTO_DCCP . |
passive | Whether to call bind(2) or connect(2). |
ai | Address information as obtained from lookup_address(). |
fo | Socket options to be set before making the connection. |
bind(2) is called on passive sockets, and connect(2) on active sockets. The algorithm tries all possible address combinations until it succeeds. If fo is supplied, options are set but cleanup must be performed in the caller.
E_MAKESOCK
on errors.Referenced by makesock().
void extract_v4_addr | ( | const struct sockaddr_storage * | ss, |
struct in_addr * | ia | ||
) |
Extract IPv4 or IPv6-mapped-IPv4 address from sockaddr_storage.
ss | Container of IPv4/6 address. |
ia | Extracted IPv4 address (different from 0) or 0 if unsuccessful. |
bool sockaddr_equal | ( | const struct sockaddr * | sa1, |
const struct sockaddr * | sa2 | ||
) |
Compare the address part of IPv4/6 addresses.
sa1 | First address. |
sa2 | Second address. |
int para_listen | ( | unsigned | l4type, |
const char * | addr, | ||
uint16_t | port | ||
) |
Create a passive / listening socket.
l4type | The transport-layer type (IPPROTO_xxx ). |
addr | Passed to parse_url() if not NULL. |
port | Ignored if addr contains a port number. |
References BACKLOG, ERRNO_TO_PARA_ERROR, makesock(), MAX_HOSTLEN, PARA_INFO_LOG, and parse_url().
Referenced by generic_com_on(), and para_listen_simple().
int para_listen_simple | ( | unsigned | l4type, |
uint16_t | port | ||
) |
Create a socket which listens on all network addresses.
l4type | See para_listen(). |
port | See para_listen(). |
This is a simple wrapper for para_listen() which passes a NULL pointer as the address information.
References para_listen().
char* remote_name | ( | int | fd | ) |
Pretty-printing of IPv4/6 socket addresses.
Pretty-printing of IPv4/6 socket addresses.
fd | The socket descriptor of the connected socket. |
References PARA_ERROR_LOG.
Referenced by accept_sender_client().
int generic_max_transport_msg_size | ( | int | sockfd | ) |
Determining maximum payload (packet) size.
Determining maximum payload (packet) size.
sockfd | The socket file descriptor. |
The socket must be connected. See RFC 1122, 3.3.3. If the protocol family could not be determined, AF_INET
is assumed.
References PARA_ERROR_LOG.
int recv_bin_buffer | ( | int | fd, |
char * | buf, | ||
size_t | size | ||
) |
Receive data from a file descriptor.
fd | The file descriptor. |
buf | The buffer to write the data to. |
size | The size of buf. |
Receive at most size bytes from file descriptor fd.
References ERRNO_TO_PARA_ERROR.
Referenced by recv_buffer(), recv_sb(), and send_callback_request().
int recv_buffer | ( | int | fd, |
char * | buf, | ||
size_t | size | ||
) |
Receive and write terminating NULL byte.
fd | The file descriptor. |
buf | The buffer to write the data to. |
size | The size of buf. |
Read at most size - 1 bytes from file descriptor fd and write a NULL byte at the end of the received data.
References recv_bin_buffer().
int para_accept | ( | int | fd, |
void * | addr, | ||
socklen_t | size, | ||
int * | new_fd | ||
) |
Wrapper around the accept system call.
fd | The listening socket. |
addr | Structure which is filled in with the address of the peer socket. |
size | Should contain the size of the structure pointed to by addr. |
new_fd | Result pointer. |
Accept incoming connections on addr, retry if interrupted.
References ERRNO_TO_PARA_ERROR.
Referenced by accept_sender_client().
int create_local_socket | ( | const char * | name | ) |
Create a socket for local communication and listen on it.
name | The socket pathname. |
This function creates a passive local socket for sequenced, reliable, two-way, connection-based byte streams. The socket file descriptor is set to nonblocking mode and listen(2) is called to prepare the socket for accepting incoming connection requests.
int connect_local_socket | ( | const char * | name | ) |
Prepare, create, and connect to a Unix domain socket for local communication.
name | The socket pathname. |
This function creates a local socket for sequenced, reliable, two-way, connection-based byte streams.
References ERRNO_TO_PARA_ERROR, and PARA_DEBUG_LOG.
Referenced by send_callback_request().
int recv_cred_buffer | ( | int | fd, |
char * | buf, | ||
size_t | size | ||
) |
Receive a buffer and the Unix credentials of the sending process.
fd | The file descriptor of the receiving socket. |
buf | The buffer to store the received message. |
size | The length of buf in bytes. |
ssize_t send_cred_buffer | ( | int | sock, |
char * | buf | ||
) |
Send a buffer and the credentials of the current process to a socket.
sock | The file descriptor of the sending socket. |
buf | The zero-terminated buffer to send. |
-E_SENDMSG
is returned.int dccp_available_ccids | ( | uint8_t ** | ccid_array | ) |
Probe the list of DCCP CCIDs configured on this host.
ccid_array | Pointer to return statically allocated array in. |
NB: This feature is only available on Linux > 2.6.30; on older kernels ENOPROTOOPT ("Protocol not available") will be returned.
< Linux socket level.
< List of supported CCIDs.
References DCCP_MAX_HOST_CCIDS, DCCP_SOCKOPT_AVAILABLE_CCIDS, ERRNO_TO_PARA_ERROR, makesock(), PARA_ERROR_LOG, and SOL_DCCP.