First commit of release 0.1
[sockstream.git] / include / port.h
1 /**************************************************************************
2 **  (c) Copyright 2012, Andromeda Technology & Automation
3 ***************************************************************************
4 ** MODULE INFORMATION *
5 ***********************
6 **      FILE NAME      : port.h
7 **      SYSTEM NAME    : Network and socket classes
8 **      VERSION NUMBER : 0.1
9 **
10 **  DESCRIPTION      :  Port class definition
11 **
12 **  EXPORTED OBJECTS : class Port
13 **  LOCAL    OBJECTS : 
14 **  MODULES  USED    :
15 ***************************************************************************
16 **  ADMINISTRATIVE INFORMATION *
17 ********************************
18 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
19 **      CREATION DATE   : Mar 02, 2012
20 **      LAST UPDATE     : Mar 08, 2012
21 **      MODIFICATIONS   : 
22 **************************************************************************/
23
24 #ifndef _PORT_H_
25 #define _PORT_H_
26
27 #include <sys/socket.h>   //  For types and constants (like SOCK_STREAM)
28
29 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30 **  NAME           : Port - A class that represents a port for services.
31 **  MEMBERS        : port      : The port number.
32 **                   sockettype: The type of socket on which the service is available.
33 **  OPERATORS      : ==, !=
34 **                   unsigned short : Convert to port number in host byte order.
35 **  METHODS        : get_port()      : The port number in network byte order.
36 **                   get_sockettype(): Find the name if the port in known.
37 **
38 **  DESCRIPTION    : 
39 **
40 **
41 **  RELATIONS      : 
42 **  SEE ALSO       : 
43 **  LAST MODIFIED  : Mar 08, 2012
44 **+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
45 */
46
47 class Port
48 {
49    in_port_t     port;
50    int           socktype;
51
52 public:
53
54    Port()
55    {
56       port = 0;
57       socktype = 0;
58    }
59
60    Port(in_port_t p, int st)
61    {
62       port = p;
63       socktype = st;
64    }
65
66    Port(unsigned short p)
67    {
68       port = htons(p);
69       socktype = 0;
70    }
71
72    in_port_t get_port()
73    {
74       return port;
75    }
76
77    int get_sockettype()
78    {
79       return socktype;
80    }
81
82    operator unsigned short ()
83    {
84       return ntohs(port);
85    }
86 };
87
88 #endif // _PORT_H_