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


C++ dns_gethostbyname函数代码示例

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


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

示例1: tc_go

//-------------------------------------------------------------------------------
// TCP client start
//-------------------------------------------------------------------------------
err_t ICACHE_FLASH_ATTR tc_go(void)
{
	err_t err = ERR_USE;
	if((tc_init_flg & TC_RUNNING) || iot_data_processing == NULL) return err; // выход, если процесс запущен или нечего запускать
	#if DEBUGSOO > 4
		os_printf("Run: %x, %u\n", iot_data_processing, iot_data_processing->min_interval);
	#endif
	err = tc_init(); // инициализация TCP
	if(err == ERR_OK) {
		tc_init_flg |= TC_RUNNING; // процесс запущен
		run_error_timer(TCP_REQUEST_TIMEOUT); // обработать ошибки и продолжение

#if DEBUGSOO > 4
		int i;
		for (i = 0; i < DNS_TABLE_SIZE; ++i) {
			os_printf("TDNS%d: %d, %s, " IPSTR " (%d)\n", i, dns_table[i].state, dns_table[i].name, IP2STR(&dns_table[i].ipaddr), dns_table[i].ttl);
		}
#endif

		err = dns_gethostbyname(iot_server_name, &tc_remote_ip, (dns_found_callback)tc_dns_found_callback, NULL);
#if DEBUGSOO > 4
		os_printf("dns_gethostbyname(%s)=%d ", iot_server_name, err);
#endif
		if(err == ERR_OK) {	// Адрес разрешен из кэша или локальной таблицы
			err = tcpsrv_client_start(tc_servcfg, tc_remote_ip.addr, DEFAULT_TC_HOST_PORT);
		} else if(err == ERR_INPROGRESS) { // Запущен процесс разрешения имени с внешнего DNS
			err = ERR_OK;
		}
		if (err != ERR_OK) {
			tc_init_flg &= ~TC_RUNNING; // процесс не запущен
//				tc_close();
		}
	}
	return err;
}
开发者ID:houzhenggang,项目名称:PowerMeter,代码行数:38,代码来源:iot_cloud.c

示例2: net_dns_static

// Lua: net.dns.resolve( domain, function(sk, ip) )
static int net_dns_static( lua_State* L ) {
  size_t dl;
  const char* domain = luaL_checklstring(L, 1, &dl);
  if (!domain && dl > 128) {
    return luaL_error(L, "wrong domain");
  }

  luaL_checkanyfunction(L, 2);
  lua_pushvalue(L, 2);  // copy argument (func) to the top of stack
  int cbref = luaL_ref(L, LUA_REGISTRYINDEX);
  if (cbref == LUA_NOREF) {
    return luaL_error(L, "wrong callback");
  }
  int *cbref_ptr = c_zalloc(sizeof(int));
  cbref_ptr[0] = cbref;
  ip_addr_t addr;
  err_t err = dns_gethostbyname(domain, &addr, net_dns_static_cb, cbref_ptr);
  if (err == ERR_OK) {
    net_dns_static_cb(domain, &addr, cbref_ptr);
    return 0;
  } else if (err == ERR_INPROGRESS) {
    return 0;
  } else {
    int e = lwip_lua_checkerr(L, err);
    c_free(cbref_ptr);
    return e;
  }
  return 0;
}
开发者ID:Dxploto,项目名称:nodemcu-firmware,代码行数:30,代码来源:net.c

示例3: GAgent_GetHostByName

int GAgent_GetHostByName(char *domain, char *IPAddress)
{
    unsigned char Err;
    ip_addr_t ip_addr;
    char str[32];

    memset(str, 0x0, sizeof(str));

    switch (dns_gethostbyname(domain, &ip_addr, Gagent_ServerFound, NULL)) {
        case ERR_OK:
			memcpy((unsigned char*)IPAddress, (unsigned char*)inet_ntoa(ip_addr.addr), strlen(inet_ntoa(ip_addr.addr)) + 1);
        	GAgent_Printf(GAGENT_LOG, "ok Server name %s, first address: %s", 
                domain, inet_ntoa(domain_ipaddr.addr));
			return 0;
        case ERR_INPROGRESS:
            GAgent_Printf(GAGENT_LOG, "dns_gethostbyname called back success.\n\r");

			/* Waiting for connect success */
		    OSSemPend(pdomainSem, 1000, &Err);
		
		    if (domain_flag == 1) {
		        memcpy((unsigned char*)IPAddress, (unsigned char*)inet_ntoa(domain_ipaddr.addr), strlen(inet_ntoa(domain_ipaddr.addr)) + 1);
		        GAgent_Printf(GAGENT_LOG, "call back Server name %s, first address: %s", 
		                domain, inet_ntoa(domain_ipaddr.addr));
				return 0;
		    } else {
		        return -1;
		    }
            break;

        default:
            GAgent_Printf(GAGENT_LOG, "dns_gethostbyname called back error.\n\r");
            return -1;
    }
}
开发者ID:Marcello168,项目名称:NL6621_GizwitsSDK_Single,代码行数:35,代码来源:adapter_ucos.c

