NetworkUtilities 1.4.2
A small compiled library for C network utility functions.
|
Functions related to initializing network ports and setting their properties. More...
Functions | |
struct sockaddr_in | initSocketAddress (char *ip_address, uint16_t port) |
Initializes a socket address. | |
int | initializeWinsock () |
Initializes Winsock library. | |
int | initializeUDPClientSocket (SOCKET *udpSocket, struct sockaddr_in *serverAddr, char *serverIP, uint16_t port) |
Initializes a UDP socket and configures server address. | |
int | initializeUDPServerSocket (SOCKET *udpSocket, struct sockaddr_in *serverAddr, uint16_t port) |
Initializes a UDP socket and configures server address. | |
void | setBlocking (SOCKET socket) |
Sets the given socket to blocking mode. | |
void | setNonBlocking (SOCKET socket) |
Sets the given socket to non-blocking mode. | |
void | updateServerIPandPort (struct sockaddr_in *serverAddr, char *serverIP, uint16_t serverPort) |
Re-configure server address and port. | |
Functions related to initializing network ports and setting their properties.
int initializeUDPClientSocket | ( | SOCKET * | udpSocket, |
struct sockaddr_in * | serverAddr, | ||
char * | serverIP, | ||
uint16_t | port ) |
Initializes a UDP socket and configures server address.
This function initializes a UDP socket and configures the server address using the provided parameters. It creates a UDP socket, sets it up with the specified server address and port, and assigns the socket to the provided pointer. If any errors occur during socket creation or address configuration, the appropriate error message is printed to stderr, Winsock resources are cleaned up, and the function returns EXIT_FAILURE.
udpSocket | A pointer to an integer where the UDP socket descriptor will be stored. |
serverAddr | Pointer to the address structure of the server connection (struct sockaddr_in) to configure the socket with. |
serverIP | The IP address of the connection (char*; IPv4). |
port | The port on the server that will be bound by this UDP socket. |
int initializeUDPServerSocket | ( | SOCKET * | udpSocket, |
struct sockaddr_in * | serverAddr, | ||
uint16_t | port ) |
Initializes a UDP socket and configures server address.
This function initializes a UDP socket and configures the server address using the provided parameters. It creates a UDP socket, sets it up with the specified server address and port, and assigns the socket to the provided pointer. If any errors occur during socket creation or address configuration, the appropriate error message is printed to stderr, Winsock resources are cleaned up, and the function returns EXIT_FAILURE.
udpSocket | A pointer to an integer where the UDP socket descriptor will be stored. |
serverAddr | Pointer to the address structure of the server connection (struct sockaddr_in) to configure the socket with. |
port | The port on the server that will be bound by this UDP socket. |
int initializeWinsock | ( | ) |
Initializes Winsock library.
This function initializes the Winsock library. It must be called before any other Winsock functions. If initialization fails, an error message is printed to stderr and the function returns EXIT_FAILURE code.
struct sockaddr_in initSocketAddress | ( | char * | ip_address, |
uint16_t | port ) |
Initializes a socket address.
ip_address | String containing the allowed connection IP address, or NULL to allow any connection. |
port | Port over which socket messages will be exchanged for this address structure. |
void setBlocking | ( | SOCKET | socket | ) |
Sets the given socket to blocking mode.
This function sets the specified socket to blocking mode.
socket | The socket to set to blocking mode. |
void setNonBlocking | ( | SOCKET | socket | ) |
Sets the given socket to non-blocking mode.
This function sets the specified socket to non-blocking mode.
socket | The socket to set to non-blocking mode. |
void updateServerIPandPort | ( | struct sockaddr_in * | serverAddr, |
char * | serverIP, | ||
uint16_t | serverPort ) |
Re-configure server address and port.
This function re-configures the server address and port using the provided input IPv4 IP address and port number.
serverAddr | Pointer to the address structure of the server connection (struct sockaddr_in) to configure the socket with. |
serverIP | The IP address of the connection (char*; IPv4). |
serverPort | The port on the server that will be bound by this UDP socket. |