当前位置: 首页>>代码示例>>C++>>正文


C++ IPAddress类代码示例

本文整理汇总了C++中IPAddress的典型用法代码示例。如果您正苦于以下问题:C++ IPAddress类的具体用法?C++ IPAddress怎么用?C++ IPAddress使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了IPAddress类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: start_ethernet

void start_ethernet(IPAddress ipAddress, IPAddress netMask, IPAddress gateWay, netif_status_callback_fn status_cb)
{
	struct ip_addr x_ip_addr, x_net_mask, x_gateway;
	extern err_t ethernetif_init(struct netif *netif);

	x_ip_addr.addr = ipAddress.GetV4LittleEndian();

	if (x_ip_addr.addr == 0)
	{
		x_net_mask.addr = 0;
		x_gateway.addr = 0;
	}
	else
	{
		x_net_mask.addr = netMask.GetV4LittleEndian();
		x_gateway.addr = gateWay.GetV4LittleEndian();
	}

	/* Add data to netif */
	netif_add(&gs_net_if, &x_ip_addr, &x_net_mask, &x_gateway, NULL, ethernetif_init, ethernet_input);

	/* Make it the default interface */
	netif_set_default(&gs_net_if);

	/* Setup callback function for netif status change */
	netif_set_status_callback(&gs_net_if, status_cb);

	/* Bring it up */
	if (x_ip_addr.addr == 0)
	{
		/* DHCP mode */
		dhcp_start(&gs_net_if);
	}
	else
	{
		/* Static mode */
		netif_set_up(&gs_net_if);
	}
}
开发者ID:dc42,项目名称:RepRapFirmware,代码行数:39,代码来源:ethernet_sam.cpp

示例2: getGateway

bool EspDrv::getGateway(IPAddress& gw)
{
	LOGDEBUG(F("> getGateway"));

	char buf[20];
	if (sendCmdGet(F("AT+CIPSTA?"), F("+CIPSTA:gateway:\""), F("\""), buf, sizeof(buf)))
	{
		gw.fromString (buf);
		return true;
	}

	return false;
}
开发者ID:DiazMaxiM,项目名称:The_Bomb_Game,代码行数:13,代码来源:EspDrv.cpp

示例3: socket

