Created
July 11, 2015 12:15
-
-
Save jasperla/64851f4fa3e3b23b6b51 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- lib/inc/internal/facts/bsd/networking_resolver.hpp.orig Sat Jul 11 14:08:19 2015 | |
| +++ lib/inc/internal/facts/bsd/networking_resolver.hpp Sat Jul 11 14:08:23 2015 | |
| @@ -32,6 +32,20 @@ namespace facter { namespace facts { namespace bsd { | |
| virtual boost::optional<uint64_t> get_link_mtu(std::string const& interface, void* data) const = 0; | |
| /** | |
| + * Determines if the given sock address is a link layer address. | |
| + * @param addr The socket address to check. | |
| + * @returns Returns true if the socket address is a link layer address or false if it is not. | |
| + */ | |
| + virtual bool is_link_address(sockaddr const* addr) const override; | |
| + | |
| + /** | |
| + * Gets the bytes of the link address. | |
| + * @param addr The socket address representing the link address. | |
| + * @return Returns a pointer to the address bytes or nullptr if not a link address. | |
| + */ | |
| + virtual uint8_t const* get_link_address_bytes(sockaddr const* addr) const override; | |
| + | |
| + /** | |
| * Gets the primary interface. | |
| * This is typically the interface of the default route. | |
| * @return Returns the primary interface or empty string if one could not be determined. | |
| --- lib/src/facts/bsd/networking_resolver.cc.orig Fri Jun 26 01:47:38 2015 | |
| +++ lib/src/facts/bsd/networking_resolver.cc Sat Jul 11 14:06:40 2015 | |
| @@ -5,6 +5,8 @@ | |
| #include <facter/util/directory.hpp> | |
| #include <leatherman/logging/logging.hpp> | |
| #include <boost/algorithm/string.hpp> | |
| +#include <net/if.h> | |
| +#include <net/if_dl.h> | |
| #include <netinet/in.h> | |
| using namespace std; | |
| @@ -90,6 +92,31 @@ namespace facter { namespace facts { namespace bsd { | |
| data.interfaces.emplace_back(move(iface)); | |
| } | |
| return data; | |
| + } | |
| + | |
| + bool networking_resolver::is_link_address(sockaddr const* addr) const | |
| + { | |
| + return addr && addr->sa_family == AF_LINK; | |
| + } | |
| + | |
| + uint8_t const* networking_resolver::get_link_address_bytes(sockaddr const* addr) const | |
| + { | |
| + if (!is_link_address(addr)) { | |
| + return nullptr; | |
| + } | |
| + sockaddr_dl const* link_addr = reinterpret_cast<sockaddr_dl const*>(addr); | |
| + if (link_addr->sdl_alen != 6) { | |
| + return nullptr; | |
| + } | |
| + return reinterpret_cast<uint8_t const*>(LLADDR(link_addr)); | |
| + } | |
| + | |
| + boost::optional<uint64_t> networking_resolver::get_link_mtu(string const& interface, void* data) const | |
| + { | |
| + ifreq req; | |
| + memset(&req, 0, sizeof(req)); | |
| + strncpy(req.ifr_name, interface.c_str(), sizeof(req.ifr_name)); | |
| + return req.ifr_mtu; | |
| } | |
| void networking_resolver::populate_address(interface& iface, ifaddrs const* addr) const |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment