本文整理汇总了C++中NetworkInterface::name方法的典型用法代码示例。如果您正苦于以下问题:C++ NetworkInterface::name方法的具体用法?C++ NetworkInterface::name怎么用?C++ NetworkInterface::name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetworkInterface
的用法示例。
在下文中一共展示了NetworkInterface::name方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: receive_probe_requests
void receive_probe_requests(NetworkInterface iface) {
SnifferConfiguration config;
config.set_rfmon(true);
config.set_filter("type mgt subtype probe-req || type data subtype null");
Sniffer sniffer(iface.name(), config);
while(true) process(sniffer.next_packet());
}
示例2: socket_open_error
void PacketSender::open_l2_socket(const NetworkInterface& iface) {
#if defined(BSD) || defined(__FreeBSD_kernel__)
int sock = -1;
// At some point, there should be an available device
for (int i = 0; sock == -1;i++) {
std::ostringstream oss;
oss << "/dev/bpf" << i;
sock = open(oss.str().c_str(), O_RDWR);
}
if(sock == -1)
throw socket_open_error(make_error_string());
struct ifreq ifr;
strncpy(ifr.ifr_name, iface.name().c_str(), sizeof(ifr.ifr_name) - 1);
if(ioctl(sock, BIOCSETIF, (caddr_t)&ifr) < 0) {
::close(sock);
throw socket_open_error(make_error_string());
}
_ether_socket[iface.id()] = sock;
#else
if (_ether_socket == INVALID_RAW_SOCKET) {
_ether_socket = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
if (_ether_socket == -1)
throw socket_open_error(make_error_string());
}
#endif
}
示例3: testForName
void NetworkInterfaceTest::testForName()
{
NetworkInterface::Map map = NetworkInterface::map();
for (NetworkInterface::Map::const_iterator it = map.begin(); it != map.end(); ++it)
{
NetworkInterface ifc = NetworkInterface::forName(it->second.name());
assert (ifc.name() == it->second.name());
}
}
示例4: GetByName
NetworkInterface* NetworkInterface::GetByName(const String& name, bool do_update)
{
if ((__interfaces != NULL)&&(!do_update))
{
for (uint32 i = 0; i < __interfaces->size(); ++i)
{
NetworkInterface* iface = (*__interfaces)[i];
if (iface->name() == name)
return iface;
}
}
if (do_update)
{
__update();
// and repeat same code from above (blah copy paste)
for (uint32 i = 0; i < __interfaces->size(); ++i)
{
NetworkInterface* iface = (*__interfaces)[i];
if (iface->name() == name)
return iface;
}
}
return NULL;
}
示例5:
NetworkState::NetworkState(String interfaceName):
interfaceName_(interfaceName),
networkMask_(0)
{
Ref<RouteInfoList> routingTable = RouteInfo::queryTable();
for (int i = 0; i < routingTable->count(); ++i) {
RouteInfo *entry = routingTable->at(i);
if (entry->source() || entry->destination()) continue;
if (interfaceName_ != "" && entry->outputInterface() != interfaceName_) continue;
interfaceName_ = entry->outputInterface();
gateway_ = entry->gateway();
break;
}
Ref<NetworkInterfaceList> interfaceList = NetworkInterface::queryAll(AF_UNSPEC);
for (int i = 0; i < interfaceList->count(); ++i) {
NetworkInterface *candidate = interfaceList->at(i);
if (candidate->name() == interfaceName_) {
interface_ = candidate;
Ref<SocketAddressList> addressList = interface_->addressList();
if (!gateway_) {
for (int j = 0; j < addressList->count(); ++j) {
SocketAddress *address = addressList->at(j);
if (address->family() != AF_INET) continue;
address_ = address;
break;
}
}
if (!address_) {
for (int j = 0; j < addressList->count(); ++j) {
SocketAddress *address = addressList->at(j);
if (gateway_ && address->family() != gateway_->family()) continue;
address_ = address;
break;
}
}
}
}
Ref<SocketAddressEntry> entry = cast<SocketAddressEntry>(address_);
if (entry)
networkMask_ = entry->networkMask();
}