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


C++ IPAddress::fromString方法代码示例

本文整理汇总了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;
}
开发者ID:ArduCAM,项目名称:ArduCAM_ESP8266_UNO,代码行数:37,代码来源:ESP8266WiFiGeneric.cpp

示例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;
}
开发者ID:DiazMaxiM,项目名称:The_Bomb_Game,代码行数:12,代码来源:EspDrv.cpp

示例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;
}
开发者ID:FaddliLWibowo,项目名称:WiFiEsp,代码行数:12,代码来源:EspDrv.cpp

示例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");
        }
    }
}
开发者ID:ManiacalLabs,项目名称:ESPSerialWiFiManager,代码行数:18,代码来源:ESPSerialWiFiManager.cpp

示例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;
	}
}
开发者ID:Cacowned,项目名称:WiFi101,代码行数:40,代码来源:WiFi.cpp

示例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;
    }
}
开发者ID:oxullo,项目名称:weatherpod,代码行数:36,代码来源:epdstreamer.cpp


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