bool EthernetClient::connect(IPAddress& host,int port) {

    fd = socket(AF_INET,SOCK_STREAM,0);
    if (fd == -1) return false;

    memset(&servaddr,0,sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_addr.s_addr = inet_addr(host.getAddress());
    servaddr.sin_port = htons(port);

    int res = ::connect(fd,(struct sockaddr*)&servaddr,sizeof(servaddr));

    return ( res != -1 );
} // connect(IPAddress&,...)
开发者ID:ern0,项目名称:posixino,代码行数:14,代码来源:posixino.cpp

示例4: memcmp

bool IPAddress::operator<(const IPAddress& ha) const {
	if (AddressFamily != ha.AddressFamily)
		return (int)get_AddressFamily() < (int)ha.get_AddressFamily();
	switch ((int)get_AddressFamily()) {
	case AF_DOMAIN_NAME:
		return m_domainname < ha.m_domainname;
	case AF_INET:
		return memcmp(&m_sin.sin_addr, &ha.m_sin.sin_addr, 4) < 0;
	case AF_INET6:
		return memcmp(&m_sin6.sin6_addr, &ha.m_sin6.sin6_addr, 16) < 0;
	default:
		Throw(ExtErr::UnknownHostAddressType);
	}
}
开发者ID:Groestlcoin,项目名称:el,代码行数:14,代码来源:ext-ip-address.cpp

示例5: t

IPAddress IPAddress::operator ^ (const IPAddress& other) const
{
	if (family() == other.family())
	{
		if (family() == IPv4)
		{
			IPv4AddressImpl t(pImpl()->addr());
			IPv4AddressImpl o(other.pImpl()->addr());
			return IPAddress((t ^ o).addr(), sizeof(struct in_addr));
		}
#if defined(POCO_HAVE_IPv6)
		else if (family() == IPv6)
		{
			const IPv6AddressImpl t(pImpl()->addr(), pImpl()->scope());
			const IPv6AddressImpl o(other.pImpl()->addr(), other.pImpl()->scope());
			const IPv6AddressImpl r = t ^ o;
			return IPAddress(r.addr(), sizeof(struct in6_addr), r.scope());
		}
#endif
		else throw Poco::InvalidArgumentException("Invalid or unsupported address family passed to IPAddress()");
	}
	else throw Poco::InvalidArgumentException("Invalid or unsupported address family passed to IPAddress()");
}
开发者ID:RobertAcksel,项目名称:poco,代码行数:23,代码来源:IPAddress.cpp

示例6: sizeof

BinaryWriter& AFXAPI operator<<(BinaryWriter& wr, const IPAddress& ha) {
	wr << (short)ha.get_AddressFamily();
	switch ((int)ha.get_AddressFamily()) {
	case AF_INET:
		wr.Write(&ha.m_sin.sin_addr, sizeof(ha.m_sin.sin_addr));
		break;
	case AF_INET6:
		wr.Write(&ha.m_sin6.sin6_addr, sizeof(ha.m_sin6.sin6_addr));
		break;
	default:
		wr.Write(&ha.m_sockaddr, sizeof(ha.m_sockaddr));		//!!! unknown size
		break;
	}
	return wr;
}
开发者ID:ufasoft,项目名称:el,代码行数:15,代码来源:ext-ip-address.cpp

示例7: connect

bool UdpConnection::connect(IPAddress ip, uint16_t port)
{
	if (udp == NULL)
		initialize();

	if (udp->local_port == 0)
	{
		udp_bind(udp, IP_ADDR_ANY, 0);
		debugf("UDP LocalPort: %d", udp->local_port);
	}

	debugf("UDP connect to %s:%d", ip.toString().c_str(), port);
	err_t res = udp_connect(udp, ip, port);
	return res == ERR_OK;
}
开发者ID:PTDreamer,项目名称:SmingRTOS,代码行数:15,代码来源:UdpConnection.cpp

示例8: assert

void NetworkInterfaceTest::testMap()
{
	NetworkInterface::Map m = NetworkInterface::map(false, false);
	assert (!m.empty());
	for (NetworkInterface::Map::const_iterator it = m.begin(); it != m.end(); ++it)
	{
		std::cout << std::endl << "=============" << std::endl;

		std::cout << "Index:       " << it->second.index() << std::endl;
		std::cout << "Name:        " << it->second.name() << std::endl;
		std::cout << "DisplayName: " << it->second.displayName() << std::endl;
		std::cout << "Status:      " << (it->second.isUp() ? "Up" : "Down") << std::endl;

		NetworkInterface::MACAddress mac(it->second.macAddress());
		if (!mac.empty() && (it->second.type() != NetworkInterface::NI_TYPE_SOFTWARE_LOOPBACK))
			std::cout << "MAC Address: (" << it->second.type() << ") " << mac << std::endl;

		typedef NetworkInterface::AddressList List;
		const List& ipList = it->second.addressList();
		List::const_iterator ipIt = ipList.begin();
		List::const_iterator ipEnd = ipList.end();
		for (int counter = 0; ipIt != ipEnd; ++ipIt, ++counter)
		{
			std::cout << std::endl << "----------" << std::endl;
			std::cout << "Address " << counter << std::endl;
			std::cout << "----------" << std::endl;
			std::cout << "Address:     " << ipIt->get<NetworkInterface::IP_ADDRESS>() << std::endl;
			IPAddress addr = ipIt->get<NetworkInterface::SUBNET_MASK>();
			if (!addr.isWildcard()) std::cout << "Subnet:      " << addr << " (/" << addr.prefixLength() << ")" << std::endl;
			addr = ipIt->get<NetworkInterface::BROADCAST_ADDRESS>();
			if (!addr.isWildcard()) std::cout << "Broadcast:   " << addr << std::endl;
		}

		std::cout << "=============" << std::endl << std::endl;
	}
}
开发者ID:trafficsim-jp,项目名称:poco,代码行数:36,代码来源:NetworkInterfaceTest.cpp

示例9: connect

bool EPDStreamer::connect(const char *host, uint16_t port)
{
    if (connState != STATE_CONN_DISCONNECTED) {
        return false;
    }

    callbacksEnabled = true;

    IPAddress ip;

    connState = STATE_CONN_CONNECTING;
    Serial.print("Attempting connection to: ");
    Serial.print(host);
    Serial.print(":");
    Serial.println(port);

    bool connectionSuccess;

    if (ip.fromString(host)) {
        Serial.println("Skipping name resolution");
        connectionSuccess = client.connect(ip, port);
    } else {
        connectionSuccess = client.connect(host, port);
    }

    if (connectionSuccess) {
        Serial.println("Connected");

        connState = STATE_CONN_CONNECTED;
        return true;
    } else {
        Serial.println("Connection failed");
        connState = STATE_CONN_DISCONNECTED;
        return false;
    }
}
开发者ID:oxullo,项目名称:weatherpod,代码行数:36,代码来源:epdstreamer.cpp

示例10: addProbedAddr

void TunManager::addProbedAddr(int ifIndex, const IPAddress& addr,
                               uint8_t mask) {
  for (auto& intf : intfs_) {
    if (intf.second->getIfIndex() == ifIndex) {
      intf.second->addAddress(addr, mask);
      return;
    }
  }
  // This function is called for all interface addresses discovered from
  // the host. Since we only create TunIntf object for TUN interfaces,
  // it is normal we cannot find the interface matching the ifIndex provided.
  VLOG(3) << "Cannot find interface @ index " << ifIndex
          << " for probed address " << addr.str() << "/"
          << static_cast<int>(mask);
}
开发者ID:superchild,项目名称:fboss,代码行数:15,代码来源:TunManager.cpp

示例11: bind

void SocketDefaultImpl::bind(const IPAddress &ip) {
  if (!isOpen()) open();

  struct sockaddr_in addr;

  memset((void *)&addr, 0, sizeof(addr));
  addr.sin_family      = AF_INET;
  addr.sin_port        = htons(ip.getPort());
  addr.sin_addr.s_addr = htonl((unsigned)ip ? (unsigned)ip : INADDR_ANY);

  SysError::clear();
  if (::bind((socket_t)socket, (struct sockaddr *)&addr, sizeof(addr)) ==
      SOCKET_ERROR)
    THROWS("Could not bind socket to " << ip << ": " << SysError());
}
开发者ID:kbernhagen,项目名称:cbang,代码行数:15,代码来源:SocketDefaultImpl.cpp

示例12: connect

int EthernetClient::connect(IPAddress ip, uint16_t port)
{
	if (m_sock)
		return 0;
	struct sockaddr_in sin = {0};
	sin.sin_family = AF_INET;
	sin.sin_port = htons(port);
	sin.sin_addr.s_addr = *(uint32_t*) (ip.raw_address());
	m_sock = socket(AF_INET, SOCK_STREAM, 0);
	if (::connect(m_sock, (struct sockaddr *) &sin, sizeof(sin)) < 0)
	{
		trace("Error Connecting(%d)%s\n", errno, strerror(errno));
		return false;
	}
	m_connected = true;
	return 1;
}
开发者ID:egisz,项目名称:sprinklers_pi,代码行数:17,代码来源:port.cpp

示例13: lock

   bool 
   WhiteListCache::IsWhitelisted(const String &fromAddress, const IPAddress &address)
   {
      // Create a lock for shared operations
      boost::upgrade_lock< boost::shared_mutex > lock(_whitelistAccessMutex);

      if (_needRefresh)
      {
         // We need exclusive access to be able to upade the cache
         boost::upgrade_to_unique_lock< boost::shared_mutex > uniqueLock(lock);

         Refresh();
      }

      vector<shared_ptr<WhiteListAddress> >::iterator iter = _whitelistItems.begin();
      vector<shared_ptr<WhiteListAddress> >::iterator iterEnd = _whitelistItems.end();

      for (; iter != iterEnd; iter++)
      {
         shared_ptr<WhiteListAddress> pWhiteAddress = (*iter);

         IPAddress iLowerIP = pWhiteAddress->GetLowerIPAddress();
         IPAddress iUpperIP = pWhiteAddress->GetUpperIPAddress();

         if (address.WithinRange(iLowerIP, iUpperIP))
         {
            String sWhiteEmailAddr = pWhiteAddress->GetEmailAddress();

            if (sWhiteEmailAddr.IsEmpty() || sWhiteEmailAddr == _T("*"))
            {
               // White listed
               return true;
            }

            // Check if the senders email address matches
            if (StringParser::WildcardMatchNoCase(sWhiteEmailAddr, fromAddress))
            {
               // White listed
               return true;
            }
         }
      }

      return false;

   }
开发者ID:Bill48105,项目名称:hmailserver,代码行数:46,代码来源:WhiteListCache.cpp

示例14: hostByAddress

HostEntry DNS::hostByAddress(const IPAddress& address, unsigned 
#ifdef POCO_HAVE_ADDRINFO
							 hintFlags
#endif
							)
{
#if defined(POCO_HAVE_LIBRESOLV)
	Poco::ScopedReadRWLock readLock(resolverLock);
#endif

#if defined(POCO_HAVE_ADDRINFO)
	SocketAddress sa(address, 0);
	static char fqname[1024];
	int rc = getnameinfo(sa.addr(), sa.length(), fqname, sizeof(fqname), NULL, 0, NI_NAMEREQD); 
	if (rc == 0)
	{
		struct addrinfo* pAI;
		struct addrinfo hints;
		std::memset(&hints, 0, sizeof(hints));
		hints.ai_flags = hintFlags;
		rc = getaddrinfo(fqname, NULL, &hints, &pAI);
		if (rc == 0)
		{
			HostEntry result(pAI);
			freeaddrinfo(pAI);
			return result;
		}
		else
		{
			aierror(rc, address.toString());
		}
	}
	else
	{
		aierror(rc, address.toString());
	}
#elif defined(POCO_VXWORKS)
	char name[MAXHOSTNAMELEN + 1];
	if (hostGetByAddr(*reinterpret_cast<const int*>(address.addr()), name) == OK)
	{
		return HostEntry(std::string(name), address);
	}
#else
	struct hostent* he = gethostbyaddr(reinterpret_cast<const char*>(address.addr()), address.length(), address.af());
	if (he)
	{
		return HostEntry(he);
	}
#endif
	int err = lastError();
	error(err, address.toString()); // will throw an appropriate exception
	throw NetException(); // to silence compiler
}
开发者ID:12307,项目名称:poco,代码行数:53,代码来源:DNS.cpp

示例15: name

	HostBinding::HostBinding(IPAddress addr) : name(addr.toString())
	{
		this->Init();
		try
		{
			this->host = DNS::hostByAddress(addr);
		}
		catch (HostNotFoundException&)
		{
			this->invalid = true;
			//TODO: improve this exception so we can properly raise
		}
		catch (NoAddressFoundException&)
		{
			this->invalid = true;
			//TODO: improve this exception so we can properly raise
		}
	}
开发者ID:peggielich,项目名称:titanium,代码行数:18,代码来源:host_binding.cpp


注:本文中的IPAddress类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。