EDGESEC
0.1.0-alpha.0+sha.ca29a8277b72f80785649ea9ef9cd7edf642d939
Secure router - reference implementation
|
File containing the implementation of the socket control utils. More...
#include <stdio.h>
#include <sys/socket.h>
#include <ctype.h>
#include <errno.h>
#include <libgen.h>
#include <limits.h>
#include <sys/ioctl.h>
#include <sys/un.h>
#include "sockctl.h"
#include "allocs.h"
#include "log.h"
#include "net.h"
#include "os.h"
Macros | |
#define | SOCK_EXTENSION ".sock" |
#define | TMP_UNIX_SOCK_FOLDER_PREFIX "/tmp/edgesec/tmp-unix-socks." |
#define | TMP_UNIX_SOCK_FOLDER_TEMPLATE TMP_UNIX_SOCK_FOLDER_PREFIX "XXXXXX" |
#define | TMP_UNIX_SOCK_NAME "client-socket" SOCK_EXTENSION |
#define | DOMAIN_REPLY_TIMEOUT 10 |
Functions | |
void | init_domain_addr (struct sockaddr_un *unaddr, const char *addr) |
int | create_domain_client (const char *path) |
Create a unix domain client socket. More... | |
int | create_domain_server (const char *server_path) |
Create a domain server object. More... | |
int | close_domain_socket (int unix_domain_socket_fd) |
Closes and cleans up a unix domain socket. More... | |
int | create_udp_server (unsigned int port) |
Create a udp server object. More... | |
ssize_t | read_socket_domain (int sock, char *data, size_t data_len, struct client_address *addr, int flags) |
ssize_t | read_socket_udp (int sock, char *data, size_t data_len, struct client_address *addr, int flags) |
ssize_t | read_socket_data (int sock, char *data, size_t data_len, struct client_address *addr, int flags) |
Read data from the server socket. More... | |
ssize_t | read_domain_data_s (int sock, char *data, size_t data_len, char *addr, int flags) |
Read data from the domain server socket with a string address. More... | |
ssize_t | write_domain_data_s (int sock, const char *data, size_t data_len, const char *addr) |
Write data to the domain server socket with a string address. More... | |
ssize_t | write_socket_domain (int sock, const char *data, size_t data_len, const struct client_address *addr) |
ssize_t | write_socket_udp (int sock, const char *data, size_t data_len, const struct client_address *addr) |
ssize_t | write_socket_data (int sock, const char *data, size_t data_len, const struct client_address *addr) |
Write data to the server socket. More... | |
int | writeread_domain_data_str (char *socket_path, const char *write_str, char **reply) |
Write and read a domain data string. More... | |
File containing the implementation of the socket control utils.
#define DOMAIN_REPLY_TIMEOUT 10 |
#define SOCK_EXTENSION ".sock" |
#define TMP_UNIX_SOCK_FOLDER_PREFIX "/tmp/edgesec/tmp-unix-socks." |
#define TMP_UNIX_SOCK_FOLDER_TEMPLATE TMP_UNIX_SOCK_FOLDER_PREFIX "XXXXXX" |
Template for mkdtemp() to create tmp folders for temporary unix domain sockets
#define TMP_UNIX_SOCK_NAME "client-socket" SOCK_EXTENSION |
Basename for temporary unix domain sockets
int close_domain_socket | ( | int | unix_domain_socket_fd | ) |
Closes and cleans up a unix domain socket.
Closes the given unix domain socket. If the given unix domain socket is a pathname socket, this function also calls unlink() on the pathname.
unix_domain_socket_fd | The file descriptor of the unix domain socket to close. |
0 | on success. |
-1 | on error (see errno for error details). |
int create_domain_client | ( | const char * | path | ) |
Create a unix domain client socket.
path | The UNIX domain socket path. If this is NULL:
|
-1 | On error. |
int create_domain_server | ( | const char * | server_path | ) |
Create a domain server object.
server_path | Server UNIX domain socket path |
int create_udp_server | ( | unsigned int | port | ) |
Create a udp server object.
port | Server port in host endian. |
void init_domain_addr | ( | struct sockaddr_un * | unaddr, |
const char * | addr | ||
) |
ssize_t read_domain_data_s | ( | int | sock, |
char * | data, | ||
size_t | data_len, | ||
char * | addr, | ||
int | flags | ||
) |
Read data from the domain server socket with a string address.
sock | Domain Server socket | |
[out] | data | Data buffer to store read data. |
data_len | Data buffer length | |
[out] | addr | Buffer to store sender address. Must be at least the same size as sun_path (usually 104 bytes on BSD, 108 on Linux). |
flags | The flags for recvfrom function |
ssize_t read_socket_data | ( | int | sock, |
char * | data, | ||
size_t | data_len, | ||
struct client_address * | addr, | ||
int | flags | ||
) |
Read data from the server socket.
sock | Server socket | |
[out] | data | Data buffer to store read data. |
data_len | Data buffer length | |
[out] | addr | The sender address structure |
flags | The flags for recvfrom function |
ssize_t read_socket_domain | ( | int | sock, |
char * | data, | ||
size_t | data_len, | ||
struct client_address * | addr, | ||
int | flags | ||
) |
ssize_t read_socket_udp | ( | int | sock, |
char * | data, | ||
size_t | data_len, | ||
struct client_address * | addr, | ||
int | flags | ||
) |
ssize_t write_domain_data_s | ( | int | sock, |
const char * | data, | ||
size_t | data_len, | ||
const char * | addr | ||
) |
Write data to the domain server socket with a string address.
sock | Domain server socket |
data | Data buffer to send. |
data_len | Data buffer length |
addr | Client address (string). This string will be truncated if it does not fit in sun_path . |
ssize_t write_socket_data | ( | int | sock, |
const char * | data, | ||
size_t | data_len, | ||
const struct client_address * | addr | ||
) |
Write data to the server socket.
sock | Server socket |
data | Data buffer to send. |
data_len | Data buffer length |
addr | The recipient address structure |
ssize_t write_socket_domain | ( | int | sock, |
const char * | data, | ||
size_t | data_len, | ||
const struct client_address * | addr | ||
) |
ssize_t write_socket_udp | ( | int | sock, |
const char * | data, | ||
size_t | data_len, | ||
const struct client_address * | addr | ||
) |
int writeread_domain_data_str | ( | char * | socket_path, |
const char * | write_str, | ||
char ** | reply | ||
) |
Write and read a domain data string.
[in,out] | socket_path | The path to the domain server socket. This path will be overwritten with the socket path of the reply, so it must be at least the same size as sun_path (usually 104 bytes on BSD, 108 on Linux). |
[in] | write_str | The data to write to the socket. |
[out] | reply | The pointer to the reply string. You must free() this reply string when done with it. |