home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / hamradio / wattcp.zip / TCPINFO.C < prev    next >
C/C++ Source or Header  |  1992-02-03  |  6KB  |  208 lines

  1. /******************************************************************************
  2.  
  3.     TCPINFO - display configuration info to the screen
  4.  
  5.     Copyright (C) 1991, University of Waterloo
  6.     portions Copyright (C) 1990, National Center for Supercomputer Applications
  7.  
  8.     This program is free software; you can redistribute it and/or modify
  9.     it, but you may not sell it.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but without any warranty; without even the implied warranty of
  13.     merchantability or fitness for a particular purpose.
  14.  
  15.         Erick Engelke                   or via E-Mail
  16.         Faculty of Engineering
  17.         University of Waterloo          Erick@development.watstar.uwaterloo.ca
  18.         200 University Ave.,
  19.         Waterloo, Ont., Canada
  20.         N2L 3G1
  21.  
  22. ******************************************************************************/
  23.  
  24. #include <stdio.h>
  25. #include <stdarg.h>
  26. #include <string.h>
  27. #include <tcp.h>
  28.  
  29. mprintf( char *format, ... )
  30. {
  31.     static linecount = 1;
  32.  
  33.     char buffer[ 512 ];
  34.     char *s, *p, pchar;
  35.     va_list *argptr;
  36.  
  37.     va_start( argptr, format );
  38.     vsprintf( s = buffer, format, argptr );
  39.     va_end( argptr );
  40.  
  41.     do {
  42.     if ( p = strchr( s, '\n' )) {
  43.         pchar = *(++p);
  44.         *p = 0;
  45.     }
  46.  
  47.     fputs( s , stdout );
  48.  
  49.     if ( s = p ) {
  50.         *s = pchar;
  51.         if (++linecount == 24 ) {
  52.         fputs( "<press any key to continue>", stdout);
  53.         getch();
  54.         fputs("\r\r", stdout);
  55.         clreol();
  56.         linecount = 1;
  57.         }
  58.     }
  59.     } while ( s );
  60. }
  61.  
  62.  
  63. int unused = 0;
  64. int extrahelp = 0;
  65. static void (*other)();
  66. static void mine(char *name, char *value)
  67. {
  68.     if ( !extrahelp ) {
  69.     unused = 1;
  70.     return;
  71.     }
  72.  
  73.     if (!unused) {
  74.     unused = 1;
  75.     mprintf("\nSome extra parameters were found in your configuration file.");
  76.     mprintf("These values may be extensions used by applications, but are");
  77.     mprintf("not used by the Waterloo TCP kernal.\n");
  78.     }
  79.     mprintf("   unknown: %s = %s\n", name,value );
  80. }
  81.  
  82. /* undocumented */
  83. extern byte _eth_addr[];
  84. extern word _pktdevclass;
  85. extern word _mss;
  86. extern longword _bootphost;
  87. extern word _bootptimeout;
  88. extern word _bootpon;
  89. extern word _arp_last_gateway;
  90. extern longword _arp_gate_data[];
  91. extern word _last_nameserver;
  92. extern word multihomes;
  93.  
  94.  
  95. char buffer[ 512 ], buf2[512];
  96.  
  97.  
  98. main( int argc, char **argv)
  99. {
  100.     int i;
  101.  
  102.     while ( argc > 1 ) {
  103.     if ( argc == 2 )
  104.         if (!stricmp( argv[ 1 ], "ALL")) {
  105.         extrahelp = 1;
  106.         break;
  107.         }
  108.     mprintf("TCPINFO [ALL]");
  109.     exit( 3 );
  110.     }
  111.  
  112.     mprintf("Reading Waterloo TCP configuration file.\n");
  113.  
  114.     other = usr_init;
  115.     usr_init = mine;
  116.     _survivebootp = 1;    /* needed to not exit if bootp fails */
  117.  
  118.     sock_init();
  119.  
  120.     if ( unused && extrahelp )
  121.     mprintf("\nThat is the end of the extra parameters\n");
  122.  
  123.     switch ( _pktdevclass ) {
  124.     case 1 : mprintf("\nEthernet Address : %hx:%hx:%hx:%hx:%hx:%hx\n",
  125.              _eth_addr[0], _eth_addr[1], _eth_addr[2],
  126.              _eth_addr[3], _eth_addr[4], _eth_addr[5] );
  127.          break;
  128.     case 6 : mprintf("Protocol         : SLIP");
  129.          break;
  130.     }
  131.  
  132.  
  133.     if (multihomes)
  134.         mprintf("\nIP Addresses     : %s - %s\n", inet_ntoa( buf2, gethostid()),
  135.             inet_ntoa( buffer, gethostid()+multihomes));
  136.     else
  137.         mprintf("\nIP Address       : %s\n", inet_ntoa( buffer, gethostid()));
  138.     mprintf("Network Mask     : %s\n\n", inet_ntoa( buffer, sin_mask ));
  139.  
  140.     mprintf("Gateways         : ");
  141.     if ( ! _arp_last_gateway ) mprintf("NONE");
  142.     else mprintf("GATEWAY'S IP     SUBNET           SUBNET MASK\n");
  143.  
  144.     for ( i = 0 ; i < _arp_last_gateway * 3;) {
  145.     printf("                 : %-15s  ", inet_ntoa(buffer,_arp_gate_data[i++] ));
  146.     if ( !_arp_gate_data[i] ) {
  147.         mprintf("DEFAULT\n\r");
  148.         i += 2;
  149.     } else {
  150.         mprintf("%-15s  ", inet_ntoa(buffer,_arp_gate_data[i++]));
  151.         mprintf("%-15s\n", inet_ntoa(buffer,_arp_gate_data[i++]));
  152.     }
  153.     }
  154.     mprintf("\n");
  155.  
  156.     if ( gethostname( NULL, 0 ) ) {
  157.     mprintf("Host name        : %s", gethostname(NULL, 0));
  158.     if ( getdomainname( NULL, 0))
  159.         mprintf(".%s", getdomainname( NULL, 0));
  160.     mprintf("\n");
  161.     }
  162.  
  163.     mprintf("Cookieserver%c    : ", ( _last_cookie < 2 ) ? ' ' : 's');
  164.     if ( !_last_cookie ) mprintf("NONE DEFINED\n");
  165.  
  166.     for ( i = 0 ; i < _last_cookie ; ++i ) {
  167.     if (i) mprintf("                 : ");
  168.     mprintf("%s\n", inet_ntoa( buffer, _cookie[i] ));
  169.     }
  170.     mprintf("\n");
  171.  
  172.     mprintf("Nameserver%c      : ", ( _last_nameserver < 2 ) ? ' ' : 's');
  173.     if ( !_last_nameserver ) mprintf("NONE DEFINED\n\n");
  174.  
  175.     for ( i = 0 ; i < _last_nameserver ; ++i ) {
  176.     if (i) mprintf("                 : ");
  177.     mprintf("%s\n", inet_ntoa( buffer, def_nameservers[i] ));
  178.     }
  179.     mprintf("Domain           : \"%s\"\n\n", getdomainname( NULL, 0));
  180.  
  181.     if (_bootpon || extrahelp ) {
  182.     mprintf("BOOTP            : %s\n", (_bootpon) ? "USED": "NOT USED");
  183.     if (_bootpon) mprintf("                 : %s\n", gethostid() ?
  184.         "SUCCEEDED" : "FAILED" );
  185.  
  186.     mprintf("BOOTP Server     : %s\n", ( _bootphost == 0xffffffffL ) ?
  187.         "BROADCAST" :
  188.         inet_ntoa( buffer, _bootphost ));
  189.     mprintf("BOOTP Timeout    : %i seconds\n\n", _bootptimeout );
  190.     }
  191.  
  192.     if (extrahelp) {
  193.     mprintf("Default Timeout  : %u seconds\n", sock_delay );
  194.     mprintf("Max Seg Size MSS : %u bytes\n\n", _mss );
  195.     debugpsocketlen();
  196.     }
  197.  
  198.     if ( unused && !extrahelp ) {
  199.         mprintf("\nAdditional non-standard parameters were found in your configuration file\n");
  200.         mprintf("If you would like to see them, try the command:\n");
  201.         mprintf("    TCPINFO ALL\n");
  202.     } else if ( !extrahelp ) {
  203.         mprintf("\nAdditional but more obscure information can be found using the command:\n");
  204.         mprintf("    TCPINFO ALL\n");
  205.     }
  206.     exit( 0 );
  207. }
  208.