• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ IPAddress函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: _address

Arc::Socket::Socket( unsigned int socket )

#endif // WINDOWS

	: _address(),
	  _port(), 
	  _type(INVALID_SOCKET_TYPE),
	  _socket(socket),
	  _error(false),
	  _errorMsg()
{
	char buf[INET_ADDRSTRLEN] = "";
	struct sockaddr_in name;
	socklen_t len = sizeof(name);
	int res;

	res = getpeername(socket, (struct sockaddr *)&name, &len);

	if (res == 0)
	{
		inet_ntop(AF_INET, &name.sin_addr, buf, sizeof buf);
	}
	else
	{
		setError("getpeername() failed");
		cleanup();
	}

	_address = IPAddress(inet_ntoa(name.sin_addr));
	_port = name.sin_port;
	_type = SOCKET_TYPE_TCP; // TODO: Get actual socket type when UDP is implemented
}
开发者ID:WhoBrokeTheBuild,项目名称:Arc,代码行数:32,代码来源:Socket.cpp


示例2: millis

 // if this is the first time calling now() or after 6 hours an NTP update is perfomed
 // warn: now() should be called within 50 days from the last call
 // warn: loses about 3 seconds every 10 hours
 DateTime MTD_FLASHMEM DateTime::now()
 {
     uint32_t currentMillis = millis();
     uint32_t locLastMillis = lastMillis();
     uint32_t diff = (currentMillis < locLastMillis) ? (0xFFFFFFFF - locLastMillis + currentMillis) : (currentMillis - locLastMillis);
     
     if (locLastMillis == 0 || diff > 6 * 3600 * 1000)
     {
         if (lastDateTime().getFromNTPServer())
         {
             lastMillis() = currentMillis;
             return lastDateTime();
         }
     }
     
     DateTime result;
     result.setUnixDateTime( lastDateTime().getUnixDateTime() + (diff / 1000) );
     
     if (s_defaultNTPServer == IPAddress(0, 0, 0, 0))
     {
         // NTP synchronizatin is disabled. Take care for millis overflow.
         if (diff > 10 * 24 * 3600 * 1000)   // past 10 days?
         {
             // reset millis counter to avoid overflow (actually it overflows after 50 days)
             lastMillis()   = currentMillis;
             lastDateTime() = result;
         }
     }
     
     return result;
 }
开发者ID:LeandroTE,项目名称:ESP8266,代码行数:34,代码来源:fdvdatetime.cpp


示例3: DEBUG_WIFI_GENERIC

int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResult, uint32_t timeout_ms)
{
    ip_addr_t addr;
    aResult = static_cast<uint32_t>(0);

    if(aResult.fromString(aHostname)) {
        // Host name is a IP address use it!
        DEBUG_WIFI_GENERIC("[hostByName] Host: %s is a IP!\n", aHostname);
        return 1;
    }

    DEBUG_WIFI_GENERIC("[hostByName] request IP for: %s\n", aHostname);
    err_t err = dns_gethostbyname(aHostname, &addr, &wifi_dns_found_callback, &aResult);
    if(err == ERR_OK) {
        aResult = IPAddress(&addr);
    } else if(err == ERR_INPROGRESS) {
        _dns_lookup_pending = true;
        delay(timeout_ms);
        _dns_lookup_pending = false;
        // will return here when dns_found_callback fires
        if(aResult.isSet()) {
            err = ERR_OK;
        }
    }

    if(err != 0) {
        DEBUG_WIFI_GENERIC("[hostByName] Host: %s lookup error: %d!\n", aHostname, (int)err);
    } else {
        DEBUG_WIFI_GENERIC("[hostByName] Host: %s IP: %s\n", aHostname, aResult.toString().c_str());
    }

    return (err == ERR_OK) ? 1 : 0;
}
开发者ID:everslick,项目名称:Arduino,代码行数:33,代码来源:ESP8266WiFiGeneric.cpp


示例4: begin