示例4: sntp_request

/**
 * Send out an sntp request via raw API.
 *
 * @param arg is unused (only necessary to conform to sys_timeout)
 */
static void sntp_request(void *arg) {
    ip_addr_t sntp_server_address;
    err_t err;

    LWIP_UNUSED_ARG(arg);

    /* Initialize SNTP server address */
#if SNTP_SERVER_DNS
    err = dns_gethostbyname(sntp_server_addresses[sntp_current_server], &sntp_server_address, sntp_dns_found, NULL);

    if (err == ERR_INPROGRESS) {
        /* DNS request sent, wait for sntp_dns_found being called */
        LWIP_DEBUGF(SNTP_DEBUG_STATE, ("sntp_request: Waiting for server address to be resolved.\n"));
        return;
    }
#else /* SNTP_SERVER_DNS */
    err = ipaddr_aton(sntp_server_addresses[sntp_current_server], &sntp_server_address) ? ERR_OK : ERR_ARG;
#endif /* SNTP_SERVER_DNS */

    if (err == ERR_OK) {
        sntp_send_request(&sntp_server_address);
    } else {
        /* address conversion failed, try another server */
        LWIP_DEBUGF(SNTP_DEBUG_WARN_STATE, ("sntp_request: Invalid server address, trying next server.\n"));
        sys_timeout((u32_t)SNTP_RETRY_TIMEOUT, sntp_try_next_server, NULL);
    }
}
开发者ID:richardeoin,项目名称:vlf-gateway-firmware,代码行数:32,代码来源:sntp.c

示例5: handle_req_state

static void
handle_req_state(void)
{
    switch (req_state) {
    case REQ_DNS_INIT:
        CYG_TEST_INFO("Trying to resolve host name");
        if (dns_gethostbyname(CYGDAT_NET_LWIP_PPP_TEST_HOST, &host_addr,
                              dns_found_cb, NULL) == ERR_OK) {
            // Cached
            req_state = REQ_DNS_SUCCESS;
            break;
        }
        req_state = REQ_DNS_WAIT;
        break;
    case REQ_DNS_WAIT:
        break;
    case REQ_DNS_FAILED:
        CYG_TEST_INFO("Failed to resolve host name");
        test_state = TEST_PPP_CLOSE;
        break;
    case REQ_DNS_SUCCESS:
        CYG_TEST_INFO("Successfully resolved host name");
        success++;
        test_state = TEST_PPP_CLOSE;
        break;
    }
}
开发者ID:Palantir555,项目名称:ecos-mars-zx3,代码行数:27,代码来源:ppp.c

示例6: TimerDelegate

void NtpClient::requestTime()
{
	if (!WifiStation.isConnected())
	{
		connectionTimer.initializeMs(1000, TimerDelegate(&NtpClient::requestTime, this)).startOnce();
		return;
	}

	struct ip_addr resolvedIp;
	int result = dns_gethostbyname(this->server.c_str(), &resolvedIp,
			staticDnsResponse, (void*) this);

	switch (result)
	{
	case ERR_OK:
		// Documentation says this will be the result if the string is already
		// an ip address in dotted decimal form or if the host is found in dns cache.
		// however I'm not sure if the dns cache is working since this never seems to
		// be called for a host lookup other than an ip address.
		// Doesn't really matter since the loockup will be fast anyways, the host
		// is most likely found in the dns cache of the next node the query is sent to.
		internalRequestTime(resolvedIp);
		break;
	case ERR_INPROGRESS:
		// currently finding ip, internalRequestTime() will be called when its found.
		//debugf("DNS IP lookup in progress.");
		break;
	default:
		debugf("DNS lookup error occurred.");
		break;
	}
}
开发者ID:BorntraegerMarc,项目名称:Sming,代码行数:32,代码来源:NtpClient.cpp

