25 #include "ndn-cxx/net/impl/linux-if-constants.hpp"
35 NetworkInterface::NetworkInterface() =
default;
40 if (!address.
getIp().is_unspecified()) {
43 bool isNew = m_netAddresses.erase(address) == 0;
44 m_netAddresses.insert(address);
46 NDN_LOG_DEBUG(
"added address " << address <<
" to " << m_name);
57 if (m_netAddresses.erase(address) > 0) {
58 NDN_LOG_DEBUG(
"removed address " << address <<
" from " << m_name);
74 BOOST_ASSERT(!name.empty());
93 if (m_state != state) {
94 std::swap(m_state, state);
103 std::swap(m_mtu, mtu);
111 m_etherAddress = address;
117 m_etherBrdAddress = address;
125 return os <<
"unknown";
127 return os <<
"loopback";
129 return os <<
"ether";
139 return os <<
"unknown";
143 return os <<
"no-carrier";
145 return os <<
"dormant";
147 return os <<
"running";
153 printFlag(std::ostream& os, uint32_t& flags, uint32_t flagVal,
const char* flagStr)
155 if (flags & flagVal) {
157 os << flagStr << (flags ?
"," :
"");
168 #define PRINT_IFF(flag) printFlag(os, flags, IFF_##flag, #flag)
174 #if defined(IFF_NOTRAILERS)
182 #if defined(__linux__)
188 #elif defined(__APPLE__) || defined(__FreeBSD__)
195 #if defined(__FreeBSD__)
204 #if defined(__linux__)
205 #define PRINT_IF_FLAG(flag) printFlag(os, flags, linux_if::FLAG_##flag, #flag)
206 PRINT_IF_FLAG(LOWER_UP);
217 os <<
" state " << netif.
getState() <<
" mtu " << netif.
getMtu() <<
"\n"
222 os <<
" " << (addr.getFamily() ==
AddressFamily::V4 ?
"inet " :
"inet6 ") << addr;
223 if (netif.
canBroadcast() && !addr.getBroadcast().is_unspecified()) {
224 os <<
" brd " << addr.getBroadcast();
226 os <<
" scope " << addr.getScope();
227 if (addr.isDeprecated()) {
Helper class to convert a number to hexadecimal format, for use with stream insertion operators.
Represents an Ethernet hardware address.
Stores one IP address supported by a network interface.
boost::asio::ip::address getIp() const
Returns the IP address (v4 or v6)
Represents one network interface attached to the host.
void setMtu(uint32_t mtu)
uint32_t getMtu() const
Returns the MTU (maximum transmission unit) of the interface.
const std::set< NetworkAddress > & getNetworkAddresses() const
Returns all network-layer addresses present on the interface.
void setEthernetAddress(const ethernet::Address &address)
signal::Signal< NetworkInterface, uint32_t, uint32_t > onMtuChanged
Fires when the interface MTU changes.
void setType(InterfaceType type)
void setState(InterfaceState state)
bool removeNetworkAddress(const NetworkAddress &address)
uint32_t getFlags() const
Returns a bitset of platform-specific flags enabled on the interface.
void setEthernetBroadcastAddress(const ethernet::Address &address)
bool canBroadcast() const
Returns true if the interface supports broadcast communication.
signal::Signal< NetworkInterface, NetworkAddress > onAddressRemoved
Fires when a network-layer address is removed from the interface.
InterfaceState getState() const
Returns the current state of the interface.
std::string getName() const
Returns the name of the interface, unique on the system.
signal::Signal< NetworkInterface, NetworkAddress > onAddressAdded
Fires when a network-layer address is added to the interface.
ethernet::Address getEthernetAddress() const
Returns the link-layer (Ethernet) address of the interface.
void setFlags(uint32_t flags)
bool addNetworkAddress(const NetworkAddress &address)
ethernet::Address getEthernetBroadcastAddress() const
Returns the link-layer (Ethernet) broadcast address of the interface.
InterfaceType getType() const
Returns the hardware type of the interface.
void setName(const std::string &name)
signal::Signal< NetworkInterface, InterfaceState, InterfaceState > onStateChanged
Fires when the interface state changes.
int getIndex() const
Returns an opaque ID that uniquely identifies the interface on the system.
#define NDN_LOG_DEBUG(expression)
Log at DEBUG level.
#define NDN_LOG_INIT(name)
Define a non-member log module.
std::ostream & operator<<(std::ostream &os, AddressScope scope)
InterfaceType
Indicates the hardware type of a network interface.
InterfaceState
Indicates the state of a network interface.
@ RUNNING
interface can be used to send and receive packets
@ UNKNOWN
interface is in an unknown state
@ DORMANT
interface has a carrier but it cannot send or receive normal user traffic yet
@ DOWN
interface is administratively down
@ NO_CARRIER
interface is administratively up but has no carrier