int EthernetClass::begin(uint8_t *mac_address)
{
  static DhcpClass s_dhcp;
  _dhcp = &s_dhcp;


  // Initialise the basic info
  W5100.init();
  W5100.setMACAddress(mac_address);
  W5100.setIPAddress(IPAddress(0,0,0,0).raw_address());

  // Now try to get our config info from a DHCP server
  int ret = _dhcp->beginWithDHCP(mac_address);
  if(ret == 1)
  {
    // We've successfully found a DHCP server and got our configuration info, so set things
    // accordingly
    W5100.setIPAddress(_dhcp->getLocalIp().raw_address());
    W5100.setGatewayIp(_dhcp->getGatewayIp().raw_address());
    W5100.setSubnetMask(_dhcp->getSubnetMask().raw_address());
    _dnsServerAddress = _dhcp->getDnsServerIp();
  }

  return ret;
}
开发者ID:12019,项目名称:libraries,代码行数:25,代码来源:Ethernet.cpp


示例5: getaddrinfo

IPAddresses Dns::Resolve(const std::string& host) {
    IPAddresses list;
    addrinfo hints = { 0 }, *addresses;

    //hints.ai_family = AF_UNSPEC;
    hints.ai_family = AF_INET;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_protocol = IPPROTO_TCP;

    getaddrinfo(host.c_str(), NULL, &hints, &addresses);

    for (addrinfo *p = addresses; p != NULL; p = p->ai_next) {
#ifdef _WIN32
        //wchar_t straddr[35];
        //char straddr[512];
        //DWORD len;
        //WSAAddressToStringA(p->ai_addr, p->ai_addrlen, NULL, straddr, &len);
        
        char* straddr = inet_ntoa(((sockaddr_in*)p->ai_addr)->sin_addr);

#else
        char straddr[512];

        inet_ntop(p->ai_family, &((sockaddr_in*)p->ai_addr)->sin_addr, straddr, sizeof(straddr));
#endif

        list.push_back(IPAddress(straddr));
    }

    return list;
}
开发者ID:plushmonkey,项目名称:mclib,代码行数:31,代码来源:Network.cpp


示例6: begin

int EthernetClass::begin(uint8_t *mac_address, unsigned long timeout, unsigned long responseTimeout)
{
  static DhcpClass s_dhcp;
  _dhcp = &s_dhcp;


  // Initialise the basic info
  W5100.init();
  SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
  W5100.setMACAddress(mac_address);
  W5100.setIPAddress(IPAddress(0,0,0,0).raw_address());
  SPI.endTransaction();

  // Now try to get our config info from a DHCP server
  int ret = _dhcp->beginWithDHCP(mac_address, timeout, responseTimeout);
  if(ret == 1)
  {
    // We've successfully found a DHCP server and got our configuration info, so set things
    // accordingly
    SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    W5100.setIPAddress(_dhcp->getLocalIp().raw_address());
    W5100.setGatewayIp(_dhcp->getGatewayIp().raw_address());
    W5100.setSubnetMask(_dhcp->getSubnetMask().raw_address());
    SPI.endTransaction();
    _dnsServerAddress = _dhcp->getDnsServerIp();
  }

  return ret;
}
开发者ID:00alis,项目名称:Arduino,代码行数:29,代码来源:Ethernet.cpp


示例7: IPAddress

   bool
   MessageUtilities::RetrieveOriginatingAddress(std::shared_ptr<Message> pMessage, String &hostName, IPAddress &address)
   //---------------------------------------------------------------------------()
   // DESCRIPTION:
   // Tries to determine the IP address / host this email originally comes from.
   //---------------------------------------------------------------------------()
   {
      hostName = "";
      address = IPAddress();

      // Extract Received headers from the message.
      std::shared_ptr<MimeHeader> pHeader = GetMessageHeader_(pMessage);

      std::list<String> receivedHeaders;

      AnsiString sHeaderName = "Received";
      std::vector<MimeField> &lstFields = pHeader->Fields();
      auto iter = lstFields.begin();
      auto iterEnd = lstFields.end();
   
      for (; iter != iterEnd; iter++)
      {
         MimeField& fd = *iter;
         
         if (sHeaderName.CompareNoCase(fd.GetName()) == 0)
         {
            receivedHeaders.push_back(fd.GetValue());
         }
      }

      return RetrieveOriginatingAddress(receivedHeaders, hostName, address);
   }
