本文整理汇总了C++中NetworkInterface类的典型用法代码示例。如果您正苦于以下问题:C++ NetworkInterface类的具体用法?C++ NetworkInterface怎么用?C++ NetworkInterface使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NetworkInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CpiDeviceList
CpiDeviceListUpnp::CpiDeviceListUpnp(FunctorCpiDevice aAdded, FunctorCpiDevice aRemoved)
: CpiDeviceList(aAdded, aRemoved)
, iStarted(false)
, iXmlFetchSem("DRLS", 0)
, iXmlFetchLock("DRLM")
{
NetworkInterfaceList& ifList = Stack::NetworkInterfaceList();
NetworkInterface* current = ifList.CurrentInterface();
iRefreshTimer = new Timer(MakeFunctor(*this, &CpiDeviceListUpnp::RefreshTimerComplete));
iInterfaceChangeListenerId = ifList.AddCurrentChangeListener(MakeFunctor(*this, &CpiDeviceListUpnp::CurrentNetworkInterfaceChanged));
iSubnetChangeListenerId = ifList.AddSubnetChangeListener(MakeFunctor(*this, &CpiDeviceListUpnp::SubnetChanged));
if (current == NULL) {
iInterface = 0;
iUnicastListener = NULL;
iMulticastListener = NULL;
iNotifyHandlerId = 0;
}
else {
iInterface = current->Address();
iUnicastListener = new SsdpListenerUnicast(*this, iInterface);
iMulticastListener = &Stack::MulticastListenerClaim(iInterface);
iNotifyHandlerId = iMulticastListener->AddNotifyHandler(this);
delete current;
}
}
示例2: scanInterface
/*!
Scans an interface and enumerates all baos devices.
It sends a search request as outlined in the BAOS 1.2 protocol
documentation and waits for the responses. There are lots of
magic numbers here and hard-coded offsets... See the spec
for more information on what is happening here...
We implement a receive timeout, and keep receiving until this
timeout elapses. If this timeout is too fast, increase it to 500
or 1000 for example.
*/
void BaosIpEnumerator::scanInterface(const NetworkInterface& networkInterface)
{
poco_information(LOGGER(),
format("Search devices on interface: %s (%s)",
networkInterface.displayName(),
networkInterface.address().toString()));
try
{
// initialize socket
MulticastSocket socket;
socket.bind(SocketAddress(networkInterface.address(), 0));
socket.setTimeToLive(DefaultMulticastTTL);
// builds and sends a SEARCH_REQUEST to the socket
sendSearchRequestFrame(socket);
// wait for SEARCH_RESPONSES and collect it
waitForSearchResponseFrames(socket);
}
catch (Poco::Exception& e)
{
poco_warning(LOGGER(), format("... search failed with error: %s", e.displayText()));
}
}
示例3: HandleInterfaceChange
void CpiDeviceListUpnp::HandleInterfaceChange(TBool aNewSubnet)
{
NetworkInterface* current = Stack::NetworkInterfaceList().CurrentInterface();
iLock.Wait();
delete iUnicastListener;
iUnicastListener = NULL;
if (iMulticastListener != NULL) {
iMulticastListener->RemoveNotifyHandler(iNotifyHandlerId);
iNotifyHandlerId = 0;
Stack::MulticastListenerRelease(iInterface);
iMulticastListener = NULL;
}
if (current == NULL) {
iInterface = 0;
RemoveAll();
iLock.Signal();
return;
}
iInterface = current->Address();
delete current;
if (aNewSubnet) {
RemoveAll();
}
iUnicastListener = new SsdpListenerUnicast(*this, iInterface);
iUnicastListener->Start();
iMulticastListener = &Stack::MulticastListenerClaim(iInterface);
iNotifyHandlerId = iMulticastListener->AddNotifyHandler(this);
iLock.Signal();
Refresh();
}
示例4: test_bring_up_down
void test_bring_up_down() {
NetworkInterface* net = MBED_CONF_APP_OBJECT_CONSTRUCTION;
for (int i = 0; i < COUNT; i++) {
int err = MBED_CONF_APP_CONNECT_STATEMENT;
TEST_ASSERT_EQUAL(0, err);
printf("MBED: IP Address %s\r\n", net->get_ip_address());
TEST_ASSERT(net->get_ip_address());
UDPSocket udp;
err = udp.open(net);
TEST_ASSERT_EQUAL(0, err);
err = udp.close();
TEST_ASSERT_EQUAL(0, err);
TCPSocket tcp;
err = tcp.open(net);
TEST_ASSERT_EQUAL(0, err);
err = tcp.close();
TEST_ASSERT_EQUAL(0, err);
err = net->disconnect();
TEST_ASSERT_EQUAL(0, err);
}
}
示例5: 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
}
示例6: _ifup
static void _ifup()
{
NetworkInterface *net = NetworkInterface::get_default_instance();
nsapi_error_t err = net->connect();
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
printf("MBED: TLSClient IP address is '%s'\n", net->get_ip_address());
}
示例7: server_sockevent
void RedirectorSrv::server_sockevent( nlink_server *cptr, uint16 revents, void *myNet ) {
NetworkInterface * client;
struct nlink_client *ncptr;
if(revents & PF_READ)
{
client = ( ( NetworkInterface * ) myNet )->getConnection( );
if (!client)
return;
uint32 nonblockingstate = true;
IOCTL_SOCKET( client->getSocketID(), IOCTL_NOBLOCK, &nonblockingstate );
ncptr = new nlink_client;
if(ncptr == NULL)
return;
memset(ncptr, 0, sizeof(*ncptr));
ncptr->hdr.type = RCLIENT;
ncptr->hdr.fd = client->getSocketID();
nlink_insert((struct nlink *)ncptr);
Client *pClient = new Client();
pClient->BindNI(client);
ncptr->pClient = pClient;
pClient->getNetwork()->sendData( mDestination.length( ), mDestination.c_str( ) );
Log::getSingleton( ).outString( "REDIRECTOR: Sent world server" );
disconnect_client( ncptr );
}
}
示例8: loadData
int HistoricalInterface::loadData() {
time_t actual_epoch, adjust_to_epoch;
int ret_state = CONST_HISTORICAL_OK;
NetworkInterface * iface = ntop->getInterfaceById(interface_id);
if((iface != NULL) && (from_epoch != 0) && (to_epoch != 0)) {
u_int8_t iface_dump_id;
iface_dump_id = iface->get_id();
actual_epoch = from_epoch;
adjust_to_epoch = to_epoch - 300; // Adjust to epoch each file contains 5 minute of data
while (actual_epoch <= adjust_to_epoch && isRunning()) {
char path[MAX_PATH];
char db_path[MAX_PATH];
memset(path, 0, sizeof(path));
memset(db_path, 0, sizeof(db_path));
strftime(path, sizeof(path), "%Y/%m/%d/%H/%M", localtime(&actual_epoch));
snprintf(db_path, sizeof(db_path), "%s/%u/flows/%s.sqlite",
ntop->get_working_dir(), iface_dump_id , path);
loadData(db_path);
num_historicals++;
actual_epoch += 300; // 5 minute steps
}
}
on_load = false;
return ret_state;
}
示例9: testForAddress
void NetworkInterfaceTest::testForAddress()
{
NetworkInterface::Map map = NetworkInterface::map();
for (NetworkInterface::Map::const_iterator it = map.begin(); it != map.end(); ++it)
{
// not all interfaces have IP configured
if (it->second.addressList().empty()) continue;
if (it->second.supportsIPv4())
{
NetworkInterface ifc = NetworkInterface::forAddress(it->second.firstAddress(IPAddress::IPv4));
assert (ifc.firstAddress(IPAddress::IPv4) == it->second.firstAddress(IPAddress::IPv4));
IPAddress addr(IPAddress::IPv4);
assert (addr.isWildcard());
it->second.firstAddress(addr, IPAddress::IPv4);
assert (!addr.isWildcard());
}
else
{
try
{
it->second.firstAddress(IPAddress::IPv4);
fail ("must throw");
}
catch (NotFoundException&) { }
IPAddress addr(IPAddress::IPv4);
assert (addr.isWildcard());
it->second.firstAddress(addr, IPAddress::IPv4);
assert (addr.isWildcard());
}
}
}
示例10: onPacketReceivedCb
void NetworkInterface::onPacketReceivedCb(u_char *user,
const struct pcap_pkthdr *h,
const u_char *bytes)
{
NetworkInterface *host = reinterpret_cast<NetworkInterface*>(user);
host->onPacketReceived(h, bytes);
}
示例11: main
int main(int argc, const char *argv[])
{
NetworkInterface ni;
ni.hostGame();
ni.endGame();
return 0;
}
示例12: testForIndex
void NetworkInterfaceTest::testForIndex()
{
NetworkInterface::Map map = NetworkInterface::map();
for (NetworkInterface::Map::const_iterator it = map.begin(); it != map.end(); ++it)
{
NetworkInterface ifc = NetworkInterface::forIndex(it->second.index());
assert (ifc.index() == it->second.index());
}
}
示例13: RandomiseUdn
static void RandomiseUdn(Bwh& aUdn)
{
aUdn.Grow(aUdn.Bytes() + 1 + Ascii::kMaxUintStringBytes + 1);
aUdn.Append('-');
Bws<Ascii::kMaxUintStringBytes> buf;
NetworkInterface* nif = Stack::NetworkInterfaceList().CurrentInterface();
TUint max = nif->Address();
delete nif;
(void)Ascii::AppendDec(buf, Random(max));
aUdn.Append(buf);
aUdn.PtrZ();
}
示例14: setInterface
void MulticastSocket::setInterface(const NetworkInterface& interface)
{
if (!interface.supportsIPv6())
{
impl()->setOption(IPPROTO_IP, IP_MULTICAST_IF, interface.address());
}
else
{
#if defined(POCO_HAVE_IPv6)
impl()->setOption(IPPROTO_IPV6, IPV6_MULTICAST_IF, interface.index());
#endif
}
}
示例15: MULTIHOMING_ASYNCHRONOUS_DNS
void MULTIHOMING_ASYNCHRONOUS_DNS()
{
rtos::Semaphore semaphore;
dns_application_data data;
data.semaphore = &semaphore;
for (unsigned int i = 0; i < MBED_CONF_APP_DNS_TEST_HOSTS_NUM; i++) {
for (unsigned int interface_index = 0; interface_index < MBED_CONF_MULTIHOMING_MAX_INTERFACES_NUM; interface_index++) {
NetworkInterface *interface = get_interface(interface_index);
if (interface == NULL) {
continue;
}
for (unsigned int j = 0; j < interface_num; j++) {
nsapi_error_t err = interface->gethostbyname_async(dns_test_hosts[i],
mbed::Callback<void(nsapi_error_t, SocketAddress *)>(hostbyname_cb, (void *) &data), NSAPI_UNSPEC, interface_name[j]);
TEST_ASSERT(err >= 0);
semaphore.wait();
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, data.result);
printf("DNS: query interface_name %s %d \n", interface_name[j], j);
if (data.result == NSAPI_ERROR_OK) {
result_ok++;
printf("DNS: query OK \"%s\" => \"%s\"\n", dns_test_hosts[i], data.addr.get_ip_address());
} else if (data.result == NSAPI_ERROR_DNS_FAILURE) {
result_dns_failure++;
printf("DNS: query \"%s\" => DNS failure\n", dns_test_hosts[i]);
} else if (data.result == NSAPI_ERROR_TIMEOUT) {
result_exp_timeout++;
printf("DNS: query \"%s\" => timeout\n", dns_test_hosts[i]);
} else if (data.result == NSAPI_ERROR_NO_MEMORY) {
result_no_mem++;
printf("DNS: query \"%s\" => no memory\n", dns_test_hosts[i]);
} else {
printf("DNS: query \"%s\" => %d, unexpected answer\n", dns_test_hosts[i], data.result);
TEST_ASSERT(data.result == NSAPI_ERROR_OK || data.result == NSAPI_ERROR_NO_MEMORY || data.result == NSAPI_ERROR_DNS_FAILURE || data.result == NSAPI_ERROR_TIMEOUT);
}
}
}
}
}