-
Notifications
You must be signed in to change notification settings - Fork 9
/
SocketTypes.h
71 lines (52 loc) · 2.78 KB
/
SocketTypes.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// This File contains all of the basic types
#ifndef SOCKETTYPES_H
#define SOCKETTYPES_H
// ========================================================================
// Include Files
// ========================================================================
#ifdef _WIN32 // windows 95 and above
#include "winsock2.h" // almost everything is contained in one file.
#include "Ws2tcpip.h"
#ifndef socklen_t
typedef int socklen_t;
#endif
#else // UNIX/Linux
#include <sys/types.h> // header containing all basic data types and
// typedefs
#include <sys/socket.h> // header containing socket data types and
// functions
#include <netinet/in.h> // IPv4 and IPv6 stuff
#include <unistd.h> // for gethostname()
#include <netdb.h> // for DNS - gethostbyname()
#include <arpa/inet.h> // contains all inet_* functions
#include <errno.h> // contains the error functions
#include <fcntl.h> // file control
#endif
namespace SocketLib
{
// ========================================================================
// Globals and Typedefs
// ========================================================================
#ifdef _WIN32 // windows 95 and above
typedef SOCKET sock; // Although sockets are int's on unix,
// windows uses it's own typedef of
// SOCKET to represent them. If you look
// in the Winsock2 source code, you'll see
// that it is just a typedef for int, but
// there is absolutely no garuntee that it
// won't change in a later version.
// therefore, in order to avoid confusion,
// this library will create it's own basic
// socket descriptor typedef
#else // UNIX/Linux
typedef int sock; // see the description above.
#endif
// ========================================================================
// Ports will be in host byte order, but IP addresses in network byte
// order. It's easier this way; ports are usually accessed as numbers,
// but IP addresses are better accessed through the string functions.
// ========================================================================
typedef unsigned short int port; // define the port type.
typedef unsigned long int ipaddress; // an IP address for IPv4
} // end namespace SocketLib
#endif