开发者ID:AimaTeam-hehai,项目名称:hmailserver,代码行数:32,代码来源:MessageUtilities.cpp


示例8: sizeof

Jatta::Network::IPAddress Jatta::Network::SocketTCP::GetIP()
{
    struct sockaddr_storage _Addr;
    socklen_t _Length = sizeof(_Addr);
    getpeername(sock, (struct sockaddr*)&_Addr, &_Length);
    if (_Addr.ss_family == AF_INET) // ipv4
    {
        return IPAddress((UInt32)((struct sockaddr_in*)&_Addr)->sin_addr.s_addr);
    }
    else // ipv6
    {
        UInt64 address[2];
        memcpy(&address, &((struct sockaddr_in6*)&_Addr)->sin6_addr, sizeof(address));
        return IPAddress(address);
    }
}
开发者ID:JoshuaBrookover,项目名称:Jatta,代码行数:16,代码来源:SocketTCP.cpp


示例9: getResponses

bool MDNS::processQueries() {
    uint16_t n = udp->parsePacket();

    if (n > 0) {
        buffer->read(udp);

        udp->flush();

        uint16_t responses = getResponses();

        buffer->clear();

        if (responses > 0) {
            writeResponses(responses);
        }

        if (buffer->available() > 0) 
        {
            //Serial.println("buffer->available()");
            udp->beginPacket(IPAddress(224, 0, 0, 251), MDNS_PORT);

            buffer->write(udp);

            udp->endPacket();
        }
    }

    return n > 0;
}
开发者ID:JacksonLv,项目名称:Duo-Particle-example,代码行数:29,代码来源:MDNS.cpp


示例10: sizeof

void SocketImpl::getOption(int level, int option, IPAddress& value)
{
    char buffer[IPAddress::MAX_ADDRESS_LENGTH];
    pil_socklen_t len = sizeof(buffer);
    getRawOption(level, option, buffer, len);
    value = IPAddress(buffer, len);
}
开发者ID:HANDS-FREE,项目名称:PIL,代码行数:7,代码来源:SocketImpl.cpp


示例11: self

IPAddress IPAddress::operator ~ () const
{
	if (family() == IPv4)
	{
		IPv4AddressImpl self(this->pImpl()->addr());
		return IPAddress((~self).addr(), sizeof(struct in_addr));
	}
#if defined(POCO_HAVE_IPv6)
	else if (family() == IPv6)
	{
		const IPv6AddressImpl self(pImpl()->addr(), pImpl()->scope());
        const IPv6AddressImpl r = ~self;
		return IPAddress(r.addr(), sizeof(struct in6_addr), r.scope());
	}
#endif
	else throw Poco::InvalidArgumentException("Invalid or unsupported address family passed to IPAddress()");
}
开发者ID:RobertoMalatesta,项目名称:of-1,代码行数:17,代码来源:IPAddress.cpp


示例12: IPAddress

IPAddress  FishinoUDP::remoteIP()
{
	IPAddress ip;
	bool res = Fishino.udpRemoteIP(_sock, ip);
	if(!res)
		return IPAddress(0, 0, 0, 0);
	return ip;
}
开发者ID:gallochri,项目名称:Fishino_Blynk,代码行数:8,代码来源:FishinoUdp.cpp


示例13: startAP

void startAP()
{
    WifiAccessPoint.enable(true);
    WifiAccessPoint.config("Sming InternetOfThings", "", AUTH_OPEN);

	// Optional: Change IP addresses (and disable DHCP)
	WifiAccessPoint.setIP(IPAddress(192, 168, 4, 1));    
}
开发者ID:ivmi,项目名称:Sming-rc,代码行数:8,代码来源:application.cpp


