示例#1
0
void noit_lua_init_dns() {
  int i;
  const struct dns_nameval *nv;
  struct dns_ctx *pctx;

  /* HASH the rr types */
  for(i=0, nv = dns_type_index(i); nv->name; nv = dns_type_index(++i))
    noit_hash_store(&dns_rtypes,
                    nv->name, strlen(nv->name),
                    (void *)nv);
  /* HASH the class types */
  for(i=0, nv = dns_class_index(i); nv->name; nv = dns_class_index(++i))
    noit_hash_store(&dns_ctypes,
                    nv->name, strlen(nv->name),
                    (void *)nv);

  eventer_name_callback("lua/dns_eventer", noit_lua_dns_eventer);
  eventer_name_callback("lua/dns_timeouts", noit_lua_dns_timeouts);

  if (dns_init(NULL, 0) < 0 || (pctx = dns_new(NULL)) == NULL) {
    noitL(noit_error, "Unable to initialize dns subsystem\n");
  }
  else
    dns_free(pctx);
}
示例#2
0
int main(int argc, char **argv)
{

  /* get commandline options, load config if needed. */
  if(get_options( argc, argv ) < 0 ) {
	  exit(1);
  }

  signal(SIGHUP, sig_hup);

  dns_init();

  if (config.daemon_mode) {
    /* Standard fork and background code */
    switch (fork()) {
	 case -1:	/* Oh shit, something went wrong */
		debug_perror("fork");
		exit(-1);
	 case 0:	/* Child: close off stdout, stdin and stderr */
		close(0);
		close(1);
		close(2);
		break;
	 default:	/* Parent: Just exit */
		exit(0);
    }
  }

  dns_main_loop();

  return 0;
}
示例#3
0
static int dns_module_init(noit_module_t *self) {
  const struct dns_nameval *nv;
  struct dns_ctx *pctx;
  int i;
  pthread_mutex_init(&dns_ctx_store_lock, NULL);
  pthread_mutex_init(&active_events_lock, NULL);
  /* HASH the rr types */
  for(i=0, nv = dns_type_index(i); nv->name; nv = dns_type_index(++i))
    noit_hash_store(&dns_rtypes,
                    nv->name, strlen(nv->name),
                    (void *)nv);
  /* HASH the class types */
  for(i=0, nv = dns_class_index(i); nv->name; nv = dns_class_index(++i))
    noit_hash_store(&dns_ctypes,
                    nv->name, strlen(nv->name),
                    (void *)nv);

  noit_check_interpolate_register_oper_fn("inaddrarpa",
                                          dns_interpolate_inaddr_arpa);
  noit_check_interpolate_register_oper_fn("reverseip",
                                          dns_interpolate_reverse_ip);

  if (dns_init(NULL, 0) < 0 || (pctx = dns_new(NULL)) == NULL) {
    noitL(nlerr, "Unable to initialize dns subsystem\n");
    return -1;
  }
  dns_free(pctx);
  if(dns_ctx_alloc(NULL, 0) == NULL) {
    noitL(nlerr, "Error setting up default dns resolver context.\n");
    return -1;
  }
  return 0;
}
示例#4
0
文件: core.c 项目: dkarametos/pom-ng
// Placeholder for all the stuff to do when processing starts
static int core_processing_start() {

	if (*PTYPE_BOOL_GETVAL(core_param_offline_dns) && dns_init() != POM_OK)
		return POM_ERR;

	return POM_OK;
}
示例#5
0
文件: init.c 项目: GiannisRambo/lwip
/**
 * Perform Sanity check of user-configurable values, and initialize all modules.
 */
void
lwip_init(void)
{
  /* Sanity check user-configurable values */
  lwip_sanity_check();

  /* Modules initialization */
  stats_init();
#if !NO_SYS
  sys_init();
#endif /* !NO_SYS */
  mem_init();
  memp_init();
  pbuf_init();
  netif_init();
#if LWIP_SOCKET
  lwip_socket_init();
#endif /* LWIP_SOCKET */
  ip_init();
#if LWIP_ARP
  etharp_init();
#endif /* LWIP_ARP */
#if LWIP_RAW
  raw_init();
#endif /* LWIP_RAW */
#if LWIP_UDP
  udp_init();
#endif /* LWIP_UDP */
#if LWIP_TCP
  tcp_init();
#endif /* LWIP_TCP */
#if LWIP_SNMP
  snmp_init();
#endif /* LWIP_SNMP */
#if LWIP_AUTOIP
  autoip_init();
#endif /* LWIP_AUTOIP */
#if LWIP_IGMP
  igmp_init();
#endif /* LWIP_IGMP */
#if LWIP_DNS
  dns_init();
#endif /* LWIP_DNS */

#if LWIP_TIMERS
  sys_timeouts_init();
#endif /* LWIP_TIMERS */

#if !NO_SYS
  /* in the Xilinx lwIP 1.2.0 port, lwip_init() was added as a convenience utility function
     to initialize all the lwIP layers. lwIP 1.3.0 introduced lwip_init() in the base lwIP
     itself. However a user cannot use lwip_init() regardless of whether it is raw or socket
     modes. The following call to lwip_sock_init() is made to make sure that lwIP is properly
     initialized in both raw & socket modes with just a call to lwip_init().
   */
  lwip_sock_init();
#endif
}
示例#6
0
文件: init.c 项目: sdelavega/smart.js
/**
 * Perform Sanity check of user-configurable values, and initialize all modules.
 */
