File containing the definition of the socket control utilities.
More...
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/un.h>
Go to the source code of this file.
|
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...
|
|
File containing the definition of the socket control utilities.
- Author
- Alexandru Mereacre
- Date
- 2020
- Copyright
- SPDX-FileCopyrightText: © 2020 NQMCyber Ltd and edgesec contributors SPDX-License-Identifier: LGPL-3.0-or-later
◆ SOCKET_TYPE
Enumerator |
---|
SOCKET_TYPE_NONE | |
SOCKET_TYPE_DOMAIN | |
SOCKET_TYPE_UDP | |
◆ 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_fd | The file descriptor of the unix domain socket to close. |
- Return values
-
0 | on success. |
-1 | on error (see errno for error details). |
◆ create_domain_client()
int create_domain_client |
( |
const char * |
path | ) |
|
Create a unix domain client socket.
- Parameters
-
path | The 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
-
◆ create_domain_server()
int create_domain_server |
( |
const char * |
server_path | ) |
|
Create a domain server object.
- Parameters
-
server_path | Server 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
-
port | Server 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
-
| 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 |
- 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
-
| 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 |
- 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
-
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 . |
- 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
-
sock | Server socket |
data | Data buffer to send. |
data_len | Data buffer length |
addr | The 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_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. |
- Returns
- int 0 on success, -1 on failure