Example #1
0
int ssl_open(http_t *client, char *msg)
{
	char buf[256];
	const char *sn;
	X509 *cert;

	if (!client->ssl_enabled)
		return tcp_init(&client->tcp, msg);

	tcp_set_port(&client->tcp, HTTPS_DEFAULT_PORT);
	DO(tcp_init(&client->tcp, msg));

	logit(LOG_INFO, "%s, initiating HTTPS ...", msg);
	client->ssl_ctx = SSL_CTX_new(SSLv23_client_method());
	if (!client->ssl_ctx)
		return RC_HTTPS_OUT_OF_MEMORY;

	/* POODLE, only allow TLSv1.x or later */
	SSL_CTX_set_options(client->ssl_ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_COMPRESSION);

	SSL_CTX_set_verify(client->ssl_ctx, SSL_VERIFY_PEER, verify_callback);
	SSL_CTX_set_verify_depth(client->ssl_ctx, 150);

	/* Try to figure out location of trusted CA certs on system */
	if (ssl_set_ca_location(client))
		return RC_HTTPS_NO_TRUSTED_CA_STORE;

	client->ssl = SSL_new(client->ssl_ctx);
	if (!client->ssl)
		return RC_HTTPS_OUT_OF_MEMORY;

	/* SSL SNI support: tell the servername we want to speak to */
	http_get_remote_name(client, &sn);
	if (!SSL_set_tlsext_host_name(client->ssl, sn))
		return RC_HTTPS_SNI_ERROR;

	SSL_set_fd(client->ssl, client->tcp.ip.socket);
	if (-1 == SSL_connect(client->ssl))
		return RC_HTTPS_FAILED_CONNECT;

	logit(LOG_INFO, "SSL connection using %s", SSL_get_cipher(client->ssl));

	cert = SSL_get_peer_certificate(client->ssl);
	if (!cert)
		return RC_HTTPS_FAILED_GETTING_CERT;

	if (SSL_get_verify_result(client->ssl) == X509_V_OK)
		logit(LOG_DEBUG, "Certificate OK");

	X509_NAME_oneline(X509_get_subject_name(cert), buf, sizeof(buf));
	logit(LOG_INFO, "SSL server cert subject: %s", buf);
	X509_NAME_oneline(X509_get_issuer_name(cert), buf, sizeof(buf));
	logit(LOG_INFO, "SSL server cert issuer: %s", buf);

	X509_free(cert);

	return 0;
}
Example #2
0
int ssl_open(http_t *client, char *msg)
{
	char buf[256];
	const char *sn;
	const X509 *cert;

	if (!client->ssl_enabled)
		return tcp_init(&client->tcp, msg);

	tcp_set_port(&client->tcp, 443);
	DO(tcp_init(&client->tcp, msg));

	logit(LOG_INFO, "%s, initiating HTTPS ...", msg);
	client->ssl_ctx = SSL_CTX_new(SSLv23_client_method());
	if (!client->ssl_ctx)
		return RC_HTTPS_OUT_OF_MEMORY;

	client->ssl = SSL_new(client->ssl_ctx);
	if (!client->ssl)
		return RC_HTTPS_OUT_OF_MEMORY;

	/* SSL SNI support: tell the servername we want to speak to */
	http_get_remote_name(client, &sn);
	if (gnutls_server_name_set(client->ssl->gnutls_state, GNUTLS_NAME_DNS, sn, strlen(sn)))
		return RC_HTTPS_SNI_ERROR;

	SSL_set_fd(client->ssl, client->tcp.ip.socket);
	if (-1 == SSL_connect(client->ssl))
		return RC_HTTPS_FAILED_CONNECT;

	logit(LOG_INFO, "SSL connection using %s", SSL_get_cipher(client->ssl));

	/* Get server's certificate (note: beware of dynamic allocation) - opt */
	cert = SSL_get_peer_certificate(client->ssl);
	if (!cert)
		return RC_HTTPS_FAILED_GETTING_CERT;

	/* Logging some cert details. Please note: X509_NAME_oneline doesn't
	   work when giving NULL instead of a buffer. */
	X509_NAME_oneline(X509_get_subject_name(cert), buf, sizeof(buf));
	logit(LOG_INFO, "SSL server cert subject: %s", buf);
	X509_NAME_oneline(X509_get_issuer_name(cert), buf, sizeof(buf));
	logit(LOG_INFO, "SSL server cert issuer: %s", buf);

	/* We could do all sorts of certificate verification stuff here before
	   deallocating the certificate. */
	X509_free(cert);

	return 0;
}
Example #3
0
int
microps_init (void) {
    if (ethernet_init() == -1) {
        goto ERROR;
    }
    if (slip_init() == -1) {
        goto ERROR;
    }
    if (arp_init() == -1) {
        goto ERROR;
    }
    if (ip_init() == -1) {
        goto ERROR;
    }
    if (icmp_init() == -1) {
        goto ERROR;
    }
    if (udp_init() == -1) {
        goto ERROR;
    }
    if (tcp_init() == -1) {
        goto ERROR;
    }
    return  0;

ERROR:
    microps_cleanup();
    return -1;
}
Example #4
0
/*
 * IP initialization: fill in IP protocol switch table.
 * All protocols not implemented in kernel go to raw IP protocol handler.
 */
