Ejemplo n.º 1
0
int
station_state(GIO *gio)
{
#ifndef NO_INET_STACK
   NET ifp;
   int i;

   for (i = 0, ifp = (NET)netlist.q_head; ifp; ifp = ifp->n_next, i++)
   {
      gio_printf(gio, "iface %d-%s IP addr:%s  ", 
                      i, ifp->name, print_ipad(ifp->n_ipaddr) );
      gio_printf(gio, "subnet:%s  ", print_ipad(ifp->snmask) );
      gio_printf(gio, "gateway:%s\n", print_ipad(ifp->n_defgw) );
   }
#endif   /* NO_INET_STACK */

   gio_printf(gio, "current tick count: %lu (TPS = %d)\n", CTICKS, TPS);

#ifdef USE_MODEM
   gio_printf(gio, "current dialout number is %s\n", mdm_dial_string);
#endif   /* USE_MODEM */

#ifdef USE_PPP
//   gio_printf(gio, "current dial-in user name is %s\n", username);
//   gio_printf(gio, "current dial-in password is %s\n", password);
#endif   /* USE_PPP */

   return (0);
}
Ejemplo n.º 2
0
int
udp_send_an_echo(UDPCLIENT udpclient)
{
   int   e;

   if ( udpclient->ticks > cticks )  
      return UDPE_TIME_NOT_RIPE ;

   udpclient->ticks += udpclient->delay;  /* Set time for sending next packet*/

   ns_printf(udpclient->pio,"sending UDP echo %ld to %s\n",
    udpclient->send_cnt,print_ipad(udpclient->rhost));

   sprintf(echodata + 17, "%-9lu", udpclient->send_cnt );
   e = t_send(udpclient->sock, echodata, udpclient->len, 0);
   if (e != udpclient->len)
   {
      e = t_errno(udpclient->sock);
      ns_printf(udpclient->pio,"error %d sending UDP echo number %ld\n", e, 
       udpclient->send_cnt );
      ns_printf(udpclient->pio,"UDP Echo Server at %s is possibly shut down\n",
         print_ipad(udpclient->rhost));
      udp_client_del(udpclient);
      return UDPE_ERR_SENDING_ECHO ;
   }

   udpclient->send_cnt ++;
   udpclient->tot_sent ++;

   return SUCCESS;
}
Ejemplo n.º 3
0
/* Callback function for when the Interniche DHCP subsystem acquires
 * an IP address.  This overrides dhc_main_ipset().
 */
