本文整理汇总了C++中IPAddress::toString方法的典型用法代码示例。如果您正苦于以下问题:C++ IPAddress::toString方法的具体用法?C++ IPAddress::toString怎么用?C++ IPAddress::toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPAddress
的用法示例。
在下文中一共展示了IPAddress::toString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sa
Nequeo::Net::Sockets::HostEntry Nequeo::Net::Sockets::DNS::hostByAddress(const IPAddress& address)
{
NetworkInitializer networkInitializer;
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 = AI_CANONNAME | AI_ADDRCONFIG;
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());
}
int err = lastError();
error(err, address.toString()); // will throw an appropriate exception
throw Nequeo::Exceptions::Net::NetException(); // to silence compiler
}
示例2: 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
}
示例3: STAGotIP
void STAGotIP(IPAddress ip, IPAddress mask, IPAddress gateway)
{
debugf("GOTIP - IP: %s, MASK: %s, GW: %s\n", ip.toString().c_str(),
mask.toString().c_str(),
gateway.toString().c_str());
if (WifiAccessPoint.isEnabled())
{
debugf("Shutdown OWN AP");
WifiAccessPoint.enable(false);
}
// Add commands to be executed after successfully connecting to AP and got IP from it
}
示例4: udp_recieve
void udp_recieve(UdpConnection& connection, char *data, int size, IPAddress remoteIP, uint16_t remotePort) {
debugf("UDP Sever callback from %s:%d, %d bytes", remoteIP.toString().c_str(), remotePort, size);
debugf("UDP Data: %s", data);
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
if( !strcmp( data, "enum" ) ){
root.addCopy("ip", WifiStation.getIP().toString());
root.add("pos", driver_pos());
udp.sendStringTo(remoteIP, remotePort, root.toJsonString().c_str());
debugf("Sending to IP:%s:%d resp:%s", remoteIP.toString().c_str(), remotePort, root.toJsonString().c_str());
} else {
debugf("UDP Unknown packet : %s", data);
}
}
示例5: addDevice
void BaosIpEnumerator::addDevice(const std::vector<unsigned char>& buffer, const IPAddress& networkInterface)
{
if (buffer.size() > 68)
{
const int svcdiblen = buffer.at(68);
const std::string ipAddress = format("%d.%d.%d.%d", (int) buffer.at(8), (int) buffer.at(9), (int) buffer.at(10), (int) buffer.at(11));
const std::string deviceName = extract(&buffer.at(38), 30);
const int manOffset = 68 + svcdiblen;
if (static_cast<std::size_t>(manOffset + 7) < buffer.size())
{
const unsigned short mancode = buffer.at(manOffset + 2) << 8 | buffer.at(manOffset + 3);
const unsigned char protocol = buffer.at(manOffset + 6);
const unsigned char version = buffer.at(manOffset + 7);
if (mancode == 0x00C5 && protocol == 0xF0)
{
poco_information(LOGGER(),
format("Found: %s %s %d",
deviceName, ipAddress, static_cast<int>(version)));
devices_.push_back(std::make_tuple(deviceName, networkInterface.toString(), ipAddress, version));
}
}
}
}
示例6: if
/**
* Resolve the given hostname to an IP address.
* @param aHostname Name to be resolved
* @param aResult IPAddress structure to store the returned IP address
* @return 1 if aIPAddrString was successfully converted to an IP address,
* else error code
*/
int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResult) {
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 = addr.addr;
} else if(err == ERR_INPROGRESS) {
esp_yield();
// will return here when dns_found_callback fires
if(aResult != 0) {
err = ERR_OK;
}
}
if(err != 0) {
DEBUG_WIFI_GENERIC("[hostByName] Host: %s lookup error: %d!\n", aHostname, err);
} else {
DEBUG_WIFI_GENERIC("[hostByName] Host: %s IP: %s\n", aHostname, aResult.toString().c_str());
}
return (err == ERR_OK) ? 1 : 0;
}
示例7: hostByAddress
HostEntry DNS::hostByAddress(const IPAddress& address)
{
NetworkInitializer networkInitializer;
#if defined(POCO_HAVE_IPv6) || 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 = AI_CANONNAME | AI_ADDRCONFIG;
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
}
示例8: loop
void loop() {
if (WiFi.ready()) {
if (firstTimeReady) {
firstTimeReady = false;
// First time we get WiFi.ready(), initialize the UDP listener. This happens
// every time we reconnect to WiFi.
mcastUdp.begin(MCAST_PORT);
}
if (!haveServerAddr && millis() - serverAddrLastCheck >= SERVER_ADDR_CHECK_RETRY_MS) {
serverAddrLastCheck = millis();
// If we don't have a server IP address, request it periodically (every 20 seconds)
Serial.printlnf("requesting server address at %s:%d", mcastAddr.toString().c_str(), MCAST_PORT);
strcpy(udpBuffer, "\n");
mcastUdp.sendPacket(udpBuffer, strlen(udpBuffer), mcastAddr, MCAST_PORT);
}
int count = mcastUdp.receivePacket(udpBuffer, UDP_BUFFER_SIZE - 1);
if (count > 0) {
udpBuffer[count] = 0;
// Handle a received UDP packet from the server with the IP address and port of the server
int addr[4], port;
if (sscanf(udpBuffer, "%u.%u.%u.%u:%u", &addr[0], &addr[1], &addr[2], &addr[3], &port) == 5) {
serverAddr = IPAddress(addr[0], addr[1], addr[2], addr[3]);
serverPort = port;
haveServerAddr = true;
Serial.printlnf("serverAddr=%s port=%d", serverAddr.toString().c_str(), serverPort);
}
}
}
else {
// If WiFi disconnects, we need to reestablish listeners next time
firstTimeReady = true;
}
}
示例9: sendTo
void UdpConnection::sendTo(IPAddress remoteIP, uint16_t remotePort, const char* data, int length)
{
remotePort = 1000;
pbuf* p = pbuf_alloc(PBUF_TRANSPORT, length, PBUF_RAM);
memcpy(p->payload, data, length);
udp_sendto(udp, p, remoteIP, remotePort);
pbuf_free(p);
debugf("UdpConnection sendTo : %s %d %s", remoteIP.toString().c_str(),remotePort, data);
}
示例10: onReceive
void DNSServer::onReceive(pbuf* buf, IPAddress remoteIP, uint16_t remotePort)
{
if (_buffer != NULL) free(_buffer);
_buffer = (char*)malloc(buf->tot_len * sizeof(char));
if (_buffer == NULL) return;
pbuf_copy_partial(buf, _buffer, buf->tot_len, 0);
debugf("DNS REQ for %s from %s:%d", getDomainNameWithoutWwwPrefix().c_str(), remoteIP.toString().c_str(), remotePort);
_dnsHeader = (DNSHeader*) _buffer;
if (_dnsHeader->QR == DNS_QR_QUERY &&
_dnsHeader->OPCode == DNS_OPCODE_QUERY &&
requestIncludesOnlyOneQuestion() &&
(_domainName == "*" || getDomainNameWithoutWwwPrefix() == _domainName)
)
{
char response[buf->tot_len+16];
int idx = buf->tot_len;
_dnsHeader->QR = DNS_QR_RESPONSE;
_dnsHeader->ANCount = _dnsHeader->QDCount;
_dnsHeader->QDCount = _dnsHeader->QDCount;
memcpy(response, _buffer, idx);
//Set a pointer to the domain name in the question section
response[idx] = 0xC0;
response[idx+1] = 0x0C;
//Type: "Host Address"
response[idx+2] = 0x00;
response[idx+3] = 0x01;
//Set the response class to IN
response[idx+4] = 0x00;
response[idx+5] = 0x01;
//TTL
response[idx+6] = _ttl >> 24;
response[idx+7] = _ttl >> 16;
response[idx+8] = _ttl >> 8;
response[idx+9] = _ttl;
//RDATA length
response[idx+10] = 0x00;
response[idx+11] = 0x04; //4 byte IP address
//The IP address
response[idx+12] = _resolvedIP[0];
response[idx+13] = _resolvedIP[1];
response[idx+14] = _resolvedIP[2];
response[idx+15] = _resolvedIP[3];
sendTo(remoteIP, remotePort, response, idx+16);
}
示例11: testOperators
void IPAddressTest::testOperators()
{
IPAddress ip("10.0.0.51");
IPAddress mask(24, IPAddress::IPv4);
IPAddress net = ip & mask;
assert(net.toString() == "10.0.0.0");
IPAddress host("0.0.0.51");
assert((net | host) == ip);
assert((~mask).toString() == "0.0.0.255");
}
示例12: 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;
}
示例13: testMap
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>().toString() << std::endl;
IPAddress addr = ipIt->get<NetworkInterface::SUBNET_MASK>();
if (!addr.isWildcard()) std::cout << "Subnet: " << addr.toString() << " (/" << addr.prefixLength() << ")" << std::endl;
addr = ipIt->get<NetworkInterface::BROADCAST_ADDRESS>();
if (!addr.isWildcard()) std::cout << "Broadcast: " << addr.toString() << std::endl;
}
std::cout << "=============" << std::endl << std::endl;
}
}
示例14: 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
}
}
示例15: _prompt_ip
IPAddress ESPSerialWiFiManager::_prompt_ip(String prompt, IPAddress def){
while(true){
String p(prompt);
if(def != 0){
p = p + " (Default: " + def.toString() + ")";
}
String ip_str = _prompt(p, ' ', 0);
if(ip_str.length() == 0){
return def;
}
IPAddress ip;
if(ip.fromString(ip_str))
return ip;
else{
OFL("Invalid IP entered! Please try again.\n");
}
}
}