1 | /// ----------------------------------------*- mode: C++; -*--
|
---|
2 | /// @file protlib_types.h
|
---|
3 | /// This file contains various typedefs
|
---|
4 | /// ----------------------------------------------------------
|
---|
5 | /// $Id: protlib_types.h 3064 2008-07-02 08:05:18Z bless $
|
---|
6 | /// $HeadURL: https://svn.ipv6.tm.uka.de/nsis/protlib/trunk/include/protlib_types.h $
|
---|
7 | // ===========================================================
|
---|
8 | //
|
---|
9 | // Copyright (C) 2005-2007, all rights reserved by
|
---|
10 | // - Institute of Telematics, Universitaet Karlsruhe (TH)
|
---|
11 | //
|
---|
12 | // More information and contact:
|
---|
13 | // https://projekte.tm.uka.de/trac/NSIS
|
---|
14 | //
|
---|
15 | // This program is free software; you can redistribute it and/or modify
|
---|
16 | // it under the terms of the GNU General Public License as published by
|
---|
17 | // the Free Software Foundation; version 2 of the License
|
---|
18 | //
|
---|
19 | // This program is distributed in the hope that it will be useful,
|
---|
20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
22 | // GNU General Public License for more details.
|
---|
23 | //
|
---|
24 | // You should have received a copy of the GNU General Public License along
|
---|
25 | // with this program; if not, write to the Free Software Foundation, Inc.,
|
---|
26 | // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
---|
27 | //
|
---|
28 | // ===========================================================
|
---|
29 | // ----------------------------------------*- mode: C++; -*--
|
---|
30 | // protlib_types.h - various typedefs
|
---|
31 | // ----------------------------------------------------------
|
---|
32 | // $Id: protlib_types.h 3064 2008-07-02 08:05:18Z bless $
|
---|
33 | // $HeadURL: https://svn.ipv6.tm.uka.de/nsis/protlib/trunk/include/protlib_types.h $
|
---|
34 | // ==========================================================
|
---|
35 | //
|
---|
36 | // (C)opyright, all rights reserved by
|
---|
37 | // - Institute of Telematics, University of Karlsruhe (TH)
|
---|
38 | // ==========================================================
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * @ingroup types
|
---|
42 | *
|
---|
43 | */
|
---|
44 |
|
---|
45 | #ifndef PROTLIB__TYPES_H
|
---|
46 | #define PROTLIB__TYPES_H
|
---|
47 |
|
---|
48 | #include <iostream>
|
---|
49 | #include <fstream>
|
---|
50 | #include <exception>
|
---|
51 |
|
---|
52 | #include <cassert>
|
---|
53 |
|
---|
54 | #include <netinet/in.h> // required for IPPROTO constants
|
---|
55 |
|
---|
56 | #include <sys/types.h>
|
---|
57 |
|
---|
58 | // What's this used for? If if it's not needed, please delete it.
|
---|
59 | #define _THREADS
|
---|
60 |
|
---|
61 |
|
---|
62 | namespace protlib {
|
---|
63 | using namespace std;
|
---|
64 | using namespace __gnu_cxx;
|
---|
65 |
|
---|
66 | /**
|
---|
67 | * @addtogroup types Type Definitions
|
---|
68 | * @{
|
---|
69 | */
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * The abstract base class for all exceptions thrown by protlib.
|
---|
73 | */
|
---|
74 | class ProtLibException : public std::exception {
|
---|
75 | public:
|
---|
76 | virtual ~ProtLibException() throw() { }
|
---|
77 |
|
---|
78 | /**
|
---|
79 | * Get a printable string representation of the error.
|
---|
80 | *
|
---|
81 | * @warning Note that the data this pointer refers to still belongs
|
---|
82 | * to the exception object. It is only valid as long as the exception
|
---|
83 | * object exists.
|
---|
84 | *
|
---|
85 | * @return the error message
|
---|
86 | */
|
---|
87 | virtual const char *what() const throw() { return error_msg.c_str(); }
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * Deprecated: Use what() instead.
|
---|
91 | */
|
---|
92 | virtual const char *getstr() const { return what(); }
|
---|
93 |
|
---|
94 |
|
---|
95 | protected:
|
---|
96 | ProtLibException() throw() { }
|
---|
97 | ProtLibException(std::string msg) throw() : error_msg(msg) { }
|
---|
98 |
|
---|
99 | std::string error_msg;
|
---|
100 | };
|
---|
101 |
|
---|
102 | inline ostream& operator<<(ostream& os, const ProtLibException &err) {
|
---|
103 | return os << err.what();
|
---|
104 | }
|
---|
105 |
|
---|
106 |
|
---|
107 | typedef unsigned char uchar;
|
---|
108 |
|
---|
109 | typedef char int8;
|
---|
110 | typedef unsigned char uint8;
|
---|
111 |
|
---|
112 | typedef short int int16;
|
---|
113 | typedef unsigned short int uint16;
|
---|
114 |
|
---|
115 | // the following types depend on the platform
|
---|
116 | // since types.h tries to figure out the correct sizes already
|
---|
117 | // we will not replicate the stuff here. Note that on 64-bit
|
---|
118 | // platforms usually int == 32-bit, long == 64-bit
|
---|
119 |
|
---|
120 | typedef int32_t int32;
|
---|
121 | typedef u_int32_t uint32;
|
---|
122 |
|
---|
123 | typedef int64_t int64;
|
---|
124 | typedef u_int64_t uint64;
|
---|
125 |
|
---|
126 |
|
---|
127 | class uint128 {
|
---|
128 | public:
|
---|
129 | uint32 w1;
|
---|
130 | uint32 w2;
|
---|
131 | uint32 w3;
|
---|
132 | uint32 w4;
|
---|
133 | uint128() : w1(0),w2(0),w3(0),w4(0) {};
|
---|
134 | uint128(uint32 w1, uint32 w2, uint32 w3, uint32 w4) : w1(w1),w2(w2),w3(w3),w4(w4) {};
|
---|
135 | bool operator==(const uint128& val) const { return w1==val.w1 && w2==val.w2 && w3==val.w3 && w4==val.w4; }
|
---|
136 | };
|
---|
137 |
|
---|
138 |
|
---|
139 | /// Network prefix length.
|
---|
140 | typedef uint8 prefix_length_t;
|
---|
141 |
|
---|
142 | /// Protocol number, as it is given in an IP header.
|
---|
143 | typedef uint8 protocol_t;
|
---|
144 |
|
---|
145 | /** these are pseudo protocol IDs in order to being able to perform
|
---|
146 | * multiplexing based on on address object alone
|
---|
147 | * currently used for Query encapsulation and TLS/TCP
|
---|
148 | * this should be changed in the future, probably by using an additional
|
---|
149 | * attribute in the appladdress object
|
---|
150 | **/
|
---|
151 | const protocol_t prot_tls_tcp = 254;
|
---|
152 | const protocol_t prot_query_encap= 255;
|
---|
153 | const protocol_t prot_tcp = IPPROTO_TCP;
|
---|
154 | const protocol_t prot_udp = IPPROTO_UDP;
|
---|
155 | const protocol_t prot_sctp = IPPROTO_SCTP;
|
---|
156 |
|
---|
157 | /// Port number, as given in TCP or UDP headers.
|
---|
158 | typedef uint16 port_t;
|
---|
159 |
|
---|
160 | /// A general purpose ID type.
|
---|
161 | typedef uint64 gp_id_t;
|
---|
162 |
|
---|
163 | /// Catch everything, do nothing.
|
---|
164 | #define catch_all(x) try { x; } catch(...) { }
|
---|
165 |
|
---|
166 | // @}
|
---|
167 |
|
---|
168 | } // namespace protlib
|
---|
169 |
|
---|
170 | #endif // PROTLIB__TYPES_H
|
---|