本文整理汇总了C++中IPAddress::fromString方法的典型用法代码示例。如果您正苦于以下问题:C++ IPAddress::fromString方法的具体用法?C++ IPAddress::fromString怎么用?C++ IPAddress::fromString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPAddress
的用法示例。
在下文中一共展示了IPAddress::fromString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: getNetmask
bool EspDrv::getNetmask(IPAddress& mask) {
LOGDEBUG(F("> getNetmask"));
char buf[20];
if (sendCmdGet(F("AT+CIPSTA?"), F("+CIPSTA:netmask:\""), F("\""), buf, sizeof(buf)))
{
mask.fromString (buf);
return true;
}
return false;
}
示例3: 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;
}
示例4: _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");
}
}
}
示例5: hostByName
int WiFiClass::hostByName(const char* aHostname, IPAddress& aResult)
{
// check if aHostname is already an ipaddress
if (aResult.fromString(aHostname)) {
// if fromString returns true we have an IP address ready
return 1;
} else {
// Network led ON (rev A then rev B).
m2m_periph_gpio_set_val(M2M_PERIPH_GPIO16, 0);
m2m_periph_gpio_set_val(M2M_PERIPH_GPIO5, 0);
// Send DNS request:
_resolve = 0;
if (gethostbyname((uint8 *)aHostname) < 0) {
// Network led OFF (rev A then rev B).
m2m_periph_gpio_set_val(M2M_PERIPH_GPIO16, 1);
m2m_periph_gpio_set_val(M2M_PERIPH_GPIO5, 1);
return 0;
}
// Wait for connection or timeout:
unsigned long start = millis();
while (_resolve == 0 && millis() - start < 20000) {
m2m_wifi_handle_events(NULL);
}
// Network led OFF (rev A then rev B).
m2m_periph_gpio_set_val(M2M_PERIPH_GPIO16, 1);
m2m_periph_gpio_set_val(M2M_PERIPH_GPIO5, 1);
if (_resolve == 0) {
return 0;
}
aResult = _resolve;
return 1;
}
}
示例6: 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;
}
}