void
ip_init(Slirp *slirp)
{
    slirp->ipq.ip_link.next = slirp->ipq.ip_link.prev = &slirp->ipq.ip_link;
    udp_init(slirp);
    tcp_init(slirp);
}
Example #5
0
void tcpipinit()
{
	prog_name= "kernel TCP/IP";

	mu_init(&mu_generic);
	mu_lock(&mu_generic);

	tcpip_dirinit();

	sr_init_cap_names();
	sr_set_cap_name(ETH_DEV0, "eth");
	sr_set_cap_name(IP_DEV0, "ip");
	sr_set_cap_name(TCP_DEV0, "tcp");
	sr_set_cap_name(UDP_DEV0, "udp");
#if 0
	sr_enable_linger_right();
#endif

	bf_init();
	clck_init();
	sr_init();
	eth_init();
	arp_init();
	ip_init();
	tcp_init();
	udp_init();
	add_default_gws();

	mu_unlock(&mu_generic);
	tcpip_chmod();
}
Example #6
0
static BOOL
iso_send_connection_request(RDPCLIENT * This, char *cookie)
{
	STREAM s;
	int cookielen = (int)strlen(cookie);
	int length = 11 + cookielen;

	s = tcp_init(This, length);

	if(s == NULL)
		return False;

	out_uint8(s, 3);	/* version */
	out_uint8(s, 0);	/* reserved */
	out_uint16_be(s, length);	/* length */

	out_uint8(s, length - 5);	/* hdrlen */
	out_uint8(s, ISO_PDU_CR);
	out_uint16(s, 0);	/* dst_ref */
	out_uint16(s, 0);	/* src_ref */
	out_uint8(s, 0);	/* class */

	out_uint8p(s, cookie, cookielen);

	s_mark_end(s);
	return tcp_send(This, s);
}
Example #7
0
void tcpip_init(void)
{
	net_mutex = thinkos_mutex_alloc();

	assert(net_mutex > 0);

	tcpip_net_lock();

	DCC_LOG1(LOG_TRACE, "net_mutex=%d", net_mutex);

	mbuf_init();

	pktbuf_pool_init();

#if (ENABLE_NET_RAW)
	raw_init();
#endif

#if (ENABLE_NET_UDP)
	udp_init();
#endif

#if (ENABLE_NET_TCP)
	tcp_init();
#endif

	ifnet_init();

	tcpip_net_unlock();
}
Example #8
0
File: ipc.c Project: semibiotic/bee
int link_wait(link_t * ld, int service)
{  int   rc;
   int   sdnew;

   if (ld->fStdio) return 0;

   rc = tcp_init(SF_ZOMBIES);
   if (rc < 0) return (-1);

   rc = tcp_socket(0);
   if (rc < 0) return (-1);
   ld->fd = rc;

   rc = tcp_server(ld->fd, service, 8, NULL);
   if (rc < 0) return (-1);


   while(1)
   {  do
      {  sdnew = tcp_accept(ld->fd);
      }  while(sdnew == (-1) && errno == EINTR);
      if (sdnew < 0) break;

      rc = tcp_forkclient(ld->fd, sdnew);
      if (rc == 0)   // child
      {  ld->fd = sdnew;
         break;
      } 
   } 

   return 0;
}
Example #9
0
int
microps_init (const struct microps_param *param) {
    if (ethernet_init() == -1) {
        goto ERROR;
	}
    if (ethernet_device_open(param->ethernet_device, param->ethernet_addr) == -1) {
        goto ERROR;
    }
	if (arp_init() == -1) {
        goto ERROR;
    }
    if (ip_init(param->ip_addr, param->ip_netmask, param->ip_gateway) == -1) {
        goto ERROR;
    }
    if (icmp_init() == -1) {
        goto ERROR;
    }
	if (udp_init() == -1) {
        goto ERROR;
    }
	if (tcp_init() == -1) {
        goto ERROR;
    }
    if (ethernet_device_run() == -1) {
        goto ERROR;        
    }
	return  0;
ERROR:
    //microps_cleanup();
	return -1;
}
Example #10
0
File: iso.c Project: RPG-7/reactos
static void
iso_send_connection_request(char *username)
{
	STREAM s;
	int length = 30 + strlen(username);

	s = tcp_init(length);

	out_uint8(s, 3);	/* version */
	out_uint8(s, 0);	/* reserved */
	out_uint16_be(s, length);	/* length */

	out_uint8(s, length - 5);	/* hdrlen */
	out_uint8(s, ISO_PDU_CR);
	out_uint16(s, 0);	/* dst_ref */
	out_uint16(s, 0);	/* src_ref */
	out_uint8(s, 0);	/* class */

	out_uint8p(s, "Cookie: mstshash=", strlen("Cookie: mstshash="));
	out_uint8p(s, username, strlen(username));

	out_uint8(s, 0x0d);	/* Unknown */
	out_uint8(s, 0x0a);	/* Unknown */

	s_mark_end(s);
	tcp_send(s);
}
Example #11
0
int main()
{

	MSG message,snd_msg;
	int read_n;
	int reuse = 1;
	signal(13,SIG_IGN);
	int fd_server = tcp_init();
	if( 0 != setsockopt(fd_server,SOL_SOCKET,SO_REUSEADDR,&reuse,sizeof(int)))
	{
		perror("set error\n");
		exit(-1);
	}

	int fd_client;// = tcp_accpet(fd_server);
	
	while( (fd_client = tcp_accept(fd_server)) )
	{
		memset(&message,0,sizeof(message));
		recv(fd_client,&message,MSG_LEN,0);
		recv(fd_client,&message.s_buf,message.s_len,0);
		printf("recv msg:%s\n",message.s_buf);

		int fd_file = open(message.s_buf,O_RDONLY);
		while(memset(&snd_msg,0,sizeof(snd_msg)),(read_n = read(fd_file,snd_msg.s_buf,MSG_SIZE))>0 )
		{
			snd_msg.s_len = read_n;
			send(fd_client,&snd_msg,snd_msg.s_len+MSG_LEN,0);
		}
		snd_msg.s_len = 0;
		send(fd_client,&snd_msg,snd_msg.s_len+MSG_LEN,0);
		close(fd_file);
		close(fd_client);
	}
}
Example #12
0
/* Initialize fast path data packet */
STREAM
iso_fp_init(rdpIso * iso, int length)
{
	STREAM s;
	s = tcp_init(iso->tcp, length + 3);
	s_push_layer(s, iso_hdr, 3);
	return s;
}
Example #13
0
/*
 * IP initialization: fill in IP protocol switch table.
 * All protocols not implemented in kernel go to raw IP protocol handler.
 */
