Loading automotive/can/1.0/default/libnetdevice/include/libnetdevice/libnetdevice.h +15 −0 Original line number Diff line number Diff line Loading @@ -16,11 +16,16 @@ #pragma once #include <linux/if_ether.h> #include <array> #include <optional> #include <string> namespace android::netdevice { typedef std::array<uint8_t, ETH_ALEN> hwaddr_t; /** * Configures libnetdevice to use PF_CAN sockets instead of AF_INET, * what requires less permissive SEPolicy rules for a given process. Loading Loading @@ -91,4 +96,14 @@ bool add(std::string dev, std::string type); */ bool del(std::string dev); /** * Fetches interface's hardware address. * * \param ifname Interface name * \return Hardware address (MAC address) or nullopt if the lookup failed */ std::optional<hwaddr_t> getHwAddr(const std::string& ifname); } // namespace android::netdevice bool operator==(const android::netdevice::hwaddr_t lhs, const unsigned char rhs[ETH_ALEN]); automotive/can/1.0/default/libnetdevice/libnetdevice.cpp +14 −0 Original line number Diff line number Diff line Loading @@ -81,4 +81,18 @@ bool del(std::string dev) { return sock.send(req) && sock.receiveAck(); } std::optional<hwaddr_t> getHwAddr(const std::string& ifname) { auto ifr = ifreqs::fromName(ifname); if (!ifreqs::send(SIOCGIFHWADDR, ifr)) return std::nullopt; hwaddr_t hwaddr; memcpy(hwaddr.data(), ifr.ifr_hwaddr.sa_data, hwaddr.size()); return hwaddr; } } // namespace android::netdevice bool operator==(const android::netdevice::hwaddr_t lhs, const unsigned char rhs[ETH_ALEN]) { static_assert(lhs.size() == ETH_ALEN); return 0 == memcmp(lhs.data(), rhs, lhs.size()); } Loading
automotive/can/1.0/default/libnetdevice/include/libnetdevice/libnetdevice.h +15 −0 Original line number Diff line number Diff line Loading @@ -16,11 +16,16 @@ #pragma once #include <linux/if_ether.h> #include <array> #include <optional> #include <string> namespace android::netdevice { typedef std::array<uint8_t, ETH_ALEN> hwaddr_t; /** * Configures libnetdevice to use PF_CAN sockets instead of AF_INET, * what requires less permissive SEPolicy rules for a given process. Loading Loading @@ -91,4 +96,14 @@ bool add(std::string dev, std::string type); */ bool del(std::string dev); /** * Fetches interface's hardware address. * * \param ifname Interface name * \return Hardware address (MAC address) or nullopt if the lookup failed */ std::optional<hwaddr_t> getHwAddr(const std::string& ifname); } // namespace android::netdevice bool operator==(const android::netdevice::hwaddr_t lhs, const unsigned char rhs[ETH_ALEN]);
automotive/can/1.0/default/libnetdevice/libnetdevice.cpp +14 −0 Original line number Diff line number Diff line Loading @@ -81,4 +81,18 @@ bool del(std::string dev) { return sock.send(req) && sock.receiveAck(); } std::optional<hwaddr_t> getHwAddr(const std::string& ifname) { auto ifr = ifreqs::fromName(ifname); if (!ifreqs::send(SIOCGIFHWADDR, ifr)) return std::nullopt; hwaddr_t hwaddr; memcpy(hwaddr.data(), ifr.ifr_hwaddr.sa_data, hwaddr.size()); return hwaddr; } } // namespace android::netdevice bool operator==(const android::netdevice::hwaddr_t lhs, const unsigned char rhs[ETH_ALEN]) { static_assert(lhs.size() == ETH_ALEN); return 0 == memcmp(lhs.data(), rhs, lhs.size()); }