IBR-DTNSuite
0.12
Main Page
Namespaces
Classes
Files
File List
File Members
vaddress.h
Go to the documentation of this file.
1
/*
2
* vaddress.h
3
*
4
* Copyright (C) 2011 IBR, TU Braunschweig
5
*
6
* Written-by: Johannes Morgenroth <morgenroth@ibr.cs.tu-bs.de>
7
*
8
* Licensed under the Apache License, Version 2.0 (the "License");
9
* you may not use this file except in compliance with the License.
10
* You may obtain a copy of the License at
11
*
12
* http://www.apache.org/licenses/LICENSE-2.0
13
*
14
* Unless required by applicable law or agreed to in writing, software
15
* distributed under the License is distributed on an "AS IS" BASIS,
16
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
* See the License for the specific language governing permissions and
18
* limitations under the License.
19
*
20
*/
21
22
#ifndef VADDRESS_H_
23
#define VADDRESS_H_
24
25
#include "
ibrcommon/Exceptions.h
"
26
#include <stdint.h>
27
28
#ifdef __WIN32__
29
#include <winsock2.h>
30
typedef
unsigned
short
int
sa_family_t;
31
#else
32
#include <sys/socket.h>
33
#endif
34
35
namespace
ibrcommon
36
{
37
class
vaddress
38
{
39
public
:
40
class
address_exception
:
public
Exception
41
{
42
public
:
43
address_exception
(
string
error
=
"unspecific address error"
) :
Exception
(
error
)
44
{};
45
};
46
47
class
address_not_set
:
public
address_exception
48
{
49
public
:
50
address_not_set
(
string
error
=
"address is not specified"
) :
address_exception
(
error
)
51
{};
52
};
53
54
class
service_not_set
:
public
address_exception
55
{
56
public
:
57
service_not_set
(
string
error
=
"service is not specified"
) :
address_exception
(
error
)
58
{};
59
};
60
61
class
scope_not_set
:
public
address_exception
62
{
63
public
:
64
scope_not_set
(
string
error
=
"scope is not specified"
) :
address_exception
(
error
)
65
{};
66
};
67
68
const
static
std::string
SCOPE_GLOBAL
;
69
const
static
std::string
SCOPE_LINKLOCAL
;
70
71
const
static
std::string
VADDR_LOCALHOST
;
72
const
static
std::string
VADDR_ANY
;
73
74
vaddress
();
75
vaddress
(
const
int
port, sa_family_t
family
= AF_UNSPEC);
76
vaddress
(
const
std::string &
address
,
const
int
port, sa_family_t
family
= AF_UNSPEC);
77
vaddress
(
const
std::string &
address
,
const
std::string &
service
, sa_family_t
family
= AF_UNSPEC);
78
vaddress
(
const
std::string &
address
,
const
std::string &
service
,
const
std::string &
scope
, sa_family_t
family
= AF_UNSPEC);
79
virtual
~vaddress
();
80
81
bool
isLocal
()
const
;
82
bool
isAny
()
const
;
83
84
sa_family_t
family
()
const
throw (
address_exception
);
85
std::
string
scope
() const throw (
scope_not_set
);
86
const std::
string
address
() const throw (
address_not_set
);
87
const std::
string
name
() const throw (address_exception);
88
const std::
string
service
() const throw (
service_not_set
);
89
90
void
setService
(const uint32_t port);
91
void
setService
(const std::
string
&
service
);
92
93
bool
operator<(const
vaddress
&dhs) const;
94
bool
operator!=(const
vaddress
&obj) const;
95
bool
operator==(const
vaddress
&obj) const;
96
97
const std::
string
toString
() const;
98
99
private:
100
std::
string
_address;
101
std::
string
_service;
102
std::
string
_scope;
103
sa_family_t _family;
104
};
105
}
106
107
#endif
/* VADDRESS_H_ */
ibrcommon
ibrcommon
net
vaddress.h
Generated on Thu Mar 27 2014 09:26:20 for IBR-DTNSuite by
1.8.4