A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
inet-socket-address.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2005 INRIA
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 */
19
20#ifndef INET_SOCKET_ADDRESS_H
21#define INET_SOCKET_ADDRESS_H
22
23#include "ipv4-address.h"
24
25#include "ns3/address.h"
26
27#include <stdint.h>
28
29namespace ns3
30{
31
32/**
33 * \ingroup address
34 *
35 * \brief an Inet address class
36 *
37 * This class is similar to inet_sockaddr in the BSD socket
38 * API. i.e., this class holds an Ipv4Address and a port number
39 * to form an ipv4 transport endpoint.
40 */
42{
43 public:
44 /**
45 * \param ipv4 the ipv4 address
46 * \param port the port number
47 */
48 InetSocketAddress(Ipv4Address ipv4, uint16_t port);
49 /**
50 * \param ipv4 the ipv4 address
51 *
52 * The port number is set to zero by default.
53 */
55 /**
56 * \param port the port number
57 *
58 * The ipv4 address is set to the "Any" address by default.
59 */
60 InetSocketAddress(uint16_t port);
61 /**
62 * \param ipv4 string which represents an ipv4 address
63 * \param port the port number
64 */
65 InetSocketAddress(const char* ipv4, uint16_t port);
66 /**
67 * \param ipv4 string which represents an ipv4 address
68 *
69 * The port number is set to zero.
70 */
71 InetSocketAddress(const char* ipv4);
72 /**
73 * \returns the port number
74 */
75 uint16_t GetPort() const;
76 /**
77 * \returns the ipv4 address
78 */
79 Ipv4Address GetIpv4() const;
80
81 /**
82 * \param port the new port number.
83 */
84 void SetPort(uint16_t port);
85 /**
86 * \param address the new ipv4 address
87 */
88 void SetIpv4(Ipv4Address address);
89
90 /**
91 * \param address address to test
92 * \returns true if the address matches, false otherwise.
93 */
94 static bool IsMatchingType(const Address& address);
95
96 /**
97 * \returns an Address instance which represents this
98 * InetSocketAddress instance.
99 */
100 operator Address() const;
101
102 /**
103 * \brief Returns an InetSocketAddress which corresponds to the input
104 * Address.
105 *
106 * \param address the Address instance to convert from.
107 * \returns an InetSocketAddress
108 */
109 static InetSocketAddress ConvertFrom(const Address& address);
110
111 /**
112 * \brief Convert to an Address type
113 * \return the Address corresponding to this object.
114 */
115 Address ConvertTo() const;
116
117 private:
118 /**
119 * \brief Get the underlying address type (automatically assigned).
120 *
121 * \returns the address type
122 */
123 static uint8_t GetType();
124 Ipv4Address m_ipv4; //!< the IPv4 address
125 uint16_t m_port; //!< the port
126};
127
128} // namespace ns3
129
130#endif /* INET_SOCKET_ADDRESS_H */
a polymophic address class
Definition: address.h:101
an Inet address class
void SetPort(uint16_t port)
static uint8_t GetType()
Get the underlying address type (automatically assigned).
Address ConvertTo() const
Convert to an Address type.
void SetIpv4(Ipv4Address address)
static bool IsMatchingType(const Address &address)
Ipv4Address m_ipv4
the IPv4 address
Ipv4Address GetIpv4() const
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
uint16_t port
Definition: dsdv-manet.cc:44
Every class exported by the ns3 library is enclosed in the ns3 namespace.