From 64fac4f2555ede6cffb2e143db88f57c9fdc1777 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 19 Oct 2014 09:13:28 -0300 Subject: [PATCH] Added NetworkInterface::is_loopback. --- include/tins/network_interface.h | 6 ++++++ src/network_interface.cpp | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/include/tins/network_interface.h b/include/tins/network_interface.h index 625f7f3..d69a2af 100644 --- a/include/tins/network_interface.h +++ b/include/tins/network_interface.h @@ -144,6 +144,12 @@ public: operator bool() const { return iface_id != 0; } + + /** + * \brief Indicates whether this is a loopback device. + * @return true iff this is a loopback device. + */ + bool is_loopback() const; /** * \brief Compares this interface for equality. diff --git a/src/network_interface.cpp b/src/network_interface.cpp index af0388d..c68b449 100644 --- a/src/network_interface.cpp +++ b/src/network_interface.cpp @@ -215,6 +215,10 @@ NetworkInterface::Info NetworkInterface::addresses() const { return info; } +bool NetworkInterface::is_loopback() const { + return addresses().ip_addr.is_loopback(); +} + NetworkInterface::id_type NetworkInterface::resolve_index(const char *name) { #ifndef WIN32 id_type id = if_nametoindex(name);