示例7: on_timer

/******************************************************************************
 * FunctionName : on_timer
 * Description  : 1s time callback to check dns found
 * Parameters   : arg -- Additional argument to pass to the callback function
 * Returns      : none
*******************************************************************************/
static void ICACHE_FLASH_ATTR
on_timer(void *arg)
{
    int err = -1;
    struct user_dns_param *param = (struct user_dns_param *)arg;

    switch(param->ip.addr)
    {
        case 0xFFFFFFFF:
        case 0x00000000:
            if(0 < param->retry--)
            {
                DEBUG_WARNING("retry\n");
                err = dns_gethostbyname(param->hostname, &param->ip, on_found, param);
                os_timer_arm(&param->tmr, 1000, 0);
                return;
            }
            else
            {
                err = ETIMEDOUT;
            }
            break;
        default:
            DEBUG_INFO("callback\n");
            err = 0;
            break;
    }

    param->h(err, &param->ip, param);
}
开发者ID:taiyuanfang,项目名称:Espressif,代码行数:36,代码来源:user_dns.c

示例8: initialize

bool TcpConnection::connect(String server, int port)
{
	if (tcp == NULL)
		initialize(tcp_new());

	ip_addr_t addr;

	debugf("connect to: %s", server.c_str());
	canSend = false; // Wait for connection
	DnsLookup *look = new DnsLookup { this, port };
	err_t dnslook = dns_gethostbyname(server.c_str(), &addr, staticDnsResponse, look);
	if (dnslook != ERR_OK)
	{
		if (dnslook == ERR_INPROGRESS)
			return true;
		else
		{
			delete look;
			return false;
		}
	}
	delete look;

	return internalTcpConnect(addr, port);
}
开发者ID:BorntraegerMarc,项目名称:SmingRTOS,代码行数:25,代码来源:TcpConnection.cpp

示例9: DEBUG_WIFI_GENERIC

/**
 * 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

示例10: switch

//Execute request & return OK if found, NOTFOUND or ERROR on error, or PROCESSING if the request has not completed yet
void LwipNetDnsRequest::poll()
{
  err_t  err;
  switch(m_state)
  {
  case LWIPNETDNS_START: //First req, let's call dns_gethostbyname
    ip_addr_t ipStruct;
    err = dns_gethostbyname(m_hostname, &ipStruct, LwipNetDnsRequest::sFoundCb, (void*) this );
    if( err == ERR_OK )
    {
      m_ip = IpAddr(&ipStruct);
      m_state = LWIPNETDNS_OK;
      DBG("DNS: Ip found in cache.\n");
    }
    else if( err == ERR_INPROGRESS)
    {
      DBG("DNS: Processing.\n");
      m_state = LWIPNETDNS_PROCESSING;
    }
    else //Likely ERR_VAL
    {
      DBG("DNS: Error on init.\n");
      m_state = LWIPNETDNS_ERROR;
    }
    break;
  case LWIPNETDNS_PROCESSING:
    break; //Nothing to do, DNS is polled on interrupt
  case LWIPNETDNS_OK:
    if(!m_cbFired)
    {
      DBG("DNS: Ip found.\n");
      m_cbFired = true;
      onReply(NETDNS_FOUND); //Raise callback
    }
    break;
  case LWIPNETDNS_NOTFOUND:
    if(!m_cbFired)
    {
      DBG("DNS: could not be resolved.\n");
      m_cbFired = true;
      onReply(NETDNS_NOTFOUND); //Raise callback
    }
    break;
  case LWIPNETDNS_ERROR:
  default:
    if(!m_cbFired)
    {
      DBG("DNS: Error.\n");
      m_cbFired = true;
      onReply(NETDNS_ERROR); //Raise callback
    }
    break;
  }
  if(m_closing && (m_state!=LWIPNETDNS_PROCESSING)) //Check wether the closure has been reqd
  {
    DBG("LwipNetDnsRequest: Closing in poll()\n");
    NetDnsRequest::close();
  }
}
开发者ID:intervigilium,项目名称:csm213a-embedded,代码行数:60,代码来源:lwipNetDnsRequest.cpp

示例11: dns_suite

void
dns_suite(void)
{
    evdns_init();
    dns_gethostbyname();
    dns_gethostbyaddr();

    evdns_shutdown(0);
}
开发者ID:flaithbheartaigh,项目名称:jaikuengine-mobile-frontend,代码行数:9,代码来源:regress_dns.c

示例12: sntp_thread

/**
 * SNTP thread
 */
