Exemple #1
0
uint8_t
twitter_send(char *status)
{
  /* Transmission taking action */
  if (twitter_tmp_buf) return 0;

  uint8_t len = strlen(status);
  if (len > 140) {
    TWDEBUG("message too long: cropping");
    len = 140;
  }

  twitter_tmp_buf = malloc(140);
  if (!twitter_tmp_buf) return 0;

  memcpy(twitter_tmp_buf, status, len);
  twitter_tmp_buf[len] = 0;

  uip_ipaddr_t *ipaddr;
  if (!(ipaddr = resolv_lookup(CONF_TWITTER_SERVICE))) {
    resolv_query(CONF_TWITTER_SERVICE, twitter_dns_query_cb);
  } else {
    twitter_dns_query_cb(NULL, ipaddr);
  }
  return 1;
}
Exemple #2
0
uint8_t
sms77_send(char *status)
{
  /* Transmission taking action */
  if (sms77_tmp_buf) return 0;

  uint8_t len = strlen(status);
  if (len > 160) {
    SMSDEBUG("message too long: cropping");
    len = 160;
  }

  sms77_tmp_buf = malloc(160);
  if (!sms77_tmp_buf) return 0;

  memcpy(sms77_tmp_buf, status, len);
  sms77_tmp_buf[len] = 0;

  uip_ipaddr_t *ipaddr;
  if (!(ipaddr = resolv_lookup(CONF_SMS77_SERVICE))) {
    resolv_query(CONF_SMS77_SERVICE, sms77_dns_query_cb);
  } else {
    sms77_dns_query_cb(NULL, ipaddr);
  }
  return 1;
}
Exemple #3
0
void appSendConnect(void)
{
    u16_t ipaddr[2];
    u16_t * ipPt;

    if(memoryData.dns == 0)
    {
       //Envia comando de conexão para endereço do servidor guardado
       uip_ipaddr(ipaddr, memoryData.ipServidor[0],memoryData.ipServidor[1],memoryData.ipServidor[2],memoryData.ipServidor[3]);
       uip_connect(ipaddr, HTONS(memoryData.porta));
       appEnableTCP();
    }
    else
    {
        //Requisita o endereço do servidor pelo dns
        ipPt = resolv_lookup((char *)memoryData.webAddr);
        if(ipPt == NULL)
        {
            resolv_conf(dnsAddr);
            resolv_query((char *)memoryData.webAddr);
        }
        else
        {
            uip_connect(ipPt, HTONS(memoryData.porta));
            appEnableTCP();
        }
    }
}
Exemple #4
0
int16_t parse_cmd_ntp_server(char *cmd, char *output, uint16_t len)
{
    uip_ipaddr_t ntpaddr;

    while (*cmd == ' ')
	cmd++;

    if (*cmd != '\0') {
	/* try to parse ip */
	if (parse_ip(cmd, &ntpaddr) != 0) {
#ifdef DNS_SUPPORT
	    uip_ipaddr_t *ip;

	    if (!(ip = resolv_lookup(cmd)))
		resolv_query(cmd, ntp_dns_query_cb);
	    else
		ntp_conf(ip);
#else
	    return ECMD_ERR_PARSE_ERROR;
#endif
	}
	else
	    ntp_conf(&ntpaddr);

	return ECMD_FINAL_OK;
    }
    else {
	return ECMD_FINAL(print_ipaddr(ntp_getserver(), output, len));
    }
}
Exemple #5
0
/*****************************************************************************
 函 数 名  : uip_app_init
 功能描述  : the uip appliacation function
 输入参数  : void  
 输出参数  : 无
 返 回 值  : 
 调用函数  : 
 被调函数  : 
 
 修改历史      :
  1.日    期   : 2017年4月17日
    作    者   : QSWWD
    修改内容   : 新生成函数

*****************************************************************************/
void uip_app_init(void)
{
	uip_ipaddr_t ipaddr;
	uip_ipaddr(ipaddr, 8,8,8,8);
	
	/*	hello_world_init();*/
	

	
	/*
	  resolv_init();
	  uip_ipaddr(ipaddr, 195,54,122,204);
	  resolv_conf(ipaddr);
	  resolv_query("www.sics.se");*/

	example1_init();
	example2_init();
	telnetd_init();
	smtp_init();
	uip_ipaddr(ipaddr, 127,0,0,1);
	smtp_configure("localhost", ipaddr);
	SMTP_SEND("*****@*****.**", NULL, "*****@*****.**",
		  "Testing SMTP from uIP",
		  "Test message sent by uIP\r\n");	
	hello_world_init();
	httpd_init();
	
#if UIP_UDP
	my_udp8899_init();
	dhcpc_init(&uip_ethaddr,6);
	resolv_init();
    resolv_conf(ipaddr);
    resolv_query("www.baidu.com");	
#endif
}
Exemple #6
0
uint8_t
httplog(char status[140] )
{
  /* Transmission taking action */
  if (httplog_tmp_buf) return 0;

  uint8_t len = strlen(status);
  if (len > 140) {
    HTTPLOG_DEBUG("message too long: cropping");
    len = 140;
  }

  httplog_tmp_buf = malloc(140);
  if (!httplog_tmp_buf) return 0;

  memcpy(httplog_tmp_buf, status, len);
  httplog_tmp_buf[len] = 0;

  uip_ipaddr_t *ipaddr;
  if (!(ipaddr = resolv_lookup(CONF_HTTPLOG_SERVICE))) {
    resolv_query(CONF_HTTPLOG_SERVICE, httplog_dns_query_cb);
  } else {
    httplog_dns_query_cb(NULL, ipaddr);
  }
  return 1;
}
Exemple #7
0
// Hostname lookup (resolver)
elua_net_ip elua_net_lookup( const char* hostname )
{
  elua_net_ip res;
  
  res.ipaddr = 0; 
#ifdef BUILD_DNS
  u16_t *data;
  
  if( ( data = resolv_lookup( ( char* )hostname ) ) != NULL )
  {
    // Name already saved locally
    res.ipwords[ 0 ] = data[ 0 ];
    res.ipwords[ 1 ] = data[ 1 ];
  }
  else
  {
    // Name not saved locally, must make request
    elua_resolv_req_done = 0;
    resolv_query( ( char* )hostname );
    platform_eth_force_interrupt();
    while( elua_resolv_req_done == 0 );
    res = elua_resolv_ip;
  }
#endif
  return res;  
}
void fs20_sendmessage(void) // Send fs20/fht command from queue to tcp port
{
	fs20_sendstate = 1; // set new state in progress

	uip_ipaddr_t ipaddr;
	FS20S_DEBUG ("connecting %s\n", CONF_FS20_SERVICE);

	if (parse_ip(CONF_FS20_SERVICE, &ipaddr) == -1)
	{
		uip_ipaddr_t *ripaddr;
		// Try to find IPAddress
		if (!(ripaddr = resolv_lookup(CONF_FS20_SERVICE)))
		{
			resolv_query(CONF_FS20_SERVICE, fs20_dns_query_cb); // If not found: query DNS
		}
		else
		{
			fs20_dns_query_cb(NULL, ripaddr); // If found use IPAddress
		}
	}
	else
	{
		FS20S_DEBUG ("ip %s\n", CONF_FS20_SERVICE);
		fs20_dns_query_cb(NULL, &ipaddr);
	}

	return;
}
Exemple #9
0
/*-----------------------------------------------------------------------------------*/
void
webclient_appcall(void)
{
  if(uip_connected()) {
    s.timer = 0;
    s.state = WEBCLIENT_STATE_STATUSLINE;
    senddata();
    webclient_connected();
    return;
  }

  if(s.state == WEBCLIENT_STATE_CLOSE) {
    webclient_closed();
    uip_abort();
    return;
  }

  if(uip_aborted()) {
    webclient_aborted();
  }
  if(uip_timedout()) {
    webclient_timedout();
  }

  
  if(uip_acked()) {
    s.timer = 0;
    acked();
  }
  if(uip_newdata()) {
    s.timer = 0;
    newdata();
  }
  if(uip_rexmit() ||
     uip_newdata() ||
     uip_acked()) {
    senddata();
  } else if(uip_poll()) {
    ++s.timer;
    if(s.timer == WEBCLIENT_TIMEOUT) {
      webclient_timedout();
      uip_abort();
      return;
    }
        /*    senddata();*/
  }

  if(uip_closed()) {
    if(s.httpflag != HTTPFLAG_MOVED) {
      /* Send NULL data to signal EOF. */
      webclient_datahandler(NULL, 0);
    } else {
      if(resolv_lookup(s.host) == NULL) {
	resolv_query(s.host);
      }
      webclient_get(s.host, s.port, s.file);
    }
  }
}
Exemple #10
0
/*---------------------------------------------------------------------------*/
static resolv_status_t
set_connection_address(uip_ipaddr_t *ipaddr, int *port)
{
#ifndef UDP_CONNECTION_ADDR
#if RESOLV_CONF_SUPPORTS_MDNS && RESOLV_CONF_SUPPORTS_DNS_SD
#define UDP_CONNECTION_ADDR       _server._udp.local
#elif RESOLV_CONF_SUPPORTS_MDNS
#define UDP_CONNECTION_ADDR       cus.local
#elif UIP_CONF_ROUTER
#define UDP_CONNECTION_ADDR       fd00:0:0:0:0212:7404:0004:0404
#else
#define UDP_CONNECTION_ADDR       fe80:0:0:0:6466:6666:6666:6666
#endif
#endif /* !UDP_CONNECTION_ADDR */

#define _QUOTEME(x) #x
#define QUOTEME(x) _QUOTEME(x)

  resolv_status_t status = RESOLV_STATUS_ERROR;

  if(uiplib_ipaddrconv(QUOTEME(UDP_CONNECTION_ADDR), ipaddr) == 0) {
    /*
     * We are looking for a hostname and not an IP address.
     */
    uip_ipaddr_t *resolved_addr = NULL;
#if RESOLV_CONF_SUPPORTS_MDNS && RESOLV_CONF_SUPPORTS_DNS_SD
    status = resolv_service_lookup(QUOTEME(UDP_CONNECTION_ADDR),&resolved_addr,port);
#else
    status = resolv_lookup(QUOTEME(UDP_CONNECTION_ADDR),&resolved_addr);
#endif /* RESOLV_CONF_SUPPORTS_MDNS && RESOLV_CONF_SUPPORTS_DNS_SD */
    if(status == RESOLV_STATUS_UNCACHED || status == RESOLV_STATUS_EXPIRED) {
      PRINTF("Attempting to look up %s\n",QUOTEME(UDP_CONNECTION_ADDR));
#if RESOLV_CONF_SUPPORTS_MDNS && RESOLV_CONF_SUPPORTS_DNS_SD
      resolv_query_service(QUOTEME(UDP_CONNECTION_ADDR));
#else
      resolv_query(QUOTEME(UDP_CONNECTION_ADDR));
#endif /* RESOLV_CONF_SUPPORTS_MDNS && RESOLV_CONF_SUPPORTS_DNS_SD */
      status = RESOLV_STATUS_RESOLVING;
    } else if(status == RESOLV_STATUS_CACHED && resolved_addr != NULL
#if RESOLV_CONF_SUPPORTS_MDNS && RESOLV_CONF_SUPPORTS_DNS_SD
              && port != NULL
#endif /* RESOLV_CONF_SUPPORTS_MDNS && RESOLV_CONF_SUPPORTS_DNS_SD */
    ) {
      PRINTF("Lookup of \"%s\" succeded!\n",QUOTEME(UDP_CONNECTION_ADDR));
    } else if(status == RESOLV_STATUS_RESOLVING) {
      PRINTF("Still looking up \"%s\"...\n",QUOTEME(UDP_CONNECTION_ADDR));
    } else {
      PRINTF("Lookup of \"%s\" failed. status = %d\n",QUOTEME(UDP_CONNECTION_ADDR),status);
    }
    if(resolved_addr)
      uip_ipaddr_copy(ipaddr, resolved_addr);
  } else {
    status = RESOLV_STATUS_CACHED;
  }

  return status;
}
Exemple #11
0
void
dhcpc_configured(const struct dhcpc_state *s)
{
  uip_sethostaddr(s->ipaddr);
  uip_setnetmask(s->netmask);
  uip_setdraddr(s->default_router);
#if CFG_SUPPORT_DNS
  resolv_conf(s->dnsaddr);
  resolv_query("www.ablecloud.cn");
#endif
}
layer_state_t contiki_io_layer_connect(
	layer_connectivity_t* context
	, const void* data
	, const layer_hint_t hint )
{

 	XI_UNUSED( hint );

	uip_ipaddr_t *ip;
	resolv_status_t dns_status;
    xi_connection_data_t* connection_data;
    layer_t* layer = ( layer_t* ) context->self;
    contiki_data_t* s = (contiki_data_t* ) layer->user_data;
    struct uip_conn *c;

    s->process = PROCESS_CURRENT();
    if (s->state == CONNECTED) {
    	xi_debug_logger( "Connecting to the endpoint [ok]" );
    	return LAYER_STATE_OK;
    } else if (s->state == CONNECTING) {
    	return LAYER_STATE_WANT_WRITE;
    } else if (s->state == CLOSED) {
	    connection_data   = ( xi_connection_data_t* ) data;
	    dns_status = resolv_lookup(connection_data->address, &ip);

	    if (dns_status != RESOLV_STATUS_CACHED) {
	    	if (dns_status ==  RESOLV_STATUS_NOT_FOUND || dns_status == RESOLV_STATUS_ERROR) {
	    		xi_debug_logger( "Getting Host by name [failed]" );
	        	xi_set_err( XI_SOCKET_GETHOSTBYNAME_ERROR );
	        	return LAYER_STATE_ERROR;
	    	}
	    	if (dns_status != RESOLV_STATUS_RESOLVING) {
	    		resolv_query(connection_data->address);
	    	}
	    	return LAYER_STATE_WANT_WRITE;	/* no IP, cannot go further */
	   	}
	   	xi_debug_logger( "Getting Host by name [ok]" );
	    xi_debug_logger( "Connecting to the endpoint..." );

	    c = uip_connect(ip, uip_htons(connection_data->port));
	 	if(c == NULL) {
	        xi_debug_logger( "Connecting to the endpoint [failed]" );
	        xi_set_err( XI_SOCKET_CONNECTION_ERROR );
	        return LAYER_STATE_ERROR;
	    }
	    s->state = CONNECTING;
	    c->appstate.p = &xively_process;
	    c->appstate.state = s;
	    tcpip_poll_tcp(c);
		return LAYER_STATE_WANT_WRITE;
	}

	return LAYER_STATE_ERROR;
}
Exemple #13
0
int
_tcpip_init(void)
{
  uip_ipaddr_t ipaddr;

  timer_set(&periodic_timer, CLOCK_SECOND/2);
  timer_set(&arp_timer, CLOCK_SECOND * 10);
  timer_set(&cli_timer, CLOCK_SECOND);
  
  mt76xx_dev_init();
  uip_init();

  //Printf_High("Tcp INIT \n");
#ifdef CONFIG_SOFTAP
	uip_ipaddr(ipaddr, 192,168,81,1);
	uip_sethostaddr(ipaddr);
	uip_ipaddr(ipaddr, 192,168,81,1);
	uip_setdraddr(ipaddr);
	uip_ipaddr(ipaddr, 255,255,255,0);
	uip_setnetmask(ipaddr);
//	Printf_High("TcpIP IniT===\n");
	uip_gethostaddr(ipaddr); 
#endif
 
  iot_udp_app_init();
  iot_tcp_app_init();

#ifndef CONFIG_SOFTAP
  if (IoTpAd.ComCfg.Use_DHCP!=1) {
	uip_ipaddr(ipaddr, IoTpAd.ComCfg.STATIC_IP[0],IoTpAd.ComCfg.STATIC_IP[1],
				IoTpAd.ComCfg.STATIC_IP[2],IoTpAd.ComCfg.STATIC_IP[3]);
	uip_sethostaddr(ipaddr);

	uip_ipaddr(ipaddr,IoTpAd.ComCfg.SubnetMask_IP[0], IoTpAd.ComCfg.SubnetMask_IP[1], 
				IoTpAd.ComCfg.SubnetMask_IP[2], IoTpAd.ComCfg.SubnetMask_IP[3]);
	uip_setnetmask(ipaddr);

	uip_ipaddr(ipaddr, IoTpAd.ComCfg.GateWay_IP[0], IoTpAd.ComCfg.GateWay_IP[1], 
				IoTpAd.ComCfg.GateWay_IP[2], IoTpAd.ComCfg.GateWay_IP[3]);
	uip_setdraddr(ipaddr);

#if CFG_SUPPORT_DNS
	uip_ipaddr(ipaddr, IoTpAd.ComCfg.DNS_IP[0],IoTpAd.ComCfg.DNS_IP[1],
				IoTpAd.ComCfg.DNS_IP[2],IoTpAd.ComCfg.DNS_IP[3]);
	resolv_conf(ipaddr);
	resolv_query("www.ablecloud.cn");
#endif
	dhcpc_set_state(STATE_CONFIG_DONE);
  }
#endif
  cli_fd = -1;
  return 0;
} 
Exemple #14
0
static void
httplog_resolve_address(void)
{
  uip_ipaddr_t *ipaddr;
  if (!(ipaddr = resolv_lookup(CONF_HTTPLOG_SERVICE)))
  {
    resolv_query(CONF_HTTPLOG_SERVICE, httplog_dns_query_cb);
  }
  else
  {
    httplog_dns_query_cb(NULL, ipaddr);
  }
}
Exemple #15
0
int16_t parse_cmd_nslookup (char *cmd, char *output, uint16_t len)
{
  while (*cmd == 32) cmd ++;
  uip_ipaddr_t *addr = resolv_lookup (cmd);

  if (addr) {
    return ECMD_FINAL(print_ipaddr(addr, output, len));
  }
  else {
    resolv_query (cmd, NULL);
    return ECMD_FINAL(snprintf_P(output, len, PSTR("nslookup triggered, try again for result.")));
  }
}
int
_tcpip_init(void)
{
    uip_ipaddr_t ipaddr;

    timer_set(&periodic_timer, CLOCK_SECOND/2);
    timer_set(&arp_timer, CLOCK_SECOND * 10);
    timer_set(&cli_timer, CLOCK_SECOND);

    mt76xx_dev_init();
    uip_init();

#ifdef CONFIG_SOFTAP
    uip_ipaddr(ipaddr, UIP_IPADDR0,UIP_IPADDR1,UIP_IPADDR2,UIP_IPADDR3);
    uip_sethostaddr(ipaddr);
    uip_ipaddr(ipaddr, UIP_IPADDR0,UIP_IPADDR1,UIP_IPADDR2,UIP_IPADDR3);
    uip_setdraddr(ipaddr);
    uip_ipaddr(ipaddr, UIP_NETMASK0,UIP_NETMASK1,UIP_NETMASK2,UIP_NETMASK3);
    uip_setnetmask(ipaddr);
    uip_gethostaddr(ipaddr);
#endif

    iot_udp_app_init();
    iot_tcp_app_init();

#ifdef CONFIG_STATION
    if (IoTpAd.ComCfg.Use_DHCP!=1) {
        uip_ipaddr(ipaddr, IoTpAd.ComCfg.STATIC_IP[0],IoTpAd.ComCfg.STATIC_IP[1],
                   IoTpAd.ComCfg.STATIC_IP[2],IoTpAd.ComCfg.STATIC_IP[3]);
        uip_sethostaddr(ipaddr);

        uip_ipaddr(ipaddr,IoTpAd.ComCfg.SubnetMask_IP[0], IoTpAd.ComCfg.SubnetMask_IP[1],
                   IoTpAd.ComCfg.SubnetMask_IP[2], IoTpAd.ComCfg.SubnetMask_IP[3]);
        uip_setnetmask(ipaddr);

        uip_ipaddr(ipaddr, IoTpAd.ComCfg.GateWay_IP[0], IoTpAd.ComCfg.GateWay_IP[1],
                   IoTpAd.ComCfg.GateWay_IP[2], IoTpAd.ComCfg.GateWay_IP[3]);
        uip_setdraddr(ipaddr);

#if CFG_SUPPORT_DNS
        uip_ipaddr(ipaddr, IoTpAd.ComCfg.DNS_IP[0],IoTpAd.ComCfg.DNS_IP[1],
                   IoTpAd.ComCfg.DNS_IP[2],IoTpAd.ComCfg.DNS_IP[3]);
        resolv_conf(ipaddr);
        resolv_query("www.baidu.com");
#endif
        dhcpc_set_state(STATE_CONFIG_DONE);
    }
#endif
    cli_fd = -1;
    return 0;
}
Exemple #17
0
/*---------------------------------------------------------------------------*/
static int
start_request(struct http_socket *s)
{
  uip_ip4addr_t ip4addr;
  uip_ip6addr_t ip6addr;
  uip_ip6addr_t *addr;
  char host[MAX_HOSTLEN];
  char path[MAX_PATHLEN];
  uint16_t port;
  int ret;

  if(parse_url(s->url, host, &port, path)) {

    printf("url %s host %s port %d path %s\n",
           s->url, host, port, path);

    /* Check if we are to route the request through a proxy. */
    if(s->proxy_port != 0) {
      /* The proxy address should be an IPv6 address. */
      uip_ip6addr_copy(&ip6addr, &s->proxy_addr);
      port = s->proxy_port;
    } else if(uiplib_ip6addrconv(host, &ip6addr) == 0) {
      /* First check if the host is an IP address. */
      if(uiplib_ip4addrconv(host, &ip4addr) != 0) {
        ip64_addr_4to6(&ip4addr, &ip6addr);
      } else {
        /* Try to lookup the hostname. If it fails, we initiate a hostname
           lookup. */
        ret = resolv_lookup(host, &addr);
        if(ret == RESOLV_STATUS_UNCACHED ||
           ret == RESOLV_STATUS_EXPIRED) {
          resolv_query(host);
          puts("Resolving host...");
          return HTTP_SOCKET_OK;
        }
        if(addr != NULL) {
          s->did_tcp_connect = 1;
          tcp_socket_connect(&s->s, addr, port);
          return HTTP_SOCKET_OK;
        } else {
          return HTTP_SOCKET_ERR;
        }
      }
    }
    tcp_socket_connect(&s->s, &ip6addr, port);
    return HTTP_SOCKET_OK;
  } else {
    return HTTP_SOCKET_ERR;
  }
}
/******************************************************************************
* void exosite_appcall(void)
*
* This function is uIP's application function.  It is called whenever a uIP 
* event occurs (e.g. when a new connection is established, new data arrives, 
* sent data is acknowledged, data needs to be retransmitted, etc.).
* 
******************************************************************************/ 
void exosite_appcall(void)
{
  if(uip_connected()) {
    s.timer = 0;
    senddata();
    return;
  }

  if(s.state == EXO_STATE_CLOSE) {
    uip_abort();
    return;
  }
  
  if(uip_aborted()) {
  }
  if(uip_timedout()) {
  }

  if(uip_acked()) {
    s.timer = 0;
    acked();
  }

  if(uip_newdata()) {
    s.timer = 0;
    newdata();
  }
 
  if(uip_rexmit() || uip_newdata() || uip_acked()) {
    senddata();
  } else if(uip_poll()) {
    ++s.timer;
    if(s.timer == EXO_TIMEOUT) {
      uip_abort();
      return;
    }
  }
#if 0  
  if(uip_closed()) {
    if(s.httpflag != HTTPFLAG_MOVED) {
      memset(s.rxdata,0,sizeof(s.rxdata));
    } else {
      if(resolv_lookup(s.host) == NULL) {
	      resolv_query(s.host);
      }
    }
  }
#endif

}
Exemple #19
0
    int