示例14: sizeof

 IPAddress IPAddress::AsIPv6Address() const {
     if (family_ != AF_INET) {
         return *this;
     }
     in6_addr v6addr = kV4MappedPrefix;
     ::memcpy(&v6addr.s6_addr[12], &u_.ip4.s_addr, sizeof(u_.ip4.s_addr));
     return IPAddress(v6addr);
 }
开发者ID:chenjianjun571,项目名称:cioforandroid,代码行数:8,代码来源:IPAddress.cpp


示例15: IPFromString

 bool IPFromString(const std::string& str, IPAddress* out) {
     if (!out) {
         return false;
     }
     in_addr addr;
     if (::inet_pton(AF_INET, str.c_str(), &addr) == 0) {
         in6_addr addr6;
         if (::inet_pton(AF_INET6, str.c_str(), &addr6) == 0) {
             *out = IPAddress();
             return false;
         }
         *out = IPAddress(addr6);
     } else {
         *out = IPAddress(addr);
     }
     return true;
 }
开发者ID:chenjianjun571,项目名称:cioforandroid,代码行数:17,代码来源:IPAddress.cpp


示例16: begin

void udp_srv::begin()
{
    std::function<void(command_response_packet&)> f = std::bind(&udp_srv::broadcast_ack, this, std::placeholders::_1);
    command_layer::register_udp_ack_func(f);
    udp.connect(IPAddress(192,168,1,255),4140);
    udp.listen(4120);
    udp.onPacket([this](AsyncUDPPacket& packet){this->udp_packet_callback(packet);});
}
开发者ID:OpenMYR,项目名称:IoT_Motors,代码行数:8,代码来源:udp_srv.cpp


示例17: Event

   bool
   SpamAssassinTestConnect::TestConnect(const String &hostName, int port, String &message)
   {
     
      String bodyText = 
         "From: [email protected]\r\n"
         "\r\n"
         "XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X.\r\n";

      String tempFile = FileUtilities::GetTempFileName();
      FileUtilities::WriteToFile(tempFile, bodyText, false);

      std::shared_ptr<IOService> pIOService = Application::Instance()->GetIOService();

      bool testCompleted;

      std::shared_ptr<Event> disconnectEvent = std::shared_ptr<Event>(new Event());
      std::shared_ptr<SpamAssassinClient> pSAClient = std::shared_ptr<SpamAssassinClient>(new SpamAssassinClient(tempFile, pIOService->GetIOService(), pIOService->GetClientContext(), disconnectEvent, testCompleted));

      DNSResolver resolver;

      std::vector<String> ip_addresses;
      resolver.GetARecords(hostName, ip_addresses);

      String ip_address;
      if (ip_addresses.size())
      {
         ip_address = *(ip_addresses.begin());
      }
      else
      {
         message = "The IP address for SpamAssassin could not be resolved. Aborting tests.";
         ErrorManager::Instance()->ReportError(ErrorManager::High, 5507, "SpamAssassinTestConnect::TestConnect", message);
         return false;
      }

      // Here we handle of the ownership to the TCPIP-connection layer.
      if (pSAClient->Connect(ip_address, port, IPAddress()))
      {
         // Make sure we keep no references to the TCP connection so that it
         // can be terminated whenever. We're longer own the connection.
         pSAClient.reset();

         disconnectEvent->Wait();
      }

      if (testCompleted)
         message = FileUtilities::ReadCompleteTextFile(tempFile);
      else
      {
         message = "Unable to connect to the specified SpamAssassin server.";
      }

      FileUtilities::DeleteFile(tempFile);

      return testCompleted;

   }
开发者ID:AimaTeam-hehai,项目名称:hmailserver,代码行数:58,代码来源:SpamAssassinTestConnect.cpp