void
lwip_init(void)
{
  /*++ Changed by Espressif ++*/
  MEMP_NUM_TCP_PCB = 5;
  TCP_WND = (4 * TCP_MSS);
  TCP_MAXRTX = 3;
  TCP_SYNMAXRTX = 6;
  /*--                      --*/


  /* Modules initialization */
  stats_init();
#if !NO_SYS
  sys_init();
#endif /* !NO_SYS */
/*++ Changed by Espressif ++*/
#if 0
  mem_init(&_bss_end);
#endif
/*--                      --*/
  memp_init();
  pbuf_init();
  netif_init();
#if LWIP_SOCKET
  lwip_socket_init();
#endif /* LWIP_SOCKET */
  ip_init();
#if LWIP_ARP
  etharp_init();
#endif /* LWIP_ARP */
#if LWIP_RAW
  raw_init();
#endif /* LWIP_RAW */
#if LWIP_UDP
  udp_init();
#endif /* LWIP_UDP */
#if LWIP_TCP
  tcp_init();
#endif /* LWIP_TCP */
#if LWIP_SNMP
  snmp_init();
#endif /* LWIP_SNMP */
#if LWIP_AUTOIP
  autoip_init();
#endif /* LWIP_AUTOIP */
#if LWIP_IGMP
  igmp_init();
#endif /* LWIP_IGMP */
#if LWIP_DNS
  dns_init();
#endif /* LWIP_DNS */

#if LWIP_TIMERS
  sys_timeouts_init();
#endif /* LWIP_TIMERS */
}
示例#7
0
int
resolv_init(struct ev_loop *loop, char **nameservers, int nameserver_num, int ipv6first)
{
    if (ipv6first)
        resolv_mode = MODE_IPV6_FIRST;
    else
        resolv_mode = MODE_IPV4_FIRST;

    struct dns_ctx *ctx = &dns_defctx;
    if (nameservers == NULL) {
        /* Nameservers not specified, use system resolver config */
        dns_init(ctx, 0);
    } else {
        dns_reset(ctx);

        for (int i = 0; i < nameserver_num; i++) {
            char *server = nameservers[i];
            dns_add_serv(ctx, server);
        }
    }

    int sockfd = dns_open(ctx);
    if (sockfd < 0) {
        FATAL("Failed to open DNS resolver socket");
    }

    if (nameserver_num == 1 && nameservers != NULL) {
        if (strncmp("127.0.0.1", nameservers[0], 9) == 0
            || strncmp("::1", nameservers[0], 3) == 0) {
            if (verbose) {
                LOGI("bind UDP resolver to %s", nameservers[0]);
            }
            if (bind_to_address(sockfd, nameservers[0]) == -1)
                ERROR("bind_to_address");
        }
    }

#ifdef __MINGW32__
    setnonblocking(sockfd);
#else
    int flags = fcntl(sockfd, F_GETFL, 0);
    fcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
#endif

    ev_io_init(&resolv_io_watcher, resolv_sock_cb, sockfd, EV_READ);
    resolv_io_watcher.data = ctx;

    ev_io_start(loop, &resolv_io_watcher);

    ev_timer_init(&resolv_timeout_watcher, resolv_timeout_cb, 0.0, 0.0);
    resolv_timeout_watcher.data = ctx;

    dns_set_tmcbck(ctx, dns_timer_setup_cb, loop);

    return sockfd;
}
示例#8
0
文件: core.c 项目: k0a1a/pom-ng
// Placeholder for all the stuff to do when processing starts
static int core_processing_start() {

	if (*PTYPE_BOOL_GETVAL(core_param_offline_dns) && dns_init() != POM_OK)
		return POM_ERR;

	if (*PTYPE_BOOL_GETVAL(core_param_reset_perf_on_restart))
		registry_perf_reset_all();

	return POM_OK;
}
示例#9
0
/**
 * Perform Sanity check of user-configurable values, and initialize all modules.
 */
void
lwip_init(void)
{
  esp_ms_timer_init(); // espressif
  /* Modules initialization */
  stats_init();
#if !NO_SYS
  sys_init();
#endif /* !NO_SYS */
  mem_init();
  memp_init();
  pbuf_init();
  netif_init();
#if LWIP_IPV4
  ip_init();
#if LWIP_ARP
  etharp_init();
#endif /* LWIP_ARP */
#endif /* LWIP_IPV4 */
#if LWIP_RAW
  raw_init();
#endif /* LWIP_RAW */
#if LWIP_UDP
  udp_init();
#endif /* LWIP_UDP */
#if LWIP_TCP
  tcp_init();
#endif /* LWIP_TCP */
#if LWIP_SNMP
  snmp_init();
#endif /* LWIP_SNMP */
#if LWIP_AUTOIP
  autoip_init();
#endif /* LWIP_AUTOIP */
#if LWIP_IGMP
  igmp_init();
#endif /* LWIP_IGMP */
#if LWIP_DNS
  dns_init();
#endif /* LWIP_DNS */
#if LWIP_IPV6
  ip6_init();
  nd6_init();
#if LWIP_IPV6_MLD
  mld6_init();
#endif /* LWIP_IPV6_MLD */
#endif /* LWIP_IPV6 */
#if PPP_SUPPORT
  ppp_init();
#endif

#if LWIP_TIMERS
  sys_timeouts_init();
#endif /* LWIP_TIMERS */
}
示例#10
0
文件: host.c 项目: AliceLR/megazeux
boolean host_layer_init(struct config_info *in_conf)
{
  if(!socksyms_init(in_conf))
    return false;

  if(!dns_init(in_conf))
    return false;

  conf = in_conf;
  return true;
}
示例#11
0
文件: test_dns.c 项目: Samdney/tor
static void
NS(test_main)(void *arg)
{
  int retval;
  int made_pending = 0;

  pending_connection_t *pending_conn = NULL;

  edge_connection_t *exitconn = create_valid_exitconn();
  or_circuit_t *on_circ = tor_malloc_zero(sizeof(or_circuit_t));

  cached_resolve_t *cache_entry = NULL;
  cached_resolve_t query;

  (void)arg;

  TO_CONN(exitconn)->address = tor_strdup("torproject.org");

  strlcpy(query.address, TO_CONN(exitconn)->address, sizeof(query.address));

  NS_MOCK(router_my_exit_policy_is_reject_star);
  NS_MOCK(launch_resolve);

  dns_init();

  retval = dns_resolve_impl(exitconn, 1, on_circ, NULL, &made_pending,
                            NULL);

  tt_int_op(retval,OP_EQ,0);
  tt_int_op(made_pending,OP_EQ,1);

  cache_entry = dns_get_cache_entry(&query);

  tt_assert(cache_entry);

  pending_conn = cache_entry->pending_connections;

  tt_assert(pending_conn != NULL);
  tt_assert(pending_conn->conn == exitconn);

  tt_assert(last_launched_resolve == cache_entry);
  tt_str_op(cache_entry->address,OP_EQ,TO_CONN(exitconn)->address);

  done:
  NS_UNMOCK(router_my_exit_policy_is_reject_star);
  NS_UNMOCK(launch_resolve);
  tor_free(on_circ);
  tor_free(TO_CONN(exitconn)->address);
  if (cache_entry)
    tor_free(cache_entry->pending_connections);
  tor_free(cache_entry);
  tor_free(exitconn);
  return;
}
示例#12
0
static dns_ctx_handle_t *dns_ctx_alloc(const char *ns, int port) {
  void *vh;
  dns_ctx_handle_t *h = NULL;
  pthread_mutex_lock(&dns_ctx_store_lock);
  if(ns == NULL && default_ctx_handle != NULL) {
    /* special case -- default context */
    h = default_ctx_handle;
    noit_atomic_inc32(&h->refcnt);
    goto bail;
  }
  if(ns &&
     noit_hash_retrieve(&dns_ctx_store, ns, strlen(ns), &vh)) {
    h = (dns_ctx_handle_t *)vh;
    noit_atomic_inc32(&h->refcnt);
  }
  else {
    int failed = 0;
    h = calloc(1, sizeof(*h));
    h->ns = ns ? strdup(ns) : NULL;
    h->ctx = dns_new(NULL);
    if(dns_init(h->ctx, 0) != 0) failed++;
    if(ns) {
      if(dns_add_serv(h->ctx, NULL) < 0) failed++;
      if(dns_add_serv(h->ctx, ns) < 0) failed++;
    }
    if(port && port != DNS_PORT) {
      dns_set_opt(h->ctx, DNS_OPT_PORT, port);
    }
    if(dns_open(h->ctx) < 0) failed++;
    if(failed) {
      noitL(nlerr, "dns_open failed\n");
      free(h->ns);
      free(h);
      h = NULL;
      goto bail;
    }
    dns_set_tmcbck(h->ctx, eventer_dns_utm_fn, h);
    h->e = eventer_alloc();
    h->e->mask = EVENTER_READ | EVENTER_EXCEPTION;
    h->e->closure = h;
    h->e->callback = dns_eventer_callback;
    h->e->fd = dns_sock(h->ctx);
    eventer_add(h->e);
    h->refcnt = 1;
    if(!ns)
      default_ctx_handle = h;
    else
      noit_hash_store(&dns_ctx_store, h->ns, strlen(h->ns), h);
  }
 bail:
  pthread_mutex_unlock(&dns_ctx_store_lock);
  return h;
}
示例#13
0
static int __init knamed_init(void)
{
    struct file  *filp;
    int           ret;
    int           err;

    PR_INFO("starting");
    PR_INFO("Author: Gu Feng <*****@*****.**>");
    PR_INFO("Version: %s", KNAMED_VERSION);
    PR_INFO("Repository: https://github.com/flygoast/knamed.git");

    filp = filp_open(KNAMED_CONF, O_RDONLY, 0);
    if (IS_ERR(filp)) {
        PR_INFO("conf file \"%s\" didn't existed, ignored", KNAMED_CONF);
        goto init;
    }

    if (filp) {
        fput(filp);
    }

init:

    ret = nf_register_hooks(knamed_ops, ARRAY_SIZE(knamed_ops));
    if (ret < 0) {
        PR_ERR("can't register hooks.");
        goto cleanup;
    }

    knamed_memory_init();

    knamed_procfs_init();
    knamed_sysctl_register();


    dns_init();

    knamed_task = kthread_run(knamed_loop, NULL, "knamedtask");
    if (IS_ERR(knamed_task)) {
        PR_ERR("Create kernel thread failed");
        err = PTR_ERR(knamed_task);
        return err;
    }

    PR_INFO("started");

    return 0;

cleanup:

    return ret;
}
示例#14
0
/**
 * Perform Sanity check of user-configurable values, and initialize all modules.
 */
void ICACHE_FLASH_ATTR
lwip_init(void)
{
    /* Modules initialization */
    stats_init();
#if !NO_SYS
    sys_init();
#endif /* !NO_SYS */
    mem_init();
    memp_init();
    pbuf_init();
    netif_init();
#if LWIP_SOCKET
    lwip_socket_init();
#endif /* LWIP_SOCKET */
    ip_init();
#if LWIP_ARP
    etharp_init();
#endif /* LWIP_ARP */
#if LWIP_RAW
    raw_init();
#endif /* LWIP_RAW */
#if LWIP_UDP
    udp_init();
#endif /* LWIP_UDP */
#if LWIP_TCP
    tcp_init();
#endif /* LWIP_TCP */
#if LWIP_SNMP
    snmp_init();
#endif /* LWIP_SNMP */
#if LWIP_AUTOIP
    autoip_init();
#endif /* LWIP_AUTOIP */
#if LWIP_IGMP
    igmp_init();
#endif /* LWIP_IGMP */
#if LWIP_DNS
    dns_init();
#endif /* LWIP_DNS */
#if LWIP_IPV6
    ip6_init();
    nd6_init();
#if LWIP_IPV6_MLD
    mld6_init();
#endif /* LWIP_IPV6_MLD */
#endif /* LWIP_IPV6 */

#if LWIP_TIMERS
    sys_timeouts_init();
#endif /* LWIP_TIMERS */
}
示例#15
0
文件: test_dns.c 项目: Samdney/tor
static void
NS(test_main)(void *arg)
{
  int retval;
  int made_pending = 0;

  edge_connection_t *exitconn = create_valid_exitconn();
  or_circuit_t *on_circ = tor_malloc_zero(sizeof(or_circuit_t));

  cached_resolve_t *resolve_out = NULL;

  cached_resolve_t *cache_entry = tor_malloc_zero(sizeof(cached_resolve_t));
  cache_entry->magic = CACHED_RESOLVE_MAGIC;
  cache_entry->state = CACHE_STATE_CACHED;
  cache_entry->minheap_idx = -1;
  cache_entry->expire = time(NULL) + 60 * 60;

  (void)arg;

  TO_CONN(exitconn)->address = tor_strdup("torproject.org");

  strlcpy(cache_entry->address, TO_CONN(exitconn)->address,
          sizeof(cache_entry->address));

  NS_MOCK(router_my_exit_policy_is_reject_star);
  NS_MOCK(set_exitconn_info_from_resolve);

  dns_init();

  dns_insert_cache_entry(cache_entry);

  retval = dns_resolve_impl(exitconn, 1, on_circ, NULL, &made_pending,
                            &resolve_out);

  tt_int_op(retval,OP_EQ,0);
  tt_int_op(made_pending,OP_EQ,0);
  tt_assert(resolve_out == cache_entry);

  tt_assert(last_exitconn == exitconn);
  tt_assert(last_resolve == cache_entry);

  done:
  NS_UNMOCK(router_my_exit_policy_is_reject_star);
  NS_UNMOCK(set_exitconn_info_from_resolve);
  tor_free(on_circ);
  tor_free(TO_CONN(exitconn)->address);
  tor_free(cache_entry->pending_connections);
  tor_free(cache_entry);
  return;
}
示例#16
0
void noit_check_resolver_init() {
  eventer_t e;
  if(dns_init(NULL, 0) < 0)
    noitL(noit_error, "dns initialization failed.\n");
  dns_ctx = dns_new(NULL);
  if(dns_init(dns_ctx, 0) != 0 ||
     dns_open(dns_ctx) < 0) {
    noitL(noit_error, "dns initialization failed.\n");
  }
  eventer_name_callback("dns_cache_callback", dns_cache_callback);
  dns_set_tmcbck(dns_ctx, dns_cache_utm_fn, dns_ctx);
  e = eventer_alloc();
  e->mask = EVENTER_READ | EVENTER_EXCEPTION;
  e->closure = dns_ctx;
  e->callback = dns_cache_callback;
  e->fd = dns_sock(dns_ctx);
  eventer_add(e);

  noit_skiplist_init(&nc_dns_cache);
  noit_skiplist_set_compare(&nc_dns_cache, name_lookup, name_lookup_k);
  noit_skiplist_add_index(&nc_dns_cache, refresh_idx, refresh_idx_k);
  noit_check_resolver_loop(NULL, 0, NULL, NULL);
  register_console_dns_cache_commands();
}
示例#17
0
static int dns_module_init(noit_module_t *self) {
  const struct dns_nameval *nv;
  struct dns_ctx *pctx;
  int i;
  const char *config_val;
  dns_mod_config_t *conf;

  conf = noit_module_get_userdata(self);

  pthread_mutex_init(&dns_ctx_store_lock, NULL);
  pthread_mutex_init(&active_events_lock, NULL);

  conf->contexts = DEFAULT_MAX_CONTEXTS;
  if(noit_hash_retr_str(conf->options,
                         "contexts", strlen("contexts"),
                         (const char**)&config_val)) {
    conf->contexts = atoi(config_val);
    if (conf->contexts <= 0)
      conf->contexts = DEFAULT_MAX_CONTEXTS;
  }
  /* HASH the rr types */
  for(i=0, nv = dns_type_index(i); nv->name; nv = dns_type_index(++i))
    noit_hash_store(&dns_rtypes,
                    nv->name, strlen(nv->name),
                    (void *)nv);
  /* HASH the class types */
  for(i=0, nv = dns_class_index(i); nv->name; nv = dns_class_index(++i))
    noit_hash_store(&dns_ctypes,
                    nv->name, strlen(nv->name),
                    (void *)nv);

  noit_check_interpolate_register_oper_fn("inaddrarpa",
                                          dns_interpolate_inaddr_arpa);
  noit_check_interpolate_register_oper_fn("reverseip",
                                          dns_interpolate_reverse_ip);

  if (dns_init(NULL, 0) < 0 || (pctx = dns_new(NULL)) == NULL) {
    noitL(nlerr, "Unable to initialize dns subsystem\n");
    return -1;
  }
  dns_free(pctx);
  if(dns_module_dns_ctx_alloc(self, NULL, 0) == NULL) {
    noitL(nlerr, "Error setting up default dns resolver context.\n");
    return -1;
  }
  register_console_dns_commands();
  return 0;
}
示例#18
0
文件: init.c 项目: 0x00dec0de/Rovnix
/**
 * Perform Sanity check of user-configurable values, and initialize all modules.
 */
void
lwip_init(void)
{
  /* Sanity check user-configurable values */
  lwip_sanity_check();

  /* Modules initialization */
  stats_init();
#if !NO_SYS
  sys_init();
#endif /* !NO_SYS */
  mem_init();
  memp_init();
  pbuf_init();
  netif_init();
#if LWIP_SOCKET
  lwip_socket_init();
#endif /* LWIP_SOCKET */
  ip_init();
#if LWIP_ARP
  etharp_init();
#endif /* LWIP_ARP */
#if LWIP_RAW
  raw_init();
#endif /* LWIP_RAW */
#if LWIP_UDP
  udp_init();
#endif /* LWIP_UDP */
#if LWIP_TCP
  tcp_init();
#endif /* LWIP_TCP */
#if LWIP_SNMP
  snmp_init();
#endif /* LWIP_SNMP */
#if LWIP_AUTOIP
  autoip_init();
#endif /* LWIP_AUTOIP */
#if LWIP_IGMP
  igmp_init();
#endif /* LWIP_IGMP */
#if LWIP_DNS
  dns_init();
#endif /* LWIP_DNS */

#if LWIP_TIMERS
  sys_timeouts_init();
#endif /* LWIP_TIMERS */
}
示例#19
0
void ape_dns_init(acetables *g_ape)
{
	int sock = dns_init(NULL, 1);

	prepare_ape_socket(sock, g_ape);
	
	g_ape->co[sock]->fd = sock;
	g_ape->co[sock]->stream_type = STREAM_DELEGATE;

	g_ape->co[sock]->callbacks.on_read = ape_dns_read;
	g_ape->co[sock]->callbacks.on_write = ape_dns_write;

	events_add(g_ape->events, sock, EVENT_READ|EVENT_WRITE);

	dns_timer_id = add_ticked(ape_dns_timeout, NULL)->identifier;
}
示例#20
0
/**
* @brief Init_lwIP initialize the LwIP
*/
void Init_lwIP(void)
{
	struct ip_addr ipaddr;
	struct ip_addr netmask;
	struct ip_addr gw;
	struct ip_addr dnsserver;
	long *cfg_ip=(long *)wireless_ip;
	//  sys_init();	 
	/* Initializes the dynamic memory heap defined by MEM_SIZE.*/
	mem_init();
	/* Initializes the memory pools defined by MEMP_NUM_x.*/
	memp_init();	
	pbuf_init();	
	netif_init();
	printf("TCP/IP initializing...\n");
	if(*cfg_ip==0){//no ip addr,use DHCP
		/* 启用DHCP服务器 */
		ipaddr.addr = 0;
		netmask.addr = 0;
		gw.addr = 0;
		printf("using dhcp!\n");
		netif_add(&netif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &ethernet_input);
		netif_set_default(&netif);
		netif_set_up(&netif);
		dhcp_start(&netif);
	}
	else{
		printf("using static ip!\n");
		/* 启用静态IP */
		IP4_ADDR(&ipaddr,wireless_ip[0], wireless_ip[1],
		wireless_ip[2], wireless_ip[3]);
		IP4_ADDR(&netmask, wireless_mask[0], wireless_mask[1], 
						wireless_mask[2], wireless_mask[3]);
		IP4_ADDR(&gw, wireless_gw[0], wireless_gw[1],
					wireless_gw[2], wireless_gw[3]);
		IP4_ADDR(&dnsserver, wireless_dns[0], wireless_dns[1],
					wireless_dns[2], wireless_dns[3]);
		dns_init();
		dns_setserver(0, &dnsserver);//set dns server addr	
		netif_add(&netif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &ethernet_input);
		netif_set_default(&netif);
		netif_set_up(&netif);
	}
	timerbase_config();
	printf("TCP/IP initialized.\n");
}
示例#21
0
/**
 * Perform Sanity check of user-configurable values, and initialize all modules.
 */
void
lwip_init(void)
{
  lwip_init_globals();

  /* Sanity check user-configurable values */
  lwip_sanity_check();

  /* Modules initialization */
  stats_init();
  sys_init();
  mem_init();
  memp_init();
  pbuf_init();
  netif_init();
#if LWIP_SOCKET
  lwip_socket_init();
#endif /* LWIP_SOCKET */
  ip_init();
#if LWIP_ARP
  etharp_init();
#endif /* LWIP_ARP */
#if LWIP_RAW
  raw_init();
#endif /* LWIP_RAW */
#if LWIP_UDP
  udp_init();
#endif /* LWIP_UDP */
#if LWIP_TCP
  /* Initialize the network stack */
  // [MS_CHANGE] - tcpip_init() is a no-op.  This method actually initializes the tcpip stack.
  tcpip_init(NULL,NULL);
#endif /* LWIP_TCP */
#if LWIP_SNMP
  snmp_init();
#endif /* LWIP_SNMP */
#if LWIP_AUTOIP
  autoip_init();
#endif /* LWIP_AUTOIP */
#if LWIP_IGMP
  igmp_init();
#endif /* LWIP_IGMP */
#if LWIP_DNS
  dns_init();
#endif /* LWIP_DNS */
}
示例#22
0
int main(int argc, char **argv)
{
	int i;
	char *ns = NULL;

	if(argc < 2) {
		usage(stderr);
		exit(1);
	}
	dns_init();
	ns = argv[1];

	for(i = 2; i < argc; i++) {
		res(argv[i], ns);
	}

	return 0;
}
示例#23
0
文件: mod_udns.c 项目: temoto/pyudns
static int
Resolver_init(Resolver *self, PyObject *args) {
    int r = 0, create_new = 0, do_open = 1;

    if (!PyArg_ParseTuple(args, "|ii", &create_new, &do_open)) {
        PyErr_SetString(PyExc_TypeError, "Resolver(create_new=False, do_open=True) wrong arguments. See help(Resolver) for details.");
        return -1;
    }

    //FIXME
    if (0 == do_open) {
        PyErr_SetString(PyExc_NotImplementedError, "Resolver() do_open=False not yet implemented. Pass True for now. Sorry.");
        return -1;
    }

    self->ctx = NULL;

    if (1 == create_new) {
        self->ctx = dns_new(NULL);
        if (NULL == self->ctx) {
            PyErr_SetString(PyExc_MemoryError, "Resolver() failed to create new udns context.");
            return -1;
        }
    }

    r = dns_init(self->ctx, 0);
    if (r < 0) {
        PyErr_SetString(PyExc_Exception, "Resolver() failed to init udns context.");
        return -1;
    }

    if (1 == do_open) {
        self->fd = dns_open(self->ctx);
        if (self->fd < 0) {
            PyErr_SetString(PyExc_IOError, "Resolver() failed to open udns socket.");
            return -1;
        }
    }

    return 0;
}
示例#24
0
void QCrawlerDNS::init(struct ev_loop * loop)
{
    dns_loop = loop;

    if (dns_init(NULL, 0) < 0 ) {
        LOG(FATAL) << "init dns fatal";
    }

    dns_fd = dns_open(NULL);
    if (dns_fd < 0) {
        LOG(FATAL) << "open dns fatal";
    }

    if (dns_loop == NULL) {
        dns_loop = ev_default_loop(0);
    }

    ev_io_init(&dns_io_watcher, dns_io_cb, dns_fd, EV_READ);
    ev_io_start(dns_loop, &dns_io_watcher);

    ev_timer_init (&dns_timeout_watcher, dns_timeout_cb, 1, 0.);
    ev_timer_start (dns_loop, &dns_timeout_watcher);
}
示例#25
0
int
resolv_init(struct ev_loop *loop) {
    struct dns_ctx *ctx = &dns_defctx;
    dns_init(ctx, 1);

    int sockfd = dns_sock(ctx);

    int flags = fcntl(sockfd, F_GETFL, 0);
    fcntl(sockfd, F_SETFL, flags | O_NONBLOCK);

    ev_io_init(&resolv_io_watcher, resolv_sock_cb, sockfd, EV_READ);
    resolv_io_watcher.data = ctx;

    ev_io_start(loop, &resolv_io_watcher);


    ev_timer_init(&resolv_timeout_watcher, resolv_timeout_cb, 0.0, 0.0);
    resolv_timeout_watcher.data = ctx;

    dns_set_tmcbck(ctx, dns_timer_setup_cb, loop);

    return sockfd;
}
示例#26
0
/*
 * Global initialization.  Basically just initialize event/dns.
 */
void
robin_init(void)
{
	extern void *current_base;
	static int once = 0;
	const char *filename;

	if (once)
		return;
	once = 1;

	/* some trickery to only init event once */
	if (current_base == NULL)
		event_init();
	dns_init();
	tbox_init();

	/* load some defaults */
	if ((filename = getenv(ROBIN_CONFENV)))
		tbloadconf(filename, rfs_conflist);
	else
		tbloadconf(ROBIN_CONFFILE, rfs_conflist);
}
示例#27
0
文件: main.c 项目: gameswarp/Arduino
static void
wl_cm_conn_cb(struct wl_network_t* net, void* ctx)
{
	struct ctx_server* hs = ctx;

	LINK_LED_ON();

	INFO_INIT("Connection cb...\n");

	printk("link up, connected to \"%s\"\n", ssid2str(&net->ssid));
    if ( hs->net_cfg.dhcp_enabled == DYNAMIC_IP_CONFIG ) {
			INFO_INIT("Start DHCP...\n");
		    printk("requesting dhcp ... ");
            int8_t result = dhcp_start(hs->net_cfg.netif);
            printk((result==ERR_OK)?"OK\n":"FAILED\n");
            hs->net_cfg.dhcp_running = 1;
    }
    else {
        netif_set_up(hs->net_cfg.netif);
    }

    INFO_INIT("Start DNS...\n");
    dns_init();
}
示例#28
0
//*****************************************************************************
//
//! Initializes the lwIP TCP/IP stack.
//!
//! \param pucMAC is a pointer to a six byte array containing the MAC
//! address to be used for the interface.
//! \param ulIPAddr is the IP address to be used (static).
//! \param ulNetMask is the network mask to be used (static).
//! \param ulGWAddr is the Gateway address to be used (static).
//! \param ulIPMode is the IP Address Mode.  \b IPADDR_USE_STATIC will force
//! static IP addressing to be used, \b IPADDR_USE_DHCP will force DHCP with
//! fallback to Link Local (Auto IP), while \b IPADDR_USE_AUTOIP will force
//! Link Local only.
//!
//! This function performs initialization of the lwIP TCP/IP stack for the
//! Stellaris Ethernet MAC, including DHCP and/or AutoIP, as configured.
//!
//! \return None.
//
//*****************************************************************************
void LWIPServiceTaskInit(void *pvParameters)
{
	struct ip_addr *ip_addr;
	struct ip_addr *net_mask;
	struct ip_addr *gw_addr;

	//struct ip_addr ip_addr_local;
	//struct ip_addr net_mask_local;

	char IPState = 0;

	char* configLoad;

	IP_CONFIG * ipCfg;

	printf("Initialisiere IP ");
	ipCfg = pvPortMalloc(sizeof(IP_CONFIG));

	configLoad = loadFromConfig(IP_CONFIG_FILE, "USE_DHCP");

#ifdef ENABLE_GRAPHIC
	vShowBootText("load ipconfig ...");
#endif

	printf("LWIPSTACK: LOAD CONFIG: (%s)\n", configLoad);
	if (configLoad == 0)
	{
		IPState = IPADDR_USE_AUTOIP;
	}
	else if (strcmp(configLoad, "true") == 0)
	{
		IPState = IPADDR_USE_DHCP;
	}
	else
	{
		IPState = IPADDR_USE_STATIC;
	}

	vPortFree(configLoad);

	// Start the TCP/IP thread & init stuff
	tcpip_init(NULL, NULL);

	vTaskDelay(100 / portTICK_RATE_MS);

	// Setup the network address values.
	if (IPState == IPADDR_USE_STATIC)
	{
		ip_addr = getAddresFromConfig("IP_ADDRESS");
		net_mask = getAddresFromConfig("IP_SUBNETMASK");
		gw_addr = getAddresFromConfig("IP_GATEWAY");
	}
#if LWIP_DHCP || LWIP_AUTOIP
	else
	{
		ip_addr = pvPortMalloc(sizeof(struct ip_addr));
		net_mask = pvPortMalloc(sizeof(struct ip_addr));
		gw_addr = pvPortMalloc(sizeof(struct ip_addr));
	}
#endif

	// Create, configure and add the Ethernet controller interface with
	// default settings.
	// WARNING: This must only be run after the OS has been started.
	// Typically this is the case, however, if not, you must place this
	// in a post-OS initialization
	// @SEE http://lwip.wikia.com/wiki/Initialization_using_tcpip.c

	printf("Starting NETIF ... \n");
#ifdef ENABLE_GRAPHIC
	vShowBootText("starting Network ...");
#endif
	netif_add(&lwip_netif, ip_addr, net_mask, gw_addr, NULL, ethernetif_init,
			tcpip_input);
	netif_set_default(&lwip_netif);

	printf("NETIF UP\n");

	// Start DHCP, if enabled.
#if LWIP_DHCP
	if (IPState == IPADDR_USE_DHCP)
	{
#ifdef ENABLE_GRAPHIC
		vShowBootText("waiting for DHCP ...");
#endif
		printf("Starte DHCP Client ...     ");
		if (dhcp_start(&lwip_netif) == ERR_OK)
		{
			printf("[ok]\n");
		}
		else
		{
			printf("[fail]\n");
		}
	}
#endif

	// Start AutoIP, if enabled and DHCP is not.
#if LWIP_AUTOIP
	if (IPState == IPADDR_USE_AUTOIP)
	{
		printf ("Setzte Auto IP (NICHT DHCP) ...\n");
		autoip_start(&lwip_netif);
	}
#endif

	if (IPState == IPADDR_USE_STATIC)
	{
		// Bring the interface up.
		netif_set_up(&lwip_netif);
	}
	vTaskDelay(1000 / portTICK_RATE_MS);

	while (0 == netif_is_up(&lwip_netif))
	{
		vTaskDelay(5000 / portTICK_RATE_MS);
		if (0 == netif_is_up(&lwip_netif))
		{
			dhcp_renew(&lwip_netif);
		}
	}

	printnetif(&lwip_netif);

	configLoad = loadFromConfig(IP_CONFIG_FILE, "IS_SERVER");
	if (strcmp(configLoad, "true") == 0)
	{
		/* Initialize HTTP, DNS, SNTP */
		printf("HTTPD Starten ...\n");
		httpd_init();
	}
	vPortFree(configLoad);

#if ENABLE_SNTP
	printf("SNTP Starten ...\n");
	sntp_init();
#endif

#if ENABLE_DNS
	printf("DNS Starten ...\n");
	dns_init();
#endif

#if ENABLE_NET_BIOS
	printf("NETBIOS Starten ...\n");
	netbios_init();
#endif

	printf("Dienste gestartet ...\n");

#ifdef ENABLE_GRAPHIC
	configLoad = loadFromConfig(IP_CONFIG_FILE, "IS_CLIENT");
	if (strcmp(configLoad, "true") == 0)
	{
		vShowBootText("loading menu ...");
		vLoadMenu();
	}
	else
	{
		vShowBootText("ready for requests ...");
	}
	vPortFree(configLoad);
#endif

	// Nothing else to do.  No point hanging around.
	while (1)
	{
		vTaskDelay(500 / portTICK_RATE_MS);
		if (EthernetPHYRead(ETH_BASE, PHY_MR1) & ETH_PHY_LINK_UP)
		{
			if (!(netif_is_up(&lwip_netif)))
			{
				// set link up flag
				netif_set_up(&lwip_netif);
#ifdef ENABLE_GRAPHIC
				vShowBootText("activate networkinterface ...");
				configLoad = loadFromConfig(IP_CONFIG_FILE, "IS_CLIENT");
				if (strcmp(configLoad, "true") == 0)
				{
					vShowBootText("loading menu ...");
					vLoadMenu();
				}
				else
				{
					vShowBootText("ready for requests ...");
				}
				vPortFree(configLoad);
#endif
				if (IPState == IPADDR_USE_DHCP)
				{
					printf("DHCP Adresse anfordern ...  ");
					if (dhcp_renew(&lwip_netif) == ERR_OK)
					{
						printf("[ok]\n");
						printnetif(&lwip_netif);
					}
					else
					{
						printf("[fail]\n");
					}
				}
			}
		}
		else
		{
			if (netif_is_up(&lwip_netif))
			{
#ifdef ENABLE_GRAPHIC
				vShowBootText("no networkconnection!!");
#endif
				printf("Deaktiviere Netzwerkinterface ...  ");
				netif_set_down(&lwip_netif);
			}
		}

	}
}
示例#29
0
int main(int argc, char **argv) {
  int c;
  struct ipcheck ipc;
  char *nameserver = NULL;
  int zgiven = 0;

  if (!(progname = strrchr(argv[0], '/'))) progname = argv[0];
  else argv[0] = ++progname;

  while((c = getopt(argc, argv, "hqtvms:S:cn:")) != EOF) switch(c) {
  case 's': ++zgiven; addzone(optarg); break;
  case 'S':
    ++zgiven;
    if (addzonefile(optarg)) break;
    fprintf(stderr, "%s: unable to read %s\n", progname, optarg);
    return 1;
  case 'c': ++zgiven; nzones = 0; break;
  case 'q': --verbose; break;
  case 'v': ++verbose; break;
  case 't': do_txt = 1; break;
  case 'n': nameserver = optarg; break;
  case 'm': ++stopfirst; break;
  case 'h':
    printf("%s: %s.\n", progname, version);
    printf("Usage is: %s [options] address..\n", progname);
    printf(
"Where options are:\n"
" -h - print this help and exit\n"
" -s service - add the service (DNSBL zone) to the serice list\n"
" -S service-file - add the DNSBL zone(s) read from the given file\n"
" -c - clear service list\n"
" -v - increase verbosity level (more -vs => more verbose)\n"
" -q - decrease verbosity level (opposite of -v)\n"
" -t - obtain and print TXT records if any\n"
" -m - stop checking after first address match in any list\n"
" -n ipaddr - use the given nameserver instead of the default\n"
"(if no -s or -S option is given, use $RBLCHECK_ZONES, ~/.rblcheckrc\n"
"or /etc/rblcheckrc in that order)\n"
    );
    return 0;
  default:
    fprintf(stderr, "%s: use `%s -h' for help\n", progname, progname);
    return 1;
  }

  if (!zgiven) {
    char *s = getenv("RBLCHECK_ZONES");
    if (s) {
      char *k;
      s = strdup(s);
      k = strtok(s, " \t");
      while(k) {
        addzone(k);
        k = strtok(NULL, " \t");
      }
      free(s);
    }
    else {
      char *path;
      char *home = getenv("HOME");
      if (!home) home = ".";
      path = malloc(strlen(home) + 1 + sizeof(".rblcheckrc"));
      sprintf(path, "%s/.rblcheckrc", home);
      if (!addzonefile(path))
        addzonefile("/etc/rblcheckrc");
      free(path);
    }
  }
  if (!nzones) {
    fprintf(stderr, "%s: no service (zone) list specified (-s or -S option)\n",
            progname);
    return 1;
  }

  argv += optind;
  argc -= optind;

  if (!argc)
    return 0;

  if (dns_init(0) < 0) {
    fprintf(stderr, "%s: unable to initialize DNS library: %s\n",
            progname, strerror(errno));
    return 1;
  }
  if (nameserver) {
    dns_add_serv(NULL, NULL);
    if (dns_add_serv(NULL, nameserver) < 0)
      fprintf(stderr, "%s: unable to use nameserver %s: %s\n",
              progname, nameserver, strerror(errno));
  }
  if (dns_open(NULL) < 0) {
    fprintf(stderr, "%s: unable to initialize DNS library: %s\n",
            progname, strerror(errno));
    return 1;
  }

  for (c = 0; c < argc; ++c) {
    if (c && (verbose > 1 || (verbose == 1 && do_txt))) putchar('\n');
    ipc.name = argv[c];
    submit(&ipc);
    waitdns(&ipc);
    display_result(&ipc);
    if (stopfirst > 1 && listed) break;
  }

  return listed ? 100 : failures ? 2 : 0;
}
示例#30
0
文件: init.c 项目: Karamax/arrakis
static void remaining_lwip_initialization(char *card_name, uint64_t queueid)
{
    nb = netbench_alloc("app", RECORDED_EVENTS_COUNT);
    //asq: connect to the NIC driver, before doing anything else
    idc_connect_to_driver(card_name, queueid);
    DEBUGPRINTPS("Connected to driver [%s]\n", card_name);
    stats_init();
    sys_init();
    DEBUGPRINTPS("remaining_lwip_init: allocating pbuf memory\n");
#ifdef CONFIG_QEMU_NETWORK
    printf("#### Networking with small amount of memory #####\n");
#endif // CONFIG_QEMU_NETWORK
    printf("#### [%u:%"PRIuDOMAINID":%s] [%s] [%d] MEM_SIZE[%d], "
            "PBUF_POOL_SIZE[%d], MEMP_MAX[%d],  RECEIVE_BUFFERS[%d] qid[%"PRIu64"]####\n",
       disp_get_core_id(), disp_get_domain_id(), disp_name(),
       MEM_CONF_LOC, is_ctl, MEM_SIZE, PBUF_POOL_SIZE, MEMP_MAX,
       RECEIVE_BUFFERS, queueid);

    memp_init();                // 0'st buffer

    DEBUGPRINTPS("remaining_lwip_init: allocating memory for sending\n");
    mem_init();                 // 1'th buffer
    DEBUGPRINTPS("remaining_lwip_init: done with memroy allocation\n");

    DEBUGPRINTPS("LWIP: lwip_starting\n");
    netif_init();
#if LWIP_SOCKET
    lwip_socket_init();
#endif                          /* LWIP_SOCKET */
    ip_init();
    DEBUGPRINTPS("r_lwip_init: done ip_init\n");
#if LWIP_ARP
    etharp_init();
#endif                          /* LWIP_ARP */
#if LWIP_RAW
    raw_init();
#endif                          /* LWIP_RAW */
#if LWIP_UDP
    udp_init();
    DEBUGPRINTPS("r_lwip_init: done udp_init\n");
#endif                          /* LWIP_UDP */
#if LWIP_TCP
    tcp_init();
    DEBUGPRINTPS("r_lwip_init: done tcp_init\n");
#endif                          /* LWIP_TCP */
#if LWIP_SNMP
    snmp_init();
    DEBUGPRINTPS("r_lwip_init: done snmp_init\n");
#endif                          /* LWIP_SNMP */
#if LWIP_AUTOIP
    autoip_init();
    DEBUGPRINTPS("r_lwip_init: done autoip_init\n");
#endif                          /* LWIP_AUTOIP */
#if LWIP_IGMP
    igmp_init();
    DEBUGPRINTPS("r_lwip_init: done igmp_init\n");
#endif                          /* LWIP_IGMP */
    DEBUGPRINTPS("r_lwip_init: done2 igmp_init\n");
#if LWIP_DNS
    DEBUGPRINTPS("r_lwip_init: starting DNS_init\n");
    dns_init();
    DEBUGPRINTPS("r_lwip_init: done DNS_init\n");
#endif                          /* LWIP_DNS */
    DEBUGPRINTPS("LWIP: lwip_started\n");
}