twitter_resolve(cb_resolve_status_t cb_resolve_status, struct process *parent)
{
    state.cb_resolve_status = cb_resolve_status;
    state.parent = parent;

#if UIP_UDP
    resolv_query(DEFAULT_HOST);
    process_start(&twitter_resolve_process, NULL);
    return 1;
#else /* UIP_UDP */
    uip_ipaddr(ip_address, DEFAULT_IP[0], DEFAULT_IP[1], DEFAULT_IP[2], DEFAULT_IP[3]);
    return 0;
#endif /* UIP_UDP */
}
Exemple #20
0
void
ntp_init()
{
#ifdef DNS_SUPPORT
  uip_ipaddr_t *ipaddr;
  if (!(ipaddr = resolv_lookup(NTP_SERVER)))
    resolv_query(NTP_SERVER, ntp_dns_query_cb);
  else
    ntp_conf(ipaddr);

#else /* ! DNS_SUPPORT */
  uip_ipaddr_t ip;
  set_NTP_SERVER_IP(&ip);

  ntp_conf(&ip);
#endif
}
Exemple #21
0
/*-----------------------------------------------------------------------------------*/
static void
connect(void)
{
  uip_ipaddr_t addr, *addrptr;
  uint16_t port;
  char *cptr;
  struct uip_conn *conn;

  /* Find the first space character in host and put a zero there
     to end the string. */
  for(cptr = telnethost; *cptr != ' ' && *cptr != 0; ++cptr);
  *cptr = 0;

  addrptr = &addr;
#if UIP_UDP
  if(uiplib_ipaddrconv(telnethost, &addr) == 0) {
    addrptr = resolv_lookup(telnethost);
    if(addrptr == NULL) {
      resolv_query(telnethost);
      show("Resolving host...");
      return;
    }
  }
#else /* UIP_UDP */
  uiplib_ipaddrconv(telnethost, &addr);
#endif /* UIP_UDP */

  port = 0;
  for(cptr = telnetport; *cptr != ' ' && *cptr != 0; ++cptr) {
    if(*cptr < '0' || *cptr > '9') {
      show("Port number error");
      return;
    }
    port = 10 * port + *cptr - '0';
  }


  conn = tcp_connect(addrptr, uip_htons(port), &ts_appstate);
  if(conn == NULL) {
    show("Out of memory error");
    return;
  }

  show("Connecting...");

}
Exemple #22
0
void
ntp_init()
{
#ifdef DNS_SUPPORT
  ntp_tries = 0; // reset try counter
  uip_ipaddr_t *ipaddr;
  if (ntp_conn != NULL || !(ipaddr = resolv_lookup(NTP_SERVER)))
    resolv_query(NTP_SERVER, ntp_dns_query_cb);
  else
    ntp_conf(ipaddr);

#else /* ! DNS_SUPPORT */
  uip_ipaddr_t ip;
  set_NTP_SERVER_IP(&ip);

  ntp_conf(&ip);
#endif
}
Exemple #23
0
void
ntp_init()
{
#ifdef DNS_SUPPORT
  uip_ipaddr_t *ipaddr;
  if (!(ipaddr = resolv_lookup(NTP_SERVER)))
    resolv_query(NTP_SERVER, ntp_dns_query_cb);
  else
    ntp_conf(ipaddr);

#else /* ! DNS_SUPPORT */
  uip_ipaddr_t ip;
  //  set_NTP_SERVER_IP(&ip);
  eeprom_restore(ntp_server, &ip, IPADDR_LEN);

  ntp_conf(&ip);
#endif
}
Exemple #24
0
/*---------------------------------------------------------------------------*/
static resolv_status_t
set_connection_address(uip_ipaddr_t *ipaddr)
{
#ifndef UDP_CONNECTION_ADDR
//#if RESOLV_CONF_SUPPORTS_MDNS
#if 0
#define UDP_CONNECTION_ADDR       contiki-udp-server.local
#elif UIP_CONF_ROUTER
#define UDP_CONNECTION_ADDR       aaaa:0:0:0:0201:2dcf:4629:04b4
#else
#define UDP_CONNECTION_ADDR       fe80:0:0:0:6466:6666:6666:6666
#endif
#endif /* !UDP_CONNECTION_ADDR */



#define _QUOTEME(x) #x
#define QUOTEME(x) _QUOTEME(x)

  resolv_status_t status = RESOLV_STATUS_ERROR;

  if(uiplib_ipaddrconv(QUOTEME(UDP_CONNECTION_ADDR), ipaddr) == 0) {
    uip_ipaddr_t *resolved_addr = NULL;
    status = resolv_lookup(QUOTEME(UDP_CONNECTION_ADDR),&resolved_addr);
    if(status == RESOLV_STATUS_UNCACHED || status == RESOLV_STATUS_EXPIRED) {
      PRINTF("Attempting to look up %s\n",QUOTEME(UDP_CONNECTION_ADDR));
      resolv_query(QUOTEME(UDP_CONNECTION_ADDR));
      status = RESOLV_STATUS_RESOLVING;
    } else if(status == RESOLV_STATUS_CACHED && resolved_addr != NULL) {
      PRINTF("Lookup of \"%s\" succeded!\n",QUOTEME(UDP_CONNECTION_ADDR));
    } else if(status == RESOLV_STATUS_RESOLVING) {
      PRINTF("Still looking up \"%s\"...\n",QUOTEME(UDP_CONNECTION_ADDR));
    } else {
      PRINTF("Lookup of \"%s\" failed. status = %d\n",QUOTEME(UDP_CONNECTION_ADDR),status);
    }
    if(resolved_addr)
      uip_ipaddr_copy(ipaddr, resolved_addr);
  } else {
    status = RESOLV_STATUS_CACHED;
  }

  return status;
}
Exemple #25
0
void mqtt_tcp_connect(char *addr, int port)
{
	uip_ip4addr_t remote_ip_addr;
	
	if(uiplib_ipaddrconv(addr, &remote_ip_addr) == 0)
	{
		resolv_query(addr);
		return;
	}
	else
	{
		g_mqtt_socket_para.connect_status = SOCKET_CREATE;
		g_mqtt_socket_para.fd = tcpconnect(&remote_ip_addr, port, &mqtt_socket_process);

		printf("Tcp socket(%d) connectting to [%d.%d.%d.%d:%d]\n", g_mqtt_socket_para.fd, 
		remote_ip_addr.u8[0], remote_ip_addr.u8[1], remote_ip_addr.u8[2], remote_ip_addr.u8[3], port);
	}
		
}
Exemple #26
0
smcp_status_t
smcp_plat_lookup_hostname(const char* hostname, smcp_sockaddr_t* saddr)
{
	smcp_status_t ret;
	memset(saddr, 0, sizeof(*saddr));

	ret = uiplib_ipaddrconv(
		hostname,
		&saddr->smcp_addr
	) ? SMCP_STATUS_OK : SMCP_STATUS_HOST_LOOKUP_FAILURE;

#if SMCP_CONF_USE_DNS
#if CONTIKI
	if(ret) {
		SMCP_NON_RECURSIVE uip_ipaddr_t *temp = NULL;
		switch(resolv_lookup(hostname,&temp)) {
			case RESOLV_STATUS_CACHED:
				memcpy(&saddr->smcp_addr, temp, sizeof(uip_ipaddr_t));
				ret = SMCP_STATUS_OK;
				break;
			case RESOLV_STATUS_UNCACHED:
			case RESOLV_STATUS_EXPIRED:
				resolv_query(hostname);
			case RESOLV_STATUS_RESOLVING:
				ret = SMCP_STATUS_WAIT_FOR_DNS;
				break;
			default:
			case RESOLV_STATUS_ERROR:
			case RESOLV_STATUS_NOT_FOUND:
				ret = SMCP_STATUS_HOST_LOOKUP_FAILURE;
				break;
		}
	}
#else // CONTIKI
#error SMCP_CONF_USE_DNS was set, but no DNS lookup mechamism is known!
#endif
#endif // SMCP_CONF_USE_DNS

	require_noerr(ret,bail);

bail:
	return ret;
}
uip_ipaddr_t * getHostByName(const char *hostName)
{
    uip_ipaddr_t * result = NULL;
    static uip_ipaddr_t ipaddr;
    if (uiplib_ipaddrconv(hostName, &ipaddr) == 0)
    {
        uip_ipaddr_t *resolved_addr = NULL;
        resolv_status_t status = resolv_lookup(hostName, &resolved_addr);
        if (status == RESOLV_STATUS_UNCACHED || status == RESOLV_STATUS_EXPIRED)
        {
            Lwm2m_Debug("Attempting to look up %s\n", hostName);
            resolv_query(hostName);
            status = RESOLV_STATUS_RESOLVING;
        }
        else if (status == RESOLV_STATUS_CACHED && resolved_addr != NULL )
        {
            Lwm2m_Debug("Lookup of \"%s\" succeeded!\n", hostName);
        }
        else if (status == RESOLV_STATUS_RESOLVING)
        {
            resolved_addr = NULL;
            Lwm2m_Debug("Still looking up \"%s\"...\n", hostName);
        }
        else
        {
            resolved_addr = NULL;
            Lwm2m_Debug("Lookup of \"%s\" failed. status = %d\n", hostName, status);
        }
        if (resolved_addr)
        {
            uip_ipaddr_copy(&ipaddr, resolved_addr);
            result = &ipaddr;
        }
    }
    else
    {
        result = &ipaddr;
        Lwm2m_Debug("Cache hit on look up %s\n", hostName);
    }

    return result;
}
Exemple #28
0
uint8_t
pachube_send(char *key, uint16_t ds, char *status) {

     DS = ds;
     memcpy(KEY, key, 65);
     
     uint8_t len = strlen(status);
     if (len > 32)
	  len = 32;
     
     memcpy(pachube_tmp_buf, status, len);
     pachube_tmp_buf[len] = 0;
     
     uip_ipaddr_t *ipaddr;
     if (!(ipaddr = resolv_lookup(CONF_PACHUBE_SERVICE))) {
	  resolv_query(CONF_PACHUBE_SERVICE, pachube_dns_query_cb);
     } else {
	  pachube_dns_query_cb(NULL, ipaddr);
     }
     return 1;
}
Exemple #29
0
/*---------------------------------------------------------------------------*/
static int
start_request(struct http_socket *s)
{
  uip_ip4addr_t ip4addr;
  uip_ip6addr_t ip6addr;
  uip_ipaddr_t *addr;
  char host[MAX_HOSTLEN];
  char path[MAX_PATHLEN];
  uint16_t port;

  if(parse_url(s->url, host, &port, path)) {

    PRINTF("%s url %s host %s port %d path %s\n",
           HTTP_METHOD_STR(s->method), s->url, host, port, path);

    /* First check if the host is an IP address. */
    if(uiplib_ip6addrconv(host, &ip6addr) == 0) {
      if(uiplib_ip4addrconv(host, &ip4addr) != 0) {
        ip64_addr_4to6(&ip4addr, &ip6addr);
      } else {
        /* Try to lookup the hostname. If it fails, we initiate a hostname
           lookup. */
        if(resolv_lookup(host, &addr) != RESOLV_STATUS_CACHED) {
          resolv_query(host);
          PRINTF("Resolving host...\n");
          return HTTP_SOCKET_OK;
        }
        tcp_socket_connect(&s->s, addr, port);
        return HTTP_SOCKET_OK;
      }
    }
    tcp_socket_connect(&s->s, (uip_ipaddr_t *)&ip6addr, port);
    return HTTP_SOCKET_OK;
  } else {
    return HTTP_SOCKET_ERR;
  }
}
Exemple #30
0
/*-----------------------------------------------------------------------------------*/
static void
connect(void)
{
  uip_ipaddr_t addr, *addrptr;
  u16_t port;
  char *cptr;

  /* Find the first space character in host and put a zero there
     to end the string. */
  for(cptr = host; *cptr != ' ' && *cptr != 0; ++cptr);
  *cptr = 0;

  addrptr = &addr;
  if(uiplib_ipaddrconv(host, &addr) == 0) {
    addrptr = resolv_lookup(host);
    if(addrptr == NULL) {
      resolv_query(host);
      show("Resolving host...");
      return;
    }
  }

  port = 0;
  for(cptr = portentry; *cptr != ' ' && *cptr != 0; ++cptr) {
    if(*cptr < '0' || *cptr > '9') {
      show("Port number error");
      return;
    }
    port = 10 * port + *cptr - '0';
  }


  vnc_viewer_connect(addrptr, port);

  show("Connecting...");

}