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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8
9#ifndef INET_SOCKET_ADDRESS_H
10#define INET_SOCKET_ADDRESS_H
11
12#include "ipv4-address.h"
13
14#include "ns3/address.h"
15
16#include <stdint.h>
17
18namespace ns3
19{
20
21/**
22 * @ingroup address
23 *
24 * @brief an Inet address class
25 *
26 * This class is similar to inet_sockaddr in the BSD socket
27 * API. i.e., this class holds an Ipv4Address and a port number
28 * to form an ipv4 transport endpoint.
29 */
31{
32 public:
33 /**
34 * @param ipv4 the ipv4 address
35 * @param port the port number
36 */
37 InetSocketAddress(Ipv4Address ipv4, uint16_t port);
38 /**
39 * @param ipv4 the ipv4 address
40 *
41 * The port number is set to zero by default.
42 */
44 /**
45 * @param port the port number
46 *
47 * The ipv4 address is set to the "Any" address by default.
48 */
49 InetSocketAddress(uint16_t port);
50 /**
51 * @param ipv4 string which represents an ipv4 address
52 * @param port the port number
53 */
54 InetSocketAddress(const char* ipv4, uint16_t port);
55 /**
56 * @param ipv4 string which represents an ipv4 address
57 *
58 * The port number is set to zero.
59 */
60 InetSocketAddress(const char* ipv4);
61 /**
62 * @returns the port number
63 */
64 uint16_t GetPort() const;
65 /**
66 * @returns the ipv4 address
67 */
68 Ipv4Address GetIpv4() const;
69
70 /**
71 * @param port the new port number.
72 */
73 void SetPort(uint16_t port);
74 /**
75 * @param address the new ipv4 address
76 */
77 void SetIpv4(Ipv4Address address);
78
79 /**
80 * @param address address to test
81 * @returns true if the address matches, false otherwise.
82 */
83 static bool IsMatchingType(const Address& address);
84
85 /**
86 * @returns an Address instance which represents this
87 * InetSocketAddress instance.
88 */
89 operator Address() const;
90
91 /**
92 * @brief Returns an InetSocketAddress which corresponds to the input
93 * Address.
94 *
95 * @param address the Address instance to convert from.
96 * @returns an InetSocketAddress
97 */
98 static InetSocketAddress ConvertFrom(const Address& address);
99
100 /**
101 * @brief Convert to an Address type
102 * @return the Address corresponding to this object.
103 */
104 Address ConvertTo() const;
105
106 private:
107 /**
108 * @brief Get the underlying address type (automatically assigned).
109 *
110 * @returns the address type
111 */
112 static uint8_t GetType();
113 Ipv4Address m_ipv4; //!< the IPv4 address
114 uint16_t m_port; //!< the port
115};
116
117} // namespace ns3
118
119#endif /* INET_SOCKET_ADDRESS_H */
a polymophic address class
Definition address.h:90
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)
InetSocketAddress(Ipv4Address ipv4, uint16_t port)
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.
uint16_t port
Definition dsdv-manet.cc:33
Every class exported by the ns3 library is enclosed in the ns3 namespace.