|
|
@ -1,15 +1,24 @@
|
|
|
|
#ifndef EASYSOCK_HPP_
|
|
|
|
#ifndef EASYSOCK_HPP_
|
|
|
|
#define EASYSOCK_HPP_
|
|
|
|
#define EASYSOCK_HPP_
|
|
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#ifdef _WIN_32
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <winsock2.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <Ws2tcpip.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#else
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
|
|
|
#include <cerrno>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef _WIN_32
|
|
|
|
|
|
|
|
typedef int SOCKET;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* This function takes:
|
|
|
|
/* This function takes:
|
|
|
|
a layer 3 - network layer - integer, which must be '4' for IPv4
|
|
|
|
a layer 3 - network layer - integer, which must be '4' for IPv4
|
|
|
@ -19,7 +28,7 @@ TCP or 'U' for UDP.
|
|
|
|
|
|
|
|
|
|
|
|
It returns the created socket, or -1 if the socket creation failed.*/
|
|
|
|
It returns the created socket, or -1 if the socket creation failed.*/
|
|
|
|
|
|
|
|
|
|
|
|
int create_socket(int network, char transport);
|
|
|
|
SOCKET create_socket(int network, char transport);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* This function fills in the sockaddr struct 'dest' based on the given information.
|
|
|
|
/* This function fills in the sockaddr struct 'dest' based on the given information.
|
|
|
@ -31,7 +40,7 @@ and dest is a pointer to the sockaddr struct that will be filled in.
|
|
|
|
The function returns with -202 if the network parameter contained neither '4'
|
|
|
|
The function returns with -202 if the network parameter contained neither '4'
|
|
|
|
nor '6'. */
|
|
|
|
nor '6'. */
|
|
|
|
|
|
|
|
|
|
|
|
int create_addr(int network, char* address, int port,struct sockaddr* dest);
|
|
|
|
SOCKET create_addr(int network, char* address, int port,struct sockaddr* dest);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -41,7 +50,7 @@ same as above.
|
|
|
|
|
|
|
|
|
|
|
|
It prints the error returned by 'bind' if something went wrong, and returns ( -1 * errno ).*/
|
|
|
|
It prints the error returned by 'bind' if something went wrong, and returns ( -1 * errno ).*/
|
|
|
|
|
|
|
|
|
|
|
|
int 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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* This function utilizes the same functions as 'create_local' but _connects_ to the
|
|
|
|
/* This function utilizes the same functions as 'create_local' but _connects_ to the
|
|
|
@ -50,7 +59,7 @@ as above. This function needs an empty 'sockaddr *' structure passed to it, whic
|
|
|
|
|
|
|
|
|
|
|
|
If something goes wrong, this function returns with ( -1 * errno ). */
|
|
|
|
If something goes wrong, this function returns with ( -1 * errno ). */
|
|
|
|
|
|
|
|
|
|
|
|
int 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);
|
|
|
|
|
|
|
|
|
|
|
|
/* check_ip_ver - This function checks if the given string is an IPv4 address (returns 4),
|
|
|
|
/* check_ip_ver - This function checks if the given string is an IPv4 address (returns 4),
|
|
|
|
IPv6 address (returns 6) or neither (returns -1). */
|
|
|
|
IPv6 address (returns 6) or neither (returns -1). */
|
|
|
@ -72,5 +81,10 @@ int char_to_socktype(char transport);
|
|
|
|
and returns the appropriate int value. */
|
|
|
|
and returns the appropriate int value. */
|
|
|
|
int inet_to_int(int af_type);
|
|
|
|
int inet_to_int(int af_type);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* sockQuit - Only for windows - Cleans up the socket */
|
|
|
|
|
|
|
|
int sock_quit(void);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* sock_close - Closes the given socket */
|
|
|
|
|
|
|
|
int sock_close(SOCKET);
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|