int ws_ipset( int iface, int state )
{
  if ( state == DHCS_BOUND )
  {
    /* print IP address acquired through DHCP Client - for user's benefit */
    printf("Acquired IP address via DHCP client for interface: %s\n",
            nets[iface]->name);

    printf("IP address : %s\n", print_ipad(nets[iface]->n_ipaddr));
    printf("Subnet Mask: %s\n", print_ipad(nets[iface]->snmask));
    printf("Gateway    : %s\n", print_ipad(nets[iface]->n_defgw));
  }
  return 0;
}
Ejemplo n.º 4
0
void
icmp_port_du(PACKET p, struct destun * pdp)
{
   dprintf("got ICMP %s UNREACHABLE from %s\n", 
      icmpdu_types[pdp->dtype], print_ipad(p->fhost) );
   dprintf(prompt);
}
Ejemplo n.º 5
0
int
station_state(void * pio)
{
   int i;
   
#ifndef NO_INET_STACK
   NET ifp;

   for (i = 0, ifp = (NET)netlist.q_head; ifp; ifp = ifp->n_next, i++)
   {
      ns_printf(pio, "iface %d-%s IP addr:%s  ", 
       i, ifp->name, print_ipad(ifp->n_ipaddr) );
      ns_printf(pio, "subnet:%s  ", print_ipad(ifp->snmask) );
      ns_printf(pio, "gateway:%s\n", print_ipad(ifp->n_defgw) );
   }
#endif   /* NO_INET_STACK */

   ns_printf(pio, "current tick count %lu\n", cticks);
#ifdef PING_APP
   ns_printf(pio, "ping delay time:  %u ms.\n", pingdelay*56);
   ns_printf(pio, "ping host:        %s\n", print_ipad(activehost));
#endif

#ifdef USE_MODEM
   ns_printf(pio, "current dialout number is %s\n", mdm_dial_string);
#endif   /* USE_MODEM */

#ifdef USE_PPP
   ns_printf(pio, "current dial-in user name is %s\n", pppcfg.username);
   ns_printf(pio, "current dial-in password is %s\n", pppcfg.password);
#endif   /* USE_PPP */

   task_stats(pio);

   return 0;
}
Ejemplo n.º 6
0
char * print46_addr(struct sockaddr *ipaddr)
{
    if (ipaddr->sa_family == AF_INET)
    {
        struct sockaddr_in * addr = (struct sockaddr_in *)ipaddr;
        return print_ipad(addr->sin_addr.s_addr);
    }
#ifdef IP_V6
    else
    {
        struct sockaddr_in6 * addr = (struct sockaddr_in6 *)ipaddr;
        static char namebuf[46];  /* max len of IPv6 addr */
        return (char *)inet_ntop(AF_INET6,&addr->sin6_addr, namebuf, sizeof(namebuf));
    }
#endif

    return NULL;
}
Ejemplo n.º 7
0
const char *
inet_ntop(int af, const void *addr, char *str, size_t size)
{
    char *cp;

#if defined(IP_V4) || defined(MINI_IP)
    if (af == AF_INET)
    {
        u_long   ip4addr;

        ip4addr = *(u_long*)addr;
        cp = print_ipad(ip4addr);
        if (strlen(cp) < size)
        {
            strcpy(str, cp);
            return (str);
        }
    }
#endif   /* IP_V4 */

#ifdef IP_V6
    if (af == AF_INET6)
    {
        char ip6buf[48];

        cp = print_ip6((ip6_addr *)addr, ip6buf);
        if (strlen(cp) < size)
        {
            strcpy(str, ip6buf);
            return (str);
        }
    }
#endif

    return ((const char *)NULL);
}
Ejemplo n.º 8
0
void
tcp_echo_recv(void)
{
   int   len;        /* length of recv data */
   int   e;          /* error holder */
   unsigned i;       /* generic index */
   int   count;      /* select return */
   fd_set fd_recv;   /* fd for recv */
   fd_set fd_accept; /* fd for accept */
   TCPCLIENT tmpclient = tcpq;
   struct sockaddr_in client;
   SOCKTYPE tmpsock; /* scratch socket */

   if (elisten_sock == INVALID_SOCKET && tcpq == NULL)
      return;  /* Echo not set up, don't bother */

#ifdef USE_FDS
   FD_ZERO(&fd_recv);
   FD_ZERO(&fd_accept);
#endif

   /* select on all open data sockets */
   i = 0;
   count = 0;
#ifdef USE_FDS
   while (tmpclient)
   {
      if (tmpclient->sock != INVALID_SOCKET)
      {
         FD_SET(tmpclient->sock, &fd_recv);
         i++;
      }
      tmpclient=tmpclient->next;
   }
#else
   while (tmpclient)
   {
      if (tmpclient->sock != INVALID_SOCKET)
         fd_recv.fd_array[i++] = tmpclient->sock ;
      tmpclient=tmpclient->next;
   }
#endif  /* USE_FDS */

#ifndef TCP_ZEROCOPY
   /* if we need to listen for server receives too */
#ifdef USE_FDS
   if (tcpecho_server && (esvr_sock != INVALID_SOCKET))
   {
      FD_SET(esvr_sock, &fd_recv);
   }
#else
   if (tcpecho_server)
   {
      if (esvr_sock != INVALID_SOCKET)
         fd_recv.fd_array[i++] = esvr_sock;
   }
#endif  /* USE_FDS */
#else
   /* if we need to close the server's active socket */
   if (esvr_sock_close != FALSE)
   {
      if (esvr_sock != INVALID_SOCKET)
      {
         socketclose(esvr_sock);
         esvr_sock = INVALID_SOCKET;
      }
      esvr_sock_close = FALSE;
   }
#endif   /* TCP_ZEROCOPY */

#ifndef USE_FDS
   fd_recv.fd_count = i;
#endif

   /* make this a short timeout since elisten may create soon */
   if (elisten_sock != INVALID_SOCKET)
   {
#ifdef USE_FDS
      FD_SET(elisten_sock, &fd_accept);
#else
      fd_accept.fd_array[0] = elisten_sock;
      fd_accept.fd_count = 1;
#endif  /* USE_FDS */
      count = t_select(&fd_recv, NULL, &fd_accept, 1);
   }
   else 
   {
      if (i)   /* if no fd_set sockets filled in, don't bother */
         count = t_select(&fd_recv, NULL, NULL, 1);
   }

   /* While the t_select() was executing, commands can be 
    * executed from cmd-prompt and sockets can be cleaned up. 
    * Check for that. 
    */
   if (elisten_sock == INVALID_SOCKET && tcpq == NULL)
      return;  /* Echo not set up, don't bother */

   for (i = 0; i < fd_recv.fd_count; i++)
   {
#ifdef USE_FDS
      tmpsock = FD_GET(i, &fd_recv);
      if (tmpsock == INVALID_SOCKET)
         continue;
#else
      tmpsock = fd_recv.fd_array[i];
#endif  /* USE_FDS */

      /* Find out the client connection corresponding to this socket */
      tmpclient = tcp_client_from_sock(tmpsock);

      /* try a receive. Pick buffer according to client or server */
      if (tmpclient)    /* found a client for this one */
         len = recv(tmpsock, tmpclient->inbuf, ECHOBUFSIZE, 0);
#ifndef TCP_ZEROCOPY
      else if (tmpsock == esvr_sock)
         len = recv(tmpsock, srv_inbuf, ECHOBUFSIZE, 0);
#endif   /* TCP_ZEROCOPY */
      else
      {
         continue;
      }

      if (len < 0)
      {
         e = t_errno(tmpsock);
         if (e != EWOULDBLOCK)
         {
            if (tmpsock != esvr_sock)
               ns_printf(tmpclient->pio,"TCP echo recv error %d\n", e);
            else
               ns_printf(NULL,"TCP echo recv error %d\n", e);
         }
      }
      else if (len == 0)
      {
         ns_printf(NULL,"TCPECHO:socket closed by other side\n");
         if (tmpsock == esvr_sock)
         {
            socketclose (tmpsock);
            esvr_sock = INVALID_SOCKET;
         }
         else
         {
            if (tmpclient == NULL)
            {
               dtrap();
            }          
            else
            {
               tmpclient->sock = INVALID_SOCKET ;
               tcp_client_del(tmpclient);
            }
         }
      }
      else  /* if (len > 0) - got some echo data */
      {
#ifndef TCP_ZEROCOPY
         if (tmpsock == esvr_sock)
         {
            /* we must be server, send echo reply */
            if (tcpecho_server)
            {
               e = send(esvr_sock, srv_inbuf, len, 0);
               if (e < 0)
               {
                  /* Print the error to console */
                  e = t_errno(esvr_sock);
                  ns_printf(NULL,
                   "TCP echo server, error %d sending reply\n", e);
               }
            }
         }
         else     /* not the server socket, must be client */
#endif   /* TCP_ZEROCOPY */
         {
            /* If not a bulk test, print info */
            if (tmpclient->len <= ECHOBUFSIZE)
            {
               ns_printf(tmpclient->pio,"TCP echo reply from:%s, len:%d, reply:%lu", 
                print_ipad(tmpclient->rhost), len, tmpclient->replies);
               ns_printf(tmpclient->pio,"\n%s",prompt);
            }
            else
            {
               u_long   dataval;
               u_long * rxbuf =  (u_long*)(tmpclient->inbuf);
               u_long * rxend =  (u_long*)(tmpclient->inbuf +  (len  &  ~3));

               dataval = tmpclient->tot_rcvd/4;

               /* adjust for odd sized previous receives */
               if (tmpclient->tot_rcvd & 3)
               {
                  MEMMOVE(rxbuf, tmpclient->inbuf + (len & 3), len);
                  rxend--;
                  dataval++;     /* ignore sliced word */
               }

               while (rxbuf < rxend)
               {
                  if (*rxbuf != dataval)
                  {
                     ns_printf(tmpclient->pio,
                      "tcp_echo data error; got %lu, expected %lu\n",
                      *rxbuf, dataval);
                  }
                  rxbuf++;
                  dataval++;
               }
            }
            tmpclient->replies++;
            tmpclient->tot_rcvd += len;
         }
      }
   }

   /* if no server listen to poll, return now */
   if (elisten_sock == INVALID_SOCKET)
      return;

#ifdef NOTDEF
   MEMSET(&client, 0, sizeof(client));
   client.sin_family = AF_INET;
   client.sin_addr.s_addr = INADDR_ANY;
   client.sin_port = htons(ECHO_PORT);
#endif

   /* check for received echo connection on server */
   len = sizeof(client);
   tmpsock = accept(elisten_sock, (struct sockaddr*)&client, &len);
   if (tmpsock != INVALID_SOCKET)
   {
      if (esvr_sock == INVALID_SOCKET)
      {
         esvr_sock = tmpsock;
#ifdef TCP_ZEROCOPY
         t_setsockopt(esvr_sock, SOL_SOCKET, SO_CALLBACK, (void*)echo_svr_upcall, 0);
#endif   /* TCP_ZEROCOPY */
      }
      else  /* we already have a connection */
      {
         dprintf("tcpecho: rejected extra connection\n");
         socketclose(tmpsock);   /* refuse to serve another */
      }
   }
}
Ejemplo n.º 9
0
int
tcp_send_an_echo(TCPCLIENT tcpclient)
{
   int   e;
   u_long   total;
   u_long   sendsize;
   u_long   starttime;
   int      block;
   u_long   words;      /* send data word index */
   u_long   dataval;
   u_long   sent  =  0; /* sent in this loop */

   if (tcpclient->ticks > cticks)  
      return TCPE_TIME_NOT_RIPE ;
   if (tcpclient->sending)    /* guard against re-entry */
      return TCPE_BLOCKED;
   tcpclient->sending++;

   ns_printf(tcpclient->pio,"sending TCP echo %ld to %s\n", 
    tcpclient->send_cnt, print_ipad(tcpclient->rhost));

   total = tcpclient->len;
   block = 0;
   starttime = cticks;
   while (total > sent)
   {
      tcpclient->ticks = cticks + tcpclient->delay;   /* back off time for next send */
      sendsize = total - sent;
      if (sendsize > ECHOBUFSIZE)
         sendsize = ECHOBUFSIZE;

      /* write pattern into full-size data for integrity test */
      dataval = (tcpclient->tot_sent + sent)/4;    /* data for first word of buffer */
      for (words = 0; words < (ECHOBUFSIZE/4); words++)
         *((u_long*)tcpclient->inbuf + words) = dataval++;

      e = send(tcpclient->sock, tcpclient->inbuf, (int)sendsize, 0);
      if (e < 0)
      {
         e = t_errno(tcpclient->sock);
         if (e == EWOULDBLOCK)
         {
            tk_yield();
            continue;
         }
         ns_printf(tcpclient->pio,"error %d sending TCP echo number %ld\n", 
            e, tcpclient->send_cnt);
         ns_printf(tcpclient->pio,"   on byte %ld\n", e);

         tcpclient->sending--;
         return TCPE_SEND_FAILED;
      }
      sent += e;
      if ((block += e) >= ECHOBUFSIZE)
      {
         ns_printf(tcpclient->pio, ".");
         block -= ECHOBUFSIZE;
      }
      tk_yield();    /* let other tasks run */
   }

   tcpclient->send_cnt++;  /* keep counters current */
   tcpclient->tot_sent += sent;
   ns_printf(tcpclient->pio, "\ntcpecho: echoed %ld bytes", sent);

   if (total > ECHOBUFSIZE)   /* see if we should print performance numbers */
   {
      u_long   endticks;
      u_long   bps;
      int   fraction;

      /* wait for all data to come back */
      endticks = cticks + (5*TPS);        /* use endticks for timeout */
      while ((tcpclient->tot_rcvd < tcpclient->tot_sent) &&
          (cticks > endticks))
      {
         tk_yield();
      }

      endticks = cticks - starttime;
      if (endticks > 0) /* avoid divide by 0 */
      {
         bps = sent/endticks;    /* bytes per tick */
         bps *= TPS;             /* convert to bytes/Sec */
         bps /= 1024;            /* KBytes/Sec */
         fraction = (int)endticks % TPS;
         endticks /= TPS;
         ns_printf(tcpclient->pio, " in %d and %d/%d seconds.\n%ld KBytes/sec", 
          (int)endticks, fraction, TPS, bps);
      }
   }
   ns_printf(tcpclient->pio, "\n");

   tcpclient->sending--;   /* clear reentry flag */
   return SUCCESS;
}
Ejemplo n.º 10
0
/*
 * FUNCTION: bsd_inet_ntoa()
 *
 * Formats an Internet address into its printable dotted-decimal
 * representation.
 *
 * PARAM1: in; IN - Internet Address (in network order)
 * RETURNS: pointer to null-terminated string containing dotted-decimal
 *          printable representation of in
 */