void
ip_init()
{
	ipq.ip_link.next = ipq.ip_link.prev = &ipq.ip_link;
	ip_id = tt.tv_sec & 0xffff;
	udp_init();
	tcp_init();
}
Example #14
0
/*
 * IP initialization: fill in IP protocol switch table.
 * All protocols not implemented in kernel go to raw IP protocol handler.
 */
void ip_init(void)
{
	ipq.next = ipq.prev = (ipqp_32)&ipq;
	ip_id = tt.tv_sec & 0xffff;
	udp_init();
	tcp_init();
	ip_defttl = IPDEFTTL;
}
Example #15
0
/**
 * 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
}
Example #16
0
int main(int argc, char *argv[]) {
	// listen on TCP port SSP_SERVER_PORT
	tcp_init();
	while ( !app_done ) {
		if ( udp_enabled ) udp_send();
		tcp_read_cmd( udp_enabled );
	}
	return 0;
}
Example #17
0
/*
 * IP initialization: fill in IP protocol switch table.
 * All protocols not implemented in kernel go to raw IP protocol handler.
 */
void
ip_init()
{
	ipq.ip_link.next = ipq.ip_link.prev = &ipq.ip_link;
	ip_id = tt.tv_sec & 0xffff;
	udp_init();
	tcp_init();
	ip_defttl = IPDEFTTL;
}
Example #18
0
/**
 * 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 */
}
Example #19
0
/* Output and send X.224 Connection Request TPDU with routing for username */
void
x224_send_connection_request(rdpIso * iso)
{
	STREAM s;
	int length = 11;
	int cookie_length;

	cookie_length = strlen(iso->cookie);

	if (iso->mcs->sec->rdp->redirect_routingtoken)
		/* routingToken */
		length += iso->mcs->sec->rdp->redirect_routingtoken_len;
	else
		/* cookie */
		length += 19 + cookie_length;

	if (iso->nego->requested_protocols > PROTOCOL_RDP)
		length += 8;

	/* FIXME: Use x224_send_dst_src_class */
	s = tcp_init(iso->tcp, length);

	tpkt_output_header(s, length);

	/* X.224 Connection Request (CR) TPDU */
	out_uint8(s, length - 5);	/* length indicator */
	out_uint8(s, X224_TPDU_CONNECTION_REQUEST);
	out_uint16_le(s, 0);	/* dst_ref */
	out_uint16_le(s, 0);	/* src_ref */
	out_uint8(s, 0);	/* class */

	if (iso->mcs->sec->rdp->redirect_routingtoken)
	{
		/* routingToken */
		out_uint8p(s, iso->mcs->sec->rdp->redirect_routingtoken, iso->mcs->sec->rdp->redirect_routingtoken_len);
	}
	else
	{
		/* cookie */
		out_uint8p(s, "Cookie: mstshash=", strlen("Cookie: mstshash="));
		out_uint8p(s, iso->cookie, cookie_length);
		out_uint8(s, 0x0D);	/* CR */
		out_uint8(s, 0x0A);	/* LF */
	}

	if (iso->nego->requested_protocols > PROTOCOL_RDP)
	{
		out_uint8(s, TYPE_RDP_NEG_REQ); /* When using TLS, NLA, or both, RDP_NEG_DATA should be present */
		out_uint8(s, 0x00);	/* flags, must be set to zero */
		out_uint16_le(s, 8);	/* RDP_NEG_DATA length (8) */
		out_uint32_le(s, iso->nego->requested_protocols); /* requestedProtocols */
	}

	s_mark_end(s);
	tcp_send(iso->tcp, s);
}
Example #20
0
int main(int argc, char **argv)
{
	struct sigaction sig_stop;
	struct sigaction sig_time;

	_main = main_init(argc, argv);
	_log = log_init();
	_main->conf = conf_init(argc, argv);
	_main->work = work_init();

	_main->tcp = tcp_init();
	_main->node = node_init();
	_main->mime = mime_init();

	/* Check configuration */
	conf_print();

	/* Catch SIG INT */
	unix_signal(&sig_stop, &sig_time);

	/* Fork daemon */
	unix_fork(log_console(_log));

	/* Increase limits */
	unix_limits(_main->conf->cores, CONF_EPOLL_MAX_EVENTS);

	/* Load mime types */
	mime_load();
	mime_hash();

	/* Prepare TCP daemon */
	tcp_start();

	/* Drop privileges */
	unix_dropuid0();

	/* Start worker threads */
	work_start();

	/* Stop worker threads */
	work_stop();

	/* Stop TCP daemon */
	tcp_stop();

	mime_free();
	node_free();
	tcp_free();

	work_free();
	conf_free();
	log_free(_log);
	main_free();

	return 0;
}
Example #21
0
File: iso.c Project: RPG-7/reactos
/* Initialise ISO transport data packet */
STREAM
iso_init(int length)
{
	STREAM s;

	s = tcp_init(length + 7);
	s_push_layer(s, iso_hdr, 7);

	return s;
}
Example #22
0
static void
main_thread(void *arg)
{
    tcp_init();

    while(1)
    {
        tcp_input
    }
}
Example #23
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 */
}
Example #24
0
void network_init()
{
	struct ip_addr ipaddr, netmask, gw;

	printf("trying to initialize network...\n");

#ifdef STATS
	stats_init();
#endif /* STATS */

	mem_init();
	memp_init();
	pbuf_init(); 
	netif_init();
	ip_init();
	udp_init();
	tcp_init();
	etharp_init();
	printf("ok now the NIC\n");
	
	if (!netif_add(&netif, &ipaddr, &netmask, &gw, NULL, enet_init, ip_input))
	{
		printf("netif_add failed!\n");
		return;
	}
	
	netif_set_default(&netif);
	
	dhcp_start(&netif);
	
	mftb(&last_tcp);
	mftb(&last_dhcp);
	
	printf("\nWaiting for DHCP");

	int i;	
	for (i=0; i<10; i++) {
		mdelay(500);
		network_poll();
		
		printf(".");
		
		if (netif.ip_addr.addr)
			break;
	}
	
	if (netif.ip_addr.addr) {
		printf("%u.%u.%u.%u\n",	
			(netif.ip_addr.addr >> 24) & 0xFF,
			(netif.ip_addr.addr >> 16) & 0xFF,
			(netif.ip_addr.addr >>  8) & 0xFF,
			(netif.ip_addr.addr >>  0) & 0xFF);
			
		printf("\n");
	} else {
Example #25
0
static void
tcpip_thread(void *arg)
{
  struct tcpip_msg *msg;

  (void)arg;

  ip_init();
#if LWIP_UDP  
  udp_init();
#endif
#if LWIP_TCP
  tcp_init();
#endif
#if IP_REASSEMBLY
  sys_timeout(1000, ip_timer, NULL);
#endif
  if (tcpip_init_done != NULL) {
    tcpip_init_done(tcpip_init_done_arg);
  }

  while (1) {                          /* MAIN Loop */
    sys_mbox_fetch(mbox, (void *)&msg);
    switch (msg->type) {
    case TCPIP_MSG_API:
      LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: API message %p\n", (void *)msg));
      api_msg_input(msg->msg.apimsg);
      break;
    case TCPIP_MSG_INPUT:
      LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: IP packet %p\n", (void *)msg));
      ip_input(msg->msg.inp.p, msg->msg.inp.netif);
      break;
    case TCPIP_MSG_CALLBACK:
      LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: CALLBACK %p\n", (void *)msg));
      msg->msg.cb.f(msg->msg.cb.ctx);
      break;
    default:
      break;
    }
#ifdef VBOX
    if (msg->type == TCPIP_MSG_TERM)
    {
        memp_free(MEMP_TCPIP_MSG, msg);
        break;
    }
#endif
    memp_free(MEMP_TCPIP_MSG, msg);
  }
#ifdef VBOX
  if (tcpip_init_done != NULL) {
    tcpip_init_done(tcpip_init_done_arg);
  }
#endif
}
Example #26
0
int
nptcp_init()
{
   int   i;
   /* total netport buffers:
    * Get twice the number of packet buffers plus 3, to help
    * support UDP. if you are receiving UDP packets faster
    * than your UDP server can process them, its possible for 
    * all of your packet buffers to end up in the UDP socket's 
    * receive queue. each of these packet buffers has associated with 
    * it 2 mbufs, one for the packet buffer itself and one for the 
    * address of the remote host that the packet came from. in order 
    * for this socket queue to get emptied and the receive buffers to 
    * get freed, the socket has to be read and what's the first thing 
    * that soreceive() does to try to do this? it tries to allocate 
    * an mbuf, so if you only have twice as many mbufs as packet 
    * buffers, soreceive() can't complete and the packet buffers stay 
    * on the queue, so we allocate 3 extra mbufs in the hope that 
    * this will allow soreceive() to complete and free up the packet 
    * buffers. yes, its kind of an ugly hack and 3 is a wild guess.
    */
   unsigned bufcount = (lilbufs + bigbufs) * 2 + 3;
   struct mbuf *  m; /* scratch mbuf for mfreeq init */

   MEMSET(&soq, 0, sizeof(soq));    /* Set socket queue to NULLs */
   MEMSET(&mbufq, 0, sizeof(mbufq));
   MEMSET(&mfreeq, 0, sizeof(mfreeq));
   for (i = 0; i < (int)bufcount; i++)
   {
      m = MBU_ALLOC(sizeof(struct mbuf));
      if (!m)  /* malloc error, bail out */
         panic("tcpinit");
      m->m_type = MT_FREE;
      m->m_len = 0;
      m->m_data = NULL;
      putq(&mfreeq, (qp)m);
   }
   mfreeq.q_min = (int)bufcount;   /* this should match q_max and q_len */

#ifdef INCLUDE_SNMP                /* SNMP initialization */
   tcpmib.tcpRtoAlgorithm = 4;     /* Van Jacobson's algorithm */
   tcpmib.tcpRtoMin = TCPTV_MIN * 1000;      /* PR_SLOWHZ */
   tcpmib.tcpRtoMax = TCPTV_REXMTMAX * 1000; /* PR_SLOWHZ */
#endif

   tcp_init();    /* call the BSD init in tcp_usr.c */

#ifdef TCP_MENUS
   install_menu(&tcpmenu[0]);
#endif   /* IN_MENUS */

   return 0;   /* good return */
}
Example #27
0
int main(int argc, char **argv)
{
  char msg[2048] = {0};
  stream_t req, res;
  struct tcp_t *tcp;
  const char * address = "www.google.com";
  const char * port = "80";

  if (argv[1])
    address = argv[1];

  if (argv[2])
    port = argv[2];

  sprintf(msg, "GET / HTTP/1.1\nHost: %s\n\n", address);

  /* allocate and setup io streams*/
  stream_init(&req, 4096);
  stream_init(&res, 4096);

  stream_out_uint8p(&req, msg, strlen(msg));
  stream_mark_end(&req);

  /* initialize tcp */
  tcp_init();

  /* setup tcp and connect*/
  tcp = tcp_new();
  tcp_set_property(tcp, TCP_PROP_ADDRESS, address);
  tcp_set_property(tcp, TCP_PROP_PORT, port);

#ifdef WITH_GNUTLS
  tcp_set_property(tcp, TCP_PROP_USE_TLS, atoi(port) == 443 ? "1" : "0");
#endif

  tcp_connect(tcp);

  /* write http request and recv response */
  tcp_send(tcp, &req);

  tcp_recv(tcp, &res, 4096);

  fprintf(stdout,"%s", res.data);

  tcp_disconnect(tcp);

  tcp_destroy(tcp);

  tcp_deinit();

  return 0;
}
Example #28
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 */
}
Example #29
0
void
lwip_raw_init()
{
	ip_init();	/* Doesn't do much, it should be called to handle future changes. */
#if LWIP_UDP
	udp_init();	/* Clears the UDP PCB list. */
#endif
#if LWIP_TCP
	tcp_init();	/* Clears the TCP PCB list and clears some internal TCP timers. */
			/* Note: you must call tcp_fasttmr() and tcp_slowtmr() at the */
			/* predefined regular intervals after this initialization. */
#endif
}
Example #30
0
/*
 * IP initialization: fill in IP protocol switch table.
 * All protocols not implemented in kernel go to raw IP protocol handler.
 */
void
ip_init(PNATState pData)
{
    int i = 0;
    for (i = 0; i < IPREASS_NHASH; ++i)
        TAILQ_INIT(&ipq[i]);
    maxnipq = 100; /* ??? */
    maxfragsperpacket = 16;
    nipq = 0;
    ip_currid = tt.tv_sec & 0xffff;
    udp_init(pData);
    tcp_init(pData);
}