示例18: SpamAssassinClient

   set<boost::shared_ptr<SpamTestResult> >
   SpamTestSpamAssassin::RunTest(boost::shared_ptr<SpamTestData> pTestData)
   {
      set<boost::shared_ptr<SpamTestResult> > setSpamTestResults;
      
      AntiSpamConfiguration& config = Configuration::Instance()->GetAntiSpamConfiguration();

      boost::shared_ptr<Message> pMessage = pTestData->GetMessageData()->GetMessage();
      const String sFilename = PersistentMessage::GetFileName(pMessage);
      
      boost::shared_ptr<SpamAssassinClient> pSAClient = boost::shared_ptr<SpamAssassinClient>(new SpamAssassinClient(sFilename));

      boost::shared_ptr<TCPConnection> pClientConnection = Application::Instance()->GetIOCPServer()->CreateConnection();
      pClientConnection->Start(pSAClient);
      
      String sHost = config.GetSpamAssassinHost();
      int iPort = config.GetSpamAssassinPort();
      // Copy the event so that we know when we've disconnected.
      Event disconnectEvent(pClientConnection->GetConnectionTerminationEvent());

      // Here we handle of the ownership to the TCPIP-connection layer.
      if (pClientConnection->Connect(sHost, iPort, IPAddress()))
      {
         // Make sure we keep no references to the TCP connection so that it
         // can be terminated whenever. We're longer own the connection.
         pClientConnection.reset();

         disconnectEvent.Wait();
      }

      // Copy back the file...
      pSAClient->FinishTesting();
      
       
      // Check if the message is tagged as spam.
      boost::shared_ptr<MessageData> pMessageData = pTestData->GetMessageData();
      pMessageData->RefreshFromMessage();

      bool bIsSpam = false;
      AnsiString sSpamStatus = pMessageData->GetFieldValue("X-Spam-Status");
      if (sSpamStatus.Mid(0, 3).ToUpper() == "YES")
         bIsSpam = true;

      if (bIsSpam)
      {
         int iScore = 0;
         if (config.GetSpamAssassinMergeScore())
            iScore = _ParseSpamAssassinScore(sSpamStatus);
         else
            iScore = config.GetSpamAssassinScore();

         String sMessage = "Tagged as Spam by SpamAssassin";
         boost::shared_ptr<SpamTestResult> pResult = boost::shared_ptr<SpamTestResult>(new SpamTestResult(GetName(), SpamTestResult::Fail, iScore, sMessage));
         setSpamTestResults.insert(pResult);   
      }
      
      return setSpamTestResults;
   }
开发者ID:bogri5520,项目名称:hMailServer,代码行数:58,代码来源:SpamTestSpamAssassin.cpp


示例19: IPAddress

AppWIFI::AppWIFI() {
	_ApIP = IPAddress(String(DEFAULT_AP_IP));
	_client_err_msg = "";
	_con_ctr = 0;
	_scanning = false;
	_dns_active = false;
	_new_connection = false;
	_client_status = CONNECTION_STATUS::IDLE;
}
开发者ID:florian-asche,项目名称:esp_rgbww_firmware,代码行数:9,代码来源:networking.cpp


示例20: lwip_recvfrom

// ret 1 = error
int32_t MTD_FLASHMEM Socket::read(void *buffer, uint32_t maxLength, IPAddress *sourceAddress, uint16_t *sourcePort) {
  sockaddr_in from;
  int fromlen;
  int32_t bytesRecv = lwip_recvfrom(m_socket, buffer, maxLength, 0, (sockaddr *)&from, (socklen_t *)&fromlen);
  if (bytesRecv > 0) {
    *sourceAddress = IPAddress(from.sin_addr.s_addr);
    *sourcePort = ntohs(from.sin_port);
  }
  return bytesRecv;
}
开发者ID:venugopalsomu,项目名称:ESPWebFramework,代码行数:11,代码来源:fdvnetwork.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ IPC_MakeHeader函数代码示例发布时间:2022-05-30
下一篇:
C++ IP6_UPD_PO_STATS函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap