EDGESEC  0.1.0-alpha.0+sha.ca29a8277b72f80785649ea9ef9cd7edf642d939
Secure router - reference implementation
Data Structures | Enumerations | Functions
sockctl.h File Reference

File containing the definition of the socket control utilities. More...

#include <netinet/in.h>
#include <sys/types.h>
#include <sys/un.h>
Include dependency graph for sockctl.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  client_address
 Client address structure definition. More...
 

Enumerations

enum  SOCKET_TYPE { SOCKET_TYPE_NONE = 0 , SOCKET_TYPE_DOMAIN , SOCKET_TYPE_UDP }
 

Functions

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_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_socket_data (int sock, const char *data, size_t data_len, const struct client_address *addr)
 Write data to the server socket. 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...
 
int writeread_domain_data_str (char *socket_path, const char *write_str, char **reply)
 Write and read a domain data string. More...
 

Detailed Description

File containing the definition of the socket control utilities.

Author
Alexandru Mereacre
Date
2020

Enumeration Type Documentation

◆ SOCKET_TYPE

Enumerator
SOCKET_TYPE_NONE 
SOCKET_TYPE_DOMAIN 
SOCKET_TYPE_UDP 

Function Documentation

◆ close_domain_socket()

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.

Parameters
unix_domain_socket_fdThe file descriptor of the unix domain socket to close.
Return values
0on success.
-1on error (see errno for error details).

◆ create_domain_client()

int create_domain_client ( const char *  path)

Create a unix domain client socket.

Parameters
pathThe UNIX domain socket path. If this is NULL:
  • On Linux, a randomly generated abstract Unix domain socket will be used instead.
  • On other Unix platforms, a randomly generated pathname Unix domain socket will be used. Please call close_domain_socket() to unlink() the pathname (and tmp folder) when finished.
Returns
File-descriptor for the client socket.
Return values
-1On error.

◆ create_domain_server()

int create_domain_server ( const char *  server_path)

Create a domain server object.

Parameters
server_pathServer UNIX domain socket path
Returns
int Domain server socket

◆ create_udp_server()

int create_udp_server ( unsigned int  port)

Create a udp server object.

Parameters
portServer port in host endian.
Returns
int UDP server socket

◆ read_domain_data_s()

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.

Parameters
sockDomain Server socket
[out]dataData buffer to store read data.
data_lenData buffer length
[out]addrBuffer to store sender address. Must be at least the same size as sun_path (usually 104 bytes on BSD, 108 on Linux).
flagsThe flags for recvfrom function
Returns
ssize_t Size of read data

◆ read_socket_data()

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.

Parameters
sockServer socket
[out]dataData buffer to store read data.
data_lenData buffer length
[out]addrThe sender address structure
flagsThe flags for recvfrom function
Returns
ssize_t Size of read data

◆ write_domain_data_s()

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.

Parameters
sockDomain server socket
dataData buffer to send.
data_lenData buffer length
addrClient address (string). This string will be truncated if it does not fit in sun_path.
Returns
ssize_t Size of written data

◆ write_socket_data()

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.

Parameters
sockServer socket
dataData buffer to send.
data_lenData buffer length
addrThe recipient address structure
Returns
ssize_t Size of written data

◆ writeread_domain_data_str()

int writeread_domain_data_str ( char *  socket_path,
const char *  write_str,
char **  reply 
)

Write and read a domain data string.

Parameters
[in,out]socket_pathThe 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_strThe data to write to the socket.
[out]replyThe pointer to the reply string. You must free() this reply string when done with it.
Returns
int 0 on success, -1 on failure