21 #include <boost/filesystem/fstream.hpp> 22 #include <boost/filesystem.hpp> 30 T readTokenFromFile(boost::filesystem::path
const & path)
32 boost::filesystem::ifstream file;
33 file.exceptions( std::ifstream::failbit | std::ifstream::badbit);
35 file.open(path, std::ios::in);
40 }
catch (std::exception &) {
45 int readHexFromFile(boost::filesystem::path
const & path)
48 return std::stoi(readTokenFromFile<std::string>(path), 0, 16);
49 }
catch (std::exception &) {
61 : bus_(Unknown), vendor_(0), device_(0)
65 : bus_(b), vendor_(v), device_(d)
69 : bus_(
Unknown), vendor_(v), device_(d)
78 boost::filesystem::directory_iterator end_itr;
79 for (boost::filesystem::directory_iterator itr (
"/sys/class/net"); itr != end_itr; ++itr) {
80 if (not boost::filesystem::is_symlink(itr->path()))
82 if (readTokenFromFile<senf::MACAddress>(itr->path()/
"address") != addr)
84 if (not boost::filesystem::exists(itr->path()/
"device"))
87 boost::uint16_t
vendor (readHexFromFile(itr->path()/
"device"/
"vendor"));
88 boost::uint16_t
device (readHexFromFile(itr->path()/
"device"/
"device"));
89 std::string b (
"Unknown");
90 if (boost::filesystem::exists(itr->path()/
"device"/
"subsystem"))
91 b = boost::filesystem::canonical(itr->path()/
"device"/
"subsystem").filename().string();
95 if (b ==
"pci_express")
107 senf::console::format(
id, os);
114 if (bus_ != other.bus_)
115 return bus_ < other.bus_;
116 if (vendor_ != other.vendor_)
117 return vendor_ < other.vendor_;
118 return device_ < other.device_;
124 return bus_ == other.bus_ and
125 vendor_ == other.vendor_ and
126 device_ == other.device_;
165 boost::uint16_t id (calcFirstFreeId());
175 prefix_ void senf::emu::SimpleInterfaceIdFactory::v_releaseId(
MACAddress const &
id)
177 idSet_.erase( boost::uint16_t(
id[4]) << 16 | boost::uint16_t(
id[5]));
180 prefix_ boost::uint32_t senf::emu::SimpleInterfaceIdFactory::calcFirstFreeId()
186 if (*idSet_.begin() > 1)
188 IdSet::const_iterator i = std::adjacent_find(
189 idSet_.begin(), idSet_.end(), boost::lambda::_1+1 < boost::lambda::_2 );
190 if (i == idSet_.end()) --i;
static MACAddress const None
boost::uint16_t device() const
static const InterfaceDeviceId None
bool operator==(InterfaceDeviceId const &other) const
bool operator<(InterfaceDeviceId const &other) const
InterfaceId public header.
boost::uint16_t vendor() const
std::ostream & operator<<(std::ostream &os, InterfaceDeviceId const &id)
static InterfaceDeviceId get(senf::MACAddress const &addr)
void releaseId(MACAddress const &id)