Added additional code to easysock library

This commit is contained in:
2024-02-19 21:55:22 -05:00
parent ec51bcdb34
commit 350b51e28b
2 changed files with 41 additions and 21 deletions

View File

@@ -12,24 +12,26 @@
#include <arpa/inet.h>
#endif
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cerrno>
#ifndef _WIN_32
typedef int SOCKET;
#endif
/* Constants that can be used in place of characters, when specifying
the transport layer protocol */
const char ES_TCP 'T';
const char ES_UDP 'U';
/* This function takes:
a layer 3 - network layer - integer, which must be '4' for IPv4
and 6 for IPv6; and
and 6 for IPv6;
a layer 4 - transport layer - character, which must be 'T' for
TCP or 'U' for UDP.
TCP or 'U' for UDP; and
a bool that indicates whether the socket should be blocking or non-blocking.
It returns the created socket, or -1 if the socket creation failed.*/
SOCKET create_socket(int network, char transport);
SOCKET create_socket(int network, char transport, bool is_blocking = false);
/* This function fills in the sockaddr struct 'dest' based on the given information.
@@ -51,7 +53,7 @@ same as above.
It prints the error returned by 'bind' if something went wrong, and returns ( -1 * errno ).*/
SOCKET create_local (int network, char transport, char* address, int port,struct sockaddr* addr_struct);
SOCKET create_local (int network, char transport, char* address, int port,struct sockaddr* addr_struct, bool is_blocking = false);
/* This function utilizes the same functions as 'create_local' but _connects_ to the
@@ -60,7 +62,7 @@ as above. This function needs an empty 'sockaddr *' structure passed to it, whic
If something goes wrong, this function returns with ( -1 * errno ). */
SOCKET create_remote (int network,char transport,char* address,int port,struct sockaddr* remote_addr_struct);
SOCKET create_remote (int network,char transport,char* address,int port,struct sockaddr* remote_addr_struct, bool is_blocking = false);
/* check_ip_ver - This function checks if the given string is an IPv4 address (returns 4),
IPv6 address (returns 6) or neither (returns -1). */