Added additional functions for windows-specific actions
This commit is contained in:
@@ -1,25 +1,34 @@
|
||||
#ifndef EASYSOCK_HPP_
|
||||
#define EASYSOCK_HPP_
|
||||
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#ifdef _WIN_32
|
||||
#include <winsock2.h>
|
||||
#include <Ws2tcpip.h>
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <cerrno>
|
||||
|
||||
#ifndef _WIN_32
|
||||
typedef int SOCKET;
|
||||
#endif
|
||||
|
||||
/* This function takes:
|
||||
a layer 3 - network layer - integer, which must be '4' for IPv4
|
||||
and 6 for IPv6; and
|
||||
a layer 4 - transport layer - character, which must be 'T' for
|
||||
TCP or 'U' for UDP.
|
||||
TCP or 'U' for UDP.
|
||||
|
||||
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.
|
||||
@@ -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'
|
||||
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 ).*/
|
||||
|
||||
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
|
||||
@@ -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 ). */
|
||||
|
||||
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),
|
||||
IPv6 address (returns 6) or neither (returns -1). */
|
||||
@@ -72,5 +81,10 @@ int char_to_socktype(char transport);
|
||||
and returns the appropriate int value. */
|
||||
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
|
||||
|
Reference in New Issue
Block a user