static void sntp_thread(void *arg) {
	LWIP_UNUSED_ARG(arg);
	while (1) {
		dns_gethostbyname(SNTP_SERVER_NAME, &SNTPaddr, sntp_server_found, NULL);
		vTaskSuspend(NULL);
		sntp_request();
		sys_msleep(SNTP_UPDATE_DELAY);
	}
}
开发者ID:hitubaldaniya,项目名称:lumweb,代码行数:12,代码来源:sntp.c

示例13: tls_socket_connect

static int tls_socket_connect( lua_State *L ) {
  tls_socket_ud *ud = (tls_socket_ud *)luaL_checkudata(L, 1, "tls.socket");
  luaL_argcheck(L, ud, 1, "TLS socket expected");
  if(ud==NULL){
  	NODE_DBG("userdata is nil.\n");
  	return 0;
  }

  if (ud->pesp_conn) {
    return luaL_error(L, "already connected");
  }

  u16 port = luaL_checkinteger( L, 2 );
  size_t il;
  const char *domain = "127.0.0.1";
  if( lua_isstring(L, 3) )
    domain = luaL_checklstring( L, 3, &il );
  if (port == 0)
    return luaL_error(L, "invalid port");
  if (domain == NULL)
    return luaL_error(L, "invalid domain");

  ud->pesp_conn = (struct espconn*)c_zalloc(sizeof(struct espconn));
  if(!ud->pesp_conn)
    return luaL_error(L, "not enough memory");
  ud->pesp_conn->proto.udp = NULL;
  ud->pesp_conn->proto.tcp = (esp_tcp *)c_zalloc(sizeof(esp_tcp));
  if(!ud->pesp_conn->proto.tcp){
    c_free(ud->pesp_conn);
    ud->pesp_conn = NULL;
    return luaL_error(L, "not enough memory");
  }
  ud->pesp_conn->type = ESPCONN_TCP;
  ud->pesp_conn->state = ESPCONN_NONE;
  ud->pesp_conn->reverse = ud;
  ud->pesp_conn->proto.tcp->remote_port = port;
  espconn_regist_connectcb(ud->pesp_conn, (espconn_connect_callback)tls_socket_onconnect);
  espconn_regist_disconcb(ud->pesp_conn, (espconn_connect_callback)tls_socket_ondisconnect);
  espconn_regist_reconcb(ud->pesp_conn, (espconn_reconnect_callback)tls_socket_onreconnect);
  espconn_regist_recvcb(ud->pesp_conn, (espconn_recv_callback)tls_socket_onrecv);
  espconn_regist_sentcb(ud->pesp_conn, (espconn_sent_callback)tls_socket_onsent);

  if (ud->self_ref == LUA_NOREF) {
    lua_pushvalue(L, 1);  // copy to the top of stack
    ud->self_ref = luaL_ref(L, LUA_REGISTRYINDEX);
  }

  ip_addr_t addr;
  err_t err = dns_gethostbyname(domain, &addr, (dns_found_callback)tls_socket_dns_cb, ud);
  if (err == ERR_OK) {
    tls_socket_dns_cb(domain, &addr, ud);
  } else if (err != ERR_INPROGRESS) {
    tls_socket_dns_cb(domain, NULL, ud);
  }

  return 0;
}
开发者ID:FelixPe,项目名称:nodemcu-firmware,代码行数:57,代码来源:tls.c

示例14: set_clock_sntp

void set_clock_sntp(const char * ntp_server, int i)
{
	strcpy(dns_hostname, ntp_server);

	//To get the ball rolling, all we have to do is send a request to get the NTP server's IP address.
	dns_gethostbyname(dns_hostname, &ntp_server_ip, send_ntp_req, NULL);

	//...oh, and save the system GMT offset for later.
	gmt_offset = i;
}
开发者ID:NBitWonder,项目名称:VoIP32,代码行数:10,代码来源:sntp.c

示例15: dns_dorequest

void dns_dorequest(void *arg)
{
  char* dnsname = "3com.com";
  ip_addr_t dnsresp;
  LWIP_UNUSED_ARG(arg);
 
  if (dns_gethostbyname(dnsname, &dnsresp, dns_found, 0) == ERR_OK) {
    dns_found(dnsname, &dnsresp, 0);
  }
}
开发者ID:killvxk,项目名称:lwip-allnetworks,代码行数:10,代码来源:test.c


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