Example #1
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;
}
Example #2
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_wget_process, ev, data)
{
  PROCESS_BEGIN();

  strncpy(url, data, sizeof(url));
  open_url(url);

  running = 1;
  
  while(running) {
    PROCESS_WAIT_EVENT();
    
    if(ev == tcpip_event) {
      webclient_appcall(data);
    } else if(ev == resolv_event_found) {
      /* Either found a hostname, or not. */
      if((char *)data != NULL &&
	 resolv_lookup((char *)data) != NULL) {
	open_url(url);
      } else {
	shell_output_str(&wget_command, "Host not found.", "");
      }
    }
  }

  PROCESS_END();
}
Example #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();
        }
    }
}
Example #4
0
PROCESS_THREAD(twitter_resolve_process, ev, data)
{
#if UIP_UDP
    uip_ipaddr_t *ipaddr;

    PROCESS_BEGIN();
    PRINTF("DNS LOOKUP\r\n");
    state.cb_resolve_status(twitter_resolve_lookup);

    PROCESS_WAIT_EVENT_UNTIL(ev == resolv_event_found);

    if (resolv_lookup(DEFAULT_HOST, &ipaddr) == RESOLV_STATUS_CACHED) {
        PRINTF("DNS SUCCESS\r\n");
        state.cb_resolve_status(twitter_resolve_success);
        twitter_address = *ipaddr;
    } else {
        PRINTF("DNS FAILURE\r\n");
        state.cb_resolve_status(twitter_resolve_failure);
        uip_ipaddr(&twitter_address, DEFAULT_IP[0], DEFAULT_IP[1], DEFAULT_IP[2], DEFAULT_IP[3]);
    }

    if (state.parent) process_post(state.parent, PROCESS_EVENT_CONTINUE, NULL);

    PROCESS_END();
#endif /* UIP_UDP */
}
Example #5
0
/*-----------------------------------------------------------------------------------*/
unsigned char
webclient_get(char *host, u16_t port, char *file)
{
  struct uip_conn *conn;
  uip_ipaddr_t *ipaddr;
  static uip_ipaddr_t addr;
  
  /* First check if the host is an IP address. */
  ipaddr = &addr;
  if(uiplib_ipaddrconv(host, (unsigned char *)addr) == 0) {
    ipaddr = (uip_ipaddr_t *)resolv_lookup(host);
    
    if(ipaddr == NULL) {
      return 0;
    }
  }
  
  conn = uip_connect(ipaddr, htons(port));
  
  if(conn == NULL) {
    return 0;
  }
  
  s.port = port;
  strncpy(s.file, file, sizeof(s.file));
  strncpy(s.host, host, sizeof(s.host));
  
  init_connection();
  return 1;
}
Example #6
0
/*-----------------------------------------------------------------------------------*/
unsigned char
webclient_get(const char *host, u16_t port, const char *file)
{
  uip_ipaddr_t addr;
  struct uip_conn *conn;
  uip_ipaddr_t *ipaddr;
  
  /* First check if the host is an IP address. */
  ipaddr = &addr;
  if(uiplib_ipaddrconv(host, &addr) == 0) {
#if UIP_UDP
    ipaddr = resolv_lookup(host);
    
    if(ipaddr == NULL) {
      return 0;
    }
#else /* UIP_UDP */
    return 0;
#endif /* UIP_UDP */
  }
  
  conn = tcp_connect(ipaddr, uip_htons(port), NULL);
  
  if(conn == NULL) {
    return 0;
  }
  
  s.port = port;
  strncpy(s.file, file, sizeof(s.file));
  strncpy(s.host, host, sizeof(s.host));
  
  init_connection();
  return 1;
}
Example #7
0
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;
}
Example #8
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;
}
Example #9
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;
}
Example #10
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_udpsend_process, ev, data)
{
  const char *next, *nextptr;
  struct shell_input *input;
  uint16_t port, local_port;
  
  PROCESS_BEGIN();

  next = strchr(data, ' ');
  if(next == NULL) {
    shell_output_str(&udpsend_command,
		     "udpsend <server> <port> [localport]: server as address", "");
    PROCESS_EXIT();
  }
  ++next;
  strncpy(server, data, sizeof(server));
  port = shell_strtolong(next, &nextptr);

  uiplib_ipaddrconv(server, (u8_t *)&serveraddr);
  udpconn = udp_new(&serveraddr, htons(port), NULL);
  
  if(next != nextptr) {
    local_port = shell_strtolong(nextptr, &nextptr);
    udp_bind(udpconn, htons(local_port));
  }
  running = 1;


  while(running) {
    PROCESS_WAIT_EVENT();

    if(ev == shell_event_input) {
      input = data;
      if(input->len1 + input->len2 == 0) {
	PROCESS_EXIT();
      }

      if(input->len1 > 0) {
	send_line(input->data1, input->len1);
      }
    } else if(ev == tcpip_event) {
      if(uip_newdata()) {
	newdata(uip_appdata, uip_datalen());
      }
#if 0
    } else if(ev == resolv_event_found) {
      /* Either found a hostname, or not. */
      if((char *)data != NULL &&
	 resolv_lookup((char *)data) != NULL) {
	uip_ipaddr_copy(serveraddr, ipaddr);
	telnet_connect(&s, server, serveraddr, nick);
      } else {
	shell_output_str(&udpsend_command, "Host not found.", "");
      }
#endif /* 0 */
    }
  }

  PROCESS_END();
}
Example #11
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));
    }
}
Example #12
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;  
}
Example #13
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);
    }
  }
}
Example #14
0
/*-----------------------------------------------------------------------------------*/
PROCESS_THREAD(wget_process, ev, data)
{
  static char name[32];
  static unsigned char i;

  PROCESS_BEGIN();

  /* Allow other processes to initialize properly. */
  for(i = 0; i < 10; ++i) {
    PROCESS_PAUSE();
  }

  fputs("Get url:", stdout);
  if(contiki_argc > 1) {
    strcpy(url, contiki_argv[1]);
    puts(url);
  } else {
    gets(url);
  }
  fputs("Save as:", stdout);
  if(contiki_argc > 2) {
    strcpy(name, contiki_argv[2]);
    puts(name);
  } else {
    gets(name);
  }
  file = cfs_open(name, CFS_WRITE);
  if(file == -1) {
    printf("Open error with '%s'\n", name);
    app_quit();
  } else {
    petsciiconv_toascii(url, sizeof(url));
    start_get();
  }

  while(1) {

    PROCESS_WAIT_EVENT();
  
    if(ev == tcpip_event) {
      webclient_appcall(data);
#if UIP_UDP
    } else if(ev == resolv_event_found) {
      /* Either found a hostname, or not. */
      if((char *)data != NULL &&
        resolv_lookup((char *)data, NULL) == RESOLV_STATUS_CACHED) {
        start_get();
      } else {
        puts("Host not found");
        app_quit();
      }
#endif /* UIP_UDP */
    }
  }

  PROCESS_END();
}
Example #15
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;
}
Example #16
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(http_socket_process, ev, data)
{
  PROCESS_BEGIN();

  while(1) {

    PROCESS_WAIT_EVENT();

    if(ev == resolv_event_found && data != NULL) {
      struct http_socket *s;
      const char *name = data;
      /* Either found a hostname, or not. We need to go through the
	 list of http sockets and figure out to which connection this
	 reply corresponds, then either restart the HTTP get, or kill
	 it (if no hostname was found). */
      for(s = list_head(socketlist);
          s != NULL;
          s = list_item_next(s)) {
        char host[MAX_HOSTLEN];
        if(s->did_tcp_connect) {
          /* We already connected, ignored */
        } else if(parse_url(s->url, host, NULL, NULL) &&
            strcmp(name, host) == 0) {
          if(resolv_lookup(name, NULL) == RESOLV_STATUS_CACHED) {
            /* Hostname found, restart get. */
            start_request(s);
          } else {
            /* Hostname not found, kill connection. */
            call_callback(s, HTTP_SOCKET_HOSTNAME_NOT_FOUND, NULL, 0);
            removesocket(s);
          }
        }
      }
    } else if(ev == PROCESS_EVENT_TIMER) {
      struct http_socket *s;
      struct etimer *timeout_timer = data;
      /*
       * A socket time-out has occurred. We need to go through the list of HTTP
       * sockets and figure out to which socket this timer event corresponds,
       * then close this socket.
       */
      for(s = list_head(socketlist);
          s != NULL;
          s = list_item_next(s)) {
        if(timeout_timer == &s->timeout_timer && s->timeout_timer_started) {
          tcp_socket_close(&s->s);
          break;
        }
      }
    }
  }

  PROCESS_END();
}
Example #17
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_tcpsend_process, ev, data)
{
  char *next;
  const char *dummy; 
  struct shell_input *input;
  uint16_t port;
  
  PROCESS_BEGIN();

  next = strchr(data, ' ');
  if(next == NULL) {
    shell_output_str(&tcpsend_command,
		     "tcpsend <server> <port>: server as address", "");
    PROCESS_EXIT();
  }
  *next = 0;
  ++next;
  strncpy(server, data, sizeof(server));
  port = shell_strtolong(next, &dummy);
  
  running = 1;

  uiplib_ipaddrconv(server, &serveraddr);
  telnet_connect(&s, &serveraddr, port);
  while(running) {
    PROCESS_WAIT_EVENT();

    if(ev == shell_event_input) {
      input = data;
      if(input->len1 + input->len2 == 0) {
	PROCESS_EXIT();
      }

      if(input->len1 > 0) {
	send_line(&s, input->data1, input->len1);
      }
    } else if(ev == tcpip_event) {
      telnet_app(data);
#if 0            
    } else if(ev == resolv_event_found) {
      /* Either found a hostname, or not. */
      if((char *)data != NULL &&
	 resolv_lookup((char *)data) != NULL) {
	uip_ipaddr_copy(serveraddr, ipaddr);
	telnet_connect(&s, server, serveraddr, nick);
      } else {
	shell_output_str(&tcpsend_command, "Host not found.", "");
      }
#endif /* 0 */
    }
  }

  PROCESS_END();
}
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;
}
Example #19
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.")));
  }
}
Example #20
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);
  }
}
Example #21
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;
  }
}
Example #22
0
/******************************************************************************
* 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

}
Example #23
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_irc_process, ev, data)
{
  char *next;
  struct shell_input *input;
  
  PROCESS_BEGIN();

  next = strchr(data, ' ');
  if(next == NULL) {
    shell_output_str(&irc_command,
		     "irc <server> <nick>: server as address", "");
    PROCESS_EXIT();
  }
  *next = 0;
  ++next;
  strncpy(server, data, sizeof(server));
  strncpy(nick, next, sizeof(nick));
  
  running = 1;

  uiplib_ipaddrconv(server, (u8_t *)&serveraddr);
  ircc_connect(&s, server, &serveraddr, nick);
  while(running) {
    PROCESS_WAIT_EVENT();

    if(ev == shell_event_input) {
      input = data;
      if(input->len1 > 0) {
	parse_line(input->data1);
      }
    } else if(ev == tcpip_event) {
      ircc_appcall(data);
#if 0            
    } else if(ev == resolv_event_found) {
      /* Either found a hostname, or not. */
      if((char *)data != NULL &&
	 resolv_lookup((char *)data) != NULL) {
	uip_ipaddr_copy(serveraddr, ipaddr);
	ircc_connect(&s, server, serveraddr, nick);
      } else {
	shell_output_str(&irc_command, "Host not found.", "");
      }
#endif /* 0 */
    }
  }

  PROCESS_END();
}
Example #24
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
}
Example #25
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...");

}
Example #26
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
}
Example #27
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
}
Example #28
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;
}
Example #29
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;
}
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;
}