char *
bsd_inet_ntoa(struct in_addr in)
{
   return print_ipad(in.s_addr);
}
Ejemplo n.º 11
0
void 
netmain_init(void)
{
   int   e;
   int   i;
   char *   msg;
#ifdef IP_V6
   ip6_addr host;
#endif

   printf("\n%s\n", name);
   printf("Copyright 1997-2006 by InterNiche Technologies. All rights reserved. \n");

#ifndef SUPERLOOP
   /* call this to do pre-task setup including intialization of port_prep */
   msg = pre_task_setup();
   if (msg)
      panic(msg);
#endif

#ifdef INCLUDE_NVPARMS     /* system uses InterNiche NV system */
   e = get_nv_params();    /* get flash parameters into data structs */
   if (e)
   {
      printf("fatal error (%d) reading NV parameters.\n", e);
      panic("nv");
   }

   /* set static iface IP info up from stored parameters. These may 
   be overwritten from command line parms or DHCP later. */
   for (i = 0; i < STATIC_NETS; i++)
   {
      netstatic[i].n_ipaddr = inet_nvparms.ifs[i].ipaddr;
      netstatic[i].snmask = inet_nvparms.ifs[i].subnet;
      netstatic[i].n_defgw = inet_nvparms.ifs[i].gateway;
#ifdef IP_MULTICAST
      /* Create a dummy entry for the Ethernet interface mcastlist */
      /* If this entry is set to NULL, multicast is not supported  */
      /* on this interface */
      netstatic[i].n_mcastlist = mcastlist;
#endif   /* IP_MULTICAST */
#ifdef IP_V6
      IP6CPY(&host, &inet_nvparms.ifs[i].ipv6addr);
      if ( (host.addr[0] == 0xFE) && (host.addr[1] == 0xC0))
      {
         netstatic[i].v6addrs[IPA_SITE] = ip6_mkaddr(&netstatic[i], 
            IPA_SITE, &host);
      }
      else if ( (host.addr[0] == 0xFE) && (host.addr[1] == 0x80) )
      {
         printf ("[IPV6 init]error : bad IPV6 address\n");
      }
      else if (host.addr[0] != 0)
      {
         netstatic[i].v6addrs[IPA_GLOBAL] = ip6_mkaddr(&netstatic[i], 
            IPA_GLOBAL, &host );
      }
#endif
   }

#ifdef DNS_CLIENT
   /* set DNS client's server list from nvparms information */
   MEMCPY(dns_servers, inet_nvparms.dns_servers, sizeof(dns_servers));

#ifdef DNS_CLIENT_UPDT
   MEMCPY(soa_mname, inet_nvparms.dns_zone_name, sizeof(soa_mname));
#endif   /* DNS_CLIENT_UPDT */

#endif   /* DNS_CLIENT */

#ifdef USE_COMPORT
   comportcfg.comport = comport_nvparms.comport;
   comportcfg.LineProtocol = comport_nvparms.LineProtocol;
#endif   /* USE_COMPORT */
#endif   /* INCLUDE_NVPARMS */

#ifndef INCLUDE_NVPARMS
#ifdef USE_COMPORT
   comportcfg.comport = 0x01;
   comportcfg.LineProtocol = PPP;   /* Default to PPP */
#endif   /* USE_COMPORT */
#endif   /* INCLUDE_NVPARMS */

   msg = ip_startup();
   if (msg)
   {
      printf("inet startup error: %s\n", msg);
      panic("IP");
   }

#if defined(MEMDEV_SIZE) && defined(VFS_FILES)
   init_memdev(); /* init the mem and null test devices */
#endif

#ifdef IP_MULTICAST
#ifdef INCLUDE_TCP
   /* call the IP multicast test program */
   u_mctest_init();
#endif
#endif  

   /* clear debugging flags. Port can optionally turn them
    * back on in post_task_setup();
    * NDEBUG = UPCTRACE | IPTRACE | TPTRACE ;  
    */
   NDEBUG = 0;    

   /* print IP address of the first interface - for user's benefit */
   printf("IP address of %s : %s\n" , ((NET)(netlist.q_head))->name,
      print_ipad(((NET)(netlist.q_head))->n_ipaddr));
 
#ifndef SUPERLOOP
   /* call this per-target routine after basic tasks & net are up */
   msg = post_task_setup();
   if (msg)
      panic(msg);
#endif

#ifdef PING_APP
   ping_init();
#endif   /* PING_APP */

#ifdef RAWIPTEST
   raw_test_init();
#endif   /* RAWIPTEST */

#if defined(TFTP_CLIENT) || defined(TFTP_SERVER)
   tftp_init();
#endif   /* TFTP */

#ifdef TESTMENU
   install_menu(testmenu);
#endif   /* TESTMENU */

#ifdef USE_AUTOIP
   Upnp_init();      /* start Auto IP before DHCP client */
#endif   /* USE_AUTOIP */

#ifdef DHCP_CLIENT
	if( POWERUP_CONFIG_DHCP_ENABLED )
   		dhc_setup();   /* kick off any DHCP clients */
#endif   /* DHCP_CLIENT */

#ifdef DHCP_SERVER
#ifdef INCLUDE_NVPARMS
   if(dhserve_nvparms.ServeDHCP)
#endif
   {
      e = dhcp_init();
      if(e)
      {
         dprintf("Error %d starting DHCP server.\n",e);
      }
      else
      {
         exit_hook(dhcpsrv_cleanup);
         dprintf("Started DHCP server\n");
      }
   }
#endif /* DHCP_SERVER */

#ifdef IN_MENUS
   printf(prompt);
#endif

#ifdef UDPSTEST
   e=udp_echo_init();
   if ( e == SUCCESS )
   {
      exit_hook(udp_echo_cleanup);
   }
   else
      dprintf("Error %d starting UDP Echo server.\n",e);
#endif

#ifdef RIP_SUPPORT
   e=rip_init();
   if ( e == SUCCESS )
   {
      exit_hook(rip_cleanup);
   }
   else
      dprintf("Error %d starting RIP server.\n",e);
#endif

#ifdef INICHE_SYSLOG
   e =syslog_init();
   if (e == SUCCESS)
      exit_hook(closelog);
   else
      dprintf("Error %d initializing syslog client.\n",e);
#endif

#ifdef FTP_CLIENT
   fc_callback=ftpc_callback;
#endif

/* The following initializations take place when SUPERLOOP is enabled.
 * Otherwise they would be done in the respective task.
 */

#ifdef SUPERLOOP

#ifdef INCLUDE_SNMP
   e = snmp_init();
   if (e == SUCCESS)
      exit_hook(snmp_cleanup);
   else
      dprintf("Error %d initializing SNMP agent.\n",e);
#endif   /* INCLUDE_SNMP */

#ifdef WEBPORT
   e = http_init(); /* start up http server */
   if (e)
      dprintf("Error %d starting HTTP server.\n",e);
#endif   /* WEBPORT */

#ifdef FTP_SERVER
   e = ftps_init();
   if ( e == SUCCESS )
   {
      exit_hook(ftps_cleanup);
   }
   else
      dprintf("Error %d starting FTP server.\n",e);
#endif   /* FTP_SERVER */

#ifdef TELNET_SVR
   e=tel_init();
   if ( e == SUCCESS )
   {
      exit_hook(tel_cleanup);
   }
   else
      dprintf("Error %d starting TELNET server.\n",e);
#endif

#ifdef TCP_ECHOTEST
   e=tcp_echo_init();
   if ( e == SUCCESS )
   {
      exit_hook(tcp_echo_cleanup);
   }
   else
      dprintf("Error %d starting TCP Echo server.\n",e);
#endif
#ifdef TCP_CIPHERTEST
   e=tcp_cipher_init();
   if ( e == SUCCESS )
   {
      exit_hook(tcp_cipher_cleanup);
   }
   else
      dprintf("Error %d starting TCP cipher server.\n",e);
#endif
#ifdef USE_CRYPTOENG
   e = ce_init();
   if(e != 0)
   {
      dprintf("ce_init() failed\n");
      panic("prep_modules");
   }
#endif

#ifdef SMTP_ALERTS
   smtp_init ();
#endif

#endif   /* SUPERLOOP */

   USE_ARG(e);    /* Avoid compiler warnings */
   USE_ARG(i);

} /* end of netmain_init() */
Ejemplo n.º 12
0
void prvMySocketTest(__unused void *params)
{
	// create server socket stuff
	int lSocket;
	struct sockaddr_in sLocalAddr;

	printf("Starting socket test interface.\n");

	lSocket = socket(AF_INET, SOCK_STREAM, 0);
	printf("socket returns %d\n", lSocket);
	if (lSocket < 0) {
		perror("socket");
		return;
	}

	memset((char *)&sLocalAddr, 0, sizeof(sLocalAddr));
	sLocalAddr.sin_family = AF_INET;
	sLocalAddr.sin_len = sizeof(sLocalAddr);
	sLocalAddr.sin_addr.s_addr = 0;
	sLocalAddr.sin_port = htons(23);

	printf("Binding socket\n");
	if (bind(lSocket, (struct sockaddr *)&sLocalAddr, sizeof(sLocalAddr)) < 0) {
		perror("bind");
		close(lSocket);
		return;
	}

	printf("Listening for socket\n");
	if (listen(lSocket, 20) != 0) {
		perror("listen");
		close(lSocket);
	    return;
	}

	while (1) {
		int clientfd;
		struct sockaddr_in client_addr;
		int addrlen = sizeof(client_addr);
		char buffer[1024];
		int nbytes;

		printf("Waiting for new client\n");

		clientfd = accept(lSocket, (struct sockaddr*)&client_addr, (socklen_t*)&addrlen);
		printf("client socket %d connected from %s\n", clientfd, print_ipad(client_addr.sin_addr.s_addr));
		if (clientfd > 0) {
			do {
				nbytes = read(clientfd, buffer, sizeof(buffer));
				if (nbytes > 0)
					write(clientfd, buffer, nbytes);

			}  while (nbytes>0);

			if (!close(clientfd))
				perror("close client");
		}
		else
			perror("accept");
	}

	if (!close(lSocket))
		perror("close server");
}
Ejemplo n.º 13
0
int
ifstats(void * pio, struct net * ifp)
{
   ns_printf(pio, "Interface %s - %s \n", 
      ifp->name, ifp->n_mib->ifDescr);
#ifdef IP_V4
   ns_printf(pio,"IPv4 address: %s, " , print_ipad(ifp->n_ipaddr));
   ns_printf(pio,"subnet mask: %s, ", print_ipad(ifp->snmask));
   ns_printf(pio,"gateway: %s\n"    , print_ipad(ifp->n_defgw));
#endif   /* IP_V4 */
#ifdef IP_V6
   if(ifp->n_flags & NF_IPV6)
   {
      int i;
      char ip6buf[46];     /* tmp buffer for ipv6 address text */

      for(i = 0; i < MAX_V6_ADDRS; i++)
      {
         if(ifp->v6addrs[i])
         {
            ns_printf(pio,"IPv6 %6s addr: %s", v6types[i], 
               print_ip6(&(ifp->v6addrs[i]->addr), ip6buf));
            ns_printf(pio," - %s\n", 
               ip6addrstates[ifp->v6addrs[i]->flags & IA_STATEMASK]);
         }
      }
   }
   else
      ns_printf(pio,"No IPv6 addresses\n");
#endif   /* IP_V6 */
   ns_printf(pio,"Status; Admin:%s Oper:%s for: %s\n", 
      ifp->n_mib->ifAdminStatus==1?"up":"down",
      ifp->n_mib->ifOperStatus==1?"up":"down",
      print_uptime(sysuptime() - (ifp->n_mib->ifLastChange)));
   ns_printf(pio,"rcvd: errors:%lu   dropped:%lu   station:%lu   bcast:%lu   bytes:%lu\n",
      ifp->n_mib->ifInErrors, ifp->n_mib->ifInDiscards,
      ifp->n_mib->ifInUcastPkts, ifp->n_mib->ifInNUcastPkts,
      ifp->n_mib->ifInOctets);
   ns_printf(pio,"sent: errors:%lu   dropped:%lu   station:%lu   bcast:%lu   bytes:%lu\n",
      ifp->n_mib->ifOutErrors, ifp->n_mib->ifOutDiscards,
      ifp->n_mib->ifOutUcastPkts, ifp->n_mib->ifOutNUcastPkts,
      ifp->n_mib->ifOutOctets);
   ns_printf(pio,"MAC address: ");
   hexdump(pio,ifp->n_mib->ifPhysAddress, 6);
   ns_printf(pio," \n");

#ifdef IP_MULTICAST
   /* Print any multicast addresses assign to this iface */
   if(ifp->mc_list)
   {
      struct in_multi * imp;

      ns_printf(pio, "   Multicast addresses: \n");
      for (imp = ifp->mc_list; imp; imp = imp->inm_next)
      {
#ifdef IP_V6
         {
            char ip6buf[40];     /* tmp buffer for ipv6 address text */
            ns_printf(pio, "   %s\n", print_ip6(&(imp->ip6addr), ip6buf));
            continue;
         }
#endif   /* IP_V6 */
         ns_printf(pio, "   %s\n",  print_ipad(imp->inm_addr) );
      }
   }
#endif   /* IP_MULTICAST */


   return 0;
}