home *** CD-ROM | disk | FTP | other *** search
/ Atari Forever 4 / Atari Forever 4 / Atari Forever 4.iso / SERIE_AI / AI_017 / INTERNET.TOS / SOFTWARE / NETSTSR / NETSTAT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-29  |  21.4 KB  |  790 lines

  1. /************************************************************************/
  2. /*                                                                      */
  3. /*    netstat.c                                                            */
  4. /*                                                                      */
  5. /*    Durch bloßes Ändern der Extension im Dateinamen, läßt sich Pro-   */
  6. /*    gramm als normale GEM-Anwendung oder aber als Accessory betrei-   */
  7. /*    ben.                                                              */
  8. /*                                                                      */
  9. /*    Copyright (c)  FORTEC/pm 1993                                     */
  10. /*                                                                      */
  11. /************************************************************************/
  12.  
  13. /* -------------------------------------------------------------------- */
  14. /*    Headerdateien einbinden.                                          */
  15. /* -------------------------------------------------------------------- */
  16.  
  17. #include <aes.h>
  18. #include <stdio.h>
  19. #include <tos.h>
  20. #include <vdi.h>
  21. #include <string.h>
  22. #include <stdlib.h>
  23. #include <ctype.h>
  24. #include <time.h>
  25. #include <ext.h>
  26. #include "cookie.h"
  27. #include "tcp.h"
  28. #include "queue.h"
  29. #include "inetcust.h"
  30. #include "udp.h"
  31. #include "tuwtcp.h"
  32. #include "nicmem.h"
  33. #include "pktqueue.h"
  34.  
  35. #define tcp_stat(a,b) gemdos(635,a,b)
  36.  
  37. #define TELNET 23
  38. #define FTP_CTL 21
  39. #define FTP_DATA 20
  40.  
  41. #define NAMESERV_IEN116 42
  42. #define NAMESERV_RFC    53
  43.  
  44. int print_tcb( TCP_TCB *);
  45. int print_udp( UDP_CTL *);
  46. char *pr_state(int);
  47. char *pr_tcpport(int,char*);
  48. char *pr_udpport(int,char*);
  49. void netstat(void);
  50. void print_ipq(PKTQUEUE* q);
  51. char *pr_ipprot(int prot);
  52. void mouse_on(void);
  53. void mouse_off(void);
  54. void print_pktbuf(PKTPOOL * p);
  55.  
  56. typedef struct
  57. {
  58.     long    st_sent;
  59.     long    st_xmiterr;
  60.     long    st_collision;
  61.     long    st_got;
  62.     long    st_received;
  63.     long    st_missed;
  64.     long    st_crc;
  65.     int        st_err;
  66.     int        st_free;
  67.     long    st_intr;
  68. } et_stat;
  69.  
  70. #define LINESIZE 70L
  71. #define NUMLINES 40
  72.  
  73. #define WINW     500
  74. #define WINH     350
  75. #define ZH 6
  76.  
  77. #define mmin(a,b) (((a) < (b)) ? (a) : (b))
  78.  
  79. TCPSTAT tstat;
  80.  
  81. char *myid = "@(#)TUW-Netstat 1.1 pm";
  82.  
  83. int x, y,
  84. kstate,
  85. key,
  86. clicks,
  87. event,
  88. state;
  89. int pipe[8];
  90. int quit;
  91.  
  92. char log_text[NUMLINES][LINESIZE+1];
  93. char text[2*LINESIZE];
  94. int  line_tab[NUMLINES];
  95. int  actline = 0;
  96.  
  97. #define LPR_PORT    515
  98.  
  99. /* -------------------------------------------------------------------- */
  100. /*    Extern definierte globale Variablen.                              */
  101. /* -------------------------------------------------------------------- */
  102. /* Mittels dieser Variablen kann    */
  103. extern int _app;  /* das Programm feststellen, ob es  */
  104. /* als Accessory oder normale App-  */
  105. /* likation gestartet wurde.        */
  106. extern int flag;
  107. extern int fhandle;
  108. extern char path[];
  109. extern long oldgem;
  110. extern long grpgem;
  111.  
  112. /* -------------------------------------------------------------------- */
  113. /*    Globale Variablen.                                                */
  114. /* -------------------------------------------------------------------- */
  115. int get_response(void);
  116. void output1(int o_len, char *o_str);
  117. void output(char *o_str);
  118. void printfile(FILE *fin);
  119. int connect(char * host, int port);
  120. void redraw_window( int all,int x,int y,int w,int h );
  121. int handle_message(int *pipe);
  122. void multi( void );
  123. void event_loop( void );
  124. void spool(void);
  125.  
  126. int  whandle;          /* Handle für geöffnetes Fenster.   */
  127. char title[] = "TUW-Netstat 1.0";  /* Titelzeile des Fensters.         */
  128. int  gl_wchar;        /* Größe und Breite eines Buchsta-  */
  129. int gl_hchar;        /* ben (wichtig falls mit unter-    */
  130. int gl_wbox;        /* schiedlichen Bildschirmauflö-    */
  131. int gl_hbox;          /* sungen gearbeitet wird) bzw.     */
  132.                     /* einer Box.                       */
  133. int  phys_handle;    /* Handles für GEM und VDI.         */
  134. int handle;
  135. int  max_x;            /* Maximale Größe der Arbeitsfläche */
  136. int max_y;
  137. int  appl_id;        /* Identifikationsnummer des Prog.  */
  138. int menu_id;              /* Id.-nummer im Menü 'Desk'.       */
  139.  
  140. int line_height = 8;
  141. int cell_width = 8;
  142.  
  143. int dum;
  144. int x,y,w,h;
  145. int attrib[10];
  146.  
  147. int scroll_log(int actline)
  148. {  /* rotate log lines */
  149.   int i;
  150.   int line;
  151.  
  152.   if(actline < NUMLINES-1) return(actline+1);
  153.   line = line_tab[0];
  154.   for(i=0; i<NUMLINES-1; i++)
  155.   {
  156.     line_tab[i] = line_tab[i+1];
  157.   }
  158.   line_tab[NUMLINES-1] = line;
  159.   return(NUMLINES-1);
  160. }
  161.  
  162. int log(char *str)
  163. {
  164.   int i,ii,ilen;
  165.   char *s;
  166.   int len,inline;
  167.  
  168.   if(!str) return(0);
  169.   len = (int)strlen(str);
  170.   if(str[len-1] == '\r')
  171.   {
  172.     str[len-1] = 0;
  173.     inline = 1;
  174.     len--;
  175.   }
  176.   else inline = 0;
  177.   ilen = 0;
  178.  
  179.   log_text[line_tab[actline]][0] = 0;
  180.   if(!len)
  181.     actline = scroll_log(actline);
  182.   s = log_text[line_tab[actline]];
  183.   while(len > 0)
  184.   {
  185.     for(i=0; i <= LINESIZE; i++)
  186.     {
  187.      if(str[ilen] == '\f')
  188.      {
  189.       ilen++;
  190.       len--;
  191.       for(ii = actline; ii < NUMLINES; ii++)        /* init log table */
  192.       {
  193.         log_text[ii][0] = 0;
  194.       } 
  195.       for(ii = 0; ii < NUMLINES; ii++)
  196.         line_tab[ii] = ii;
  197.       actline = 0;
  198.       s = log_text[line_tab[0]];
  199.       inline = 1;
  200.      }
  201.      else
  202.      {
  203.       *s++ = str[ilen];
  204.      }
  205.       if(!str[ilen])
  206.         break;
  207.       ilen++;
  208.       len--;
  209.     }
  210.     if(!inline) *s=0;
  211.     if(!inline) actline = scroll_log(actline);
  212.     if(!inline) s = log_text[line_tab[actline]];
  213.   }
  214.   return(1);
  215. }
  216.  
  217. void open_window( void )
  218. {
  219.   if(whandle <= 0)
  220.   {
  221.     whandle = wind_create(NAME|CLOSER|MOVER, 0, 0, max_x + 1, max_y + 1 );
  222.     if( whandle <= 0 )
  223.       return;
  224.  
  225.     wind_set(whandle, WF_NAME, title);
  226.     vst_font(handle, 1);  /* auswählen       */
  227.     vst_height(handle, ZH, &dum,&dum,&cell_width,&line_height);  /* set small font   */
  228.     vqt_attributes( handle, attrib );
  229.     vst_alignment(handle, 0, 4, &dum, &dum);
  230.     wind_calc(WC_BORDER, NAME|CLOSER|MOVER , 40, 40, cell_width*LINESIZE, line_height*NUMLINES, &x, &y, &w, &h);
  231.     wind_open(whandle, x,y,w,h+15);
  232.   }
  233.   else
  234.     wind_set( whandle, WF_TOP );
  235. }
  236.  
  237. /* -------------------------------------------------------------------- */
  238. /*    min()                                                             */
  239. /*                                                                      */
  240. /*    Minimum zweier Zahlen berechnen.                                  */
  241. /* -------------------------------------------------------------------- */
  242.  
  243. int min( int a, int b)
  244. {
  245.   if( a > b )
  246.     return( b );
  247.   else
  248.     return( a );
  249. }
  250.  
  251. /* -------------------------------------------------------------------- */
  252. /*    max()                                                             */
  253. /*                                                                      */
  254. /*    Maximum zweier Zahlen bestimmen.                                  */
  255. /* -------------------------------------------------------------------- */
  256.  
  257. int max( int a, int b)
  258. {
  259.   if( a < b )
  260.     return( b );
  261.   else
  262.     return( a );
  263. }
  264.  
  265. /* -------------------------------------------------------------------- */
  266. /*    rc_intersect()                                                    */
  267. /*                                                                      */
  268. /*    Schnittfläche zweier Rechtecke berechnen.                         */
  269. /* -------------------------------------------------------------------- */
  270.  
  271. int rc_intersect(GRECT *r1, GRECT *r2)
  272. {
  273.   int xl, yu, xr, yd;  /* left, upper, right, down */
  274.  
  275.   xl      = max( r2->g_x, r1->g_x );
  276.   yu      = max( r2->g_y, r1->g_y );
  277.   xr      = min( (r2->g_x + r2->g_w), (r1->g_x + r1->g_w) );
  278.   yd      = min( (r2->g_y + r2->g_h), (r1->g_y + r1->g_h) );
  279.  
  280.   r2->g_x = xl;
  281.   r2->g_y = yu;
  282.   r2->g_w = xr - xl;
  283.   r2->g_h = yd - yu;
  284.  
  285.   return( r2->g_w > 0 && r2->g_h > 0 );
  286. }
  287.  
  288. /* -------------------------------------------------------------------- */
  289. /*    mouse_on()                                                        */
  290. /*                                                                      */
  291. /*    Mauszeiger anschalten.                                            */
  292. /* -------------------------------------------------------------------- */
  293.  
  294. void mouse_on(void)
  295.  
  296. {
  297.   graf_mouse( M_ON, (void *)0 );
  298. }
  299.  
  300. /* -------------------------------------------------------------------- */
  301. /*    mouse_off()                                                       */
  302. /*                                                                      */
  303. /*    Mauszeiger ausschalten.                                           */
  304. /* -------------------------------------------------------------------- */
  305.  
  306. void mouse_off(void)
  307. {
  308.   graf_mouse( M_OFF, (void *)0 );
  309. }
  310. /* -------------------------------------------------------------------- */
  311. /*    redraw_window()                                                   */
  312. /*                                                                      */
  313. /*    Fensterinhalt neu zeichnen, nachdem er zuvor aus irgendeinem      */
  314. /*    Grunde zerstört wurde, oder weil das Fenster neu geöffnet wurde.  */
  315. /* -------------------------------------------------------------------- */
  316.  
  317. void redraw_window( int all,int x,int y,int w,int h )
  318. {
  319.   GRECT   box,
  320.   work;
  321.   int     clip[4], r[4];
  322.   int     line,dum;
  323.   int     i,    width,height;
  324.  
  325.   if( whandle <= 0 )  /* Wenn kein Fenster auf ist,    */
  326.     return;  /* braucht auch nicht gezeichnet */
  327.   /* zu werden.                    */
  328.     wind_update(BEG_UPDATE);
  329. /*    mouse_off();*/
  330.  
  331.     vsf_color( handle, 0 );  /* set white fill   */
  332.     vswr_mode( handle, 1 );  /* set replace mode */
  333.     vst_height( handle, 6, &dum,&dum,&width,&height);  /* set small font   */
  334.  
  335.     wind_get( whandle, WF_WORKXYWH, &work.g_x, &work.g_y, &work.g_w, &work.g_h );
  336.     wind_get( whandle, WF_FIRSTXYWH, &box.g_x, &box.g_y, &box.g_w,
  337.     &box.g_h );
  338.  
  339.     while ( box.g_w > 0 && box.g_h > 0 )
  340.     {
  341.       if( rc_intersect( &work, &box ) )
  342.       {
  343.         clip[0] = box.g_x;
  344.         clip[1] = box.g_y;
  345.         clip[2] = box.g_x + box.g_w - 1;
  346.         clip[3] = box.g_y + box.g_h - 1;
  347.  
  348.         vs_clip( handle, 1, clip );
  349.         if( all )
  350.           vr_recfl( handle, clip );
  351.         /* fill rectangle */
  352.  
  353.         for(line=0;line < NUMLINES; line++)
  354.         {
  355.           i = strlen(log_text[line_tab[line]]);
  356.           v_gtext( handle, work.g_x, work.g_y + 15 + (line*height),log_text[line_tab[line]]);
  357.           if(!all)
  358.           {
  359.            r[0] = work.g_x + (width*i);
  360.            r[1] = work.g_y + 15 + (line*height);
  361.            r[2] = r[0] +  ((LINESIZE-i)*width) - 1;
  362.            r[3] = r[1] - height + 1;
  363.            vr_recfl(handle,r);
  364.           }
  365.         }
  366.         vs_clip( handle, 0, clip );
  367.       }
  368.       wind_get( whandle, WF_NEXTXYWH, &box.g_x, &box.g_y, &box.g_w,
  369.       &box.g_h );
  370.     }
  371. /*    mouse_on();*/
  372.     wind_update(END_UPDATE);
  373. }
  374.  
  375. /* -------------------------------------------------------------------- */
  376. /*    handle_message()                                                  */
  377. /*                                                                      */
  378. /*    Auswertung der Ereignisse des Multi-Events bezüglich des Message- */
  379. /*    buffers.                                                          */
  380. /* -------------------------------------------------------------------- */
  381.  
  382. int handle_message(int *pipe)
  383. {
  384.   switch ( pipe[0] )
  385.   {
  386.   case WM_REDRAW:
  387.     if( pipe[3] == whandle )
  388.     {
  389.      mouse_off();
  390.      redraw_window(1,pipe[4], pipe[5], pipe[6], pipe[7]);
  391.      mouse_on();
  392.     }
  393.     break;
  394.  
  395.   case WM_TOPPED:
  396.     if( pipe[3] == whandle )
  397.     wind_set( whandle, WF_TOP );
  398.     break;
  399.  
  400.   case WM_CLOSED:
  401.     if( pipe[3] == whandle )
  402.     {
  403.       wind_close( whandle );
  404.       wind_delete( whandle );
  405.       whandle = 0;
  406.     }
  407.     if( _app )
  408.       return(1);
  409.     break;
  410.  
  411.   case WM_MOVED:
  412.   case WM_SIZED:
  413.     if( pipe[3] == whandle )
  414.       wind_set( whandle, WF_CURRXYWH,  pipe[4], pipe[5],
  415.       pipe[6], pipe[7] );
  416.     break;
  417.  
  418.   case AC_OPEN:
  419.     if( pipe[4] == menu_id )
  420.       open_window();
  421.     break;
  422.  
  423.   case AC_CLOSE:
  424.     if( pipe[3] == menu_id )
  425.       whandle = 0;
  426.     break;
  427.   }
  428.   return(0);
  429. }
  430.  
  431. /* -------------------------------------------------------------------- */
  432. /*    event_loop()                                                      */
  433. /*                                                                      */
  434. /*    Die Multi-Event-Schleife.                                         */
  435. /* -------------------------------------------------------------------- */
  436.  
  437. void event_loop( void )
  438. {
  439.   quit = 0;
  440.   do
  441.   {
  442.     event = evnt_multi( MU_MESAG | MU_TIMER,
  443.     2, 0x1, 1,
  444.     0, 0, 0, 0, 0,
  445.     0, 0, 0, 0, 0,
  446.     pipe,
  447.     1000, 0,
  448.     &x, &y, &state, &kstate, &key, &clicks );
  449.  
  450.     if( event & MU_TIMER)
  451.     {
  452.      netstat();
  453.     }
  454.  
  455.     if( event & MU_MESAG)
  456.       quit = handle_message( pipe );
  457.  
  458.   }
  459.   while (!quit);
  460. }
  461.  
  462. /* -------------------------------------------------------------------- */
  463. /*    main()                                                            */
  464. /*                                                                      */
  465. /*    Kernstück des Programms.                                          */
  466. /* -------------------------------------------------------------------- */
  467.  
  468. int main( void )
  469. {
  470.   int i;
  471.   int work_in[11];
  472.   int work_out[57];
  473.  
  474.   /* ----------------------------------------------------------------- */
  475.   /* Initialization                                                    */
  476.   /* ----------------------------------------------------------------- */
  477.  
  478.   appl_id = appl_init();
  479.   if( appl_id != -1 )
  480.   {
  481.     for (i = 0; i < 10; i++)
  482.       work_in[i]  = 1;
  483.     work_in[10] = 2;
  484.     phys_handle = graf_handle( &gl_wchar, &gl_hchar, &gl_wbox,
  485.     &gl_hbox );
  486.     whandle = 0;
  487.     handle = phys_handle;
  488.     v_opnvwk( work_in, &handle, work_out );
  489.     for(i=0; i< NUMLINES; i++)        /* init log table */
  490.     {
  491.         line_tab[i] = i;
  492.         log_text[i][0] = 0;
  493.     }
  494.     actline = 0;
  495.     if( handle != 0 )
  496.     {
  497.       max_x = work_out[0];
  498.       max_y = work_out[1];
  499.  
  500.       if( !_app )
  501.       {
  502.         menu_id = menu_register( appl_id, "  Netstat" );
  503.         /*open_window();*/
  504.       }
  505.       else
  506.       {
  507.         graf_mouse( 0, (void*)0 );
  508.         open_window();
  509.       }
  510.       /* ----------------------------------------------------------------- */
  511.       /* Event Loop                                                        */
  512.       /* ----------------------------------------------------------------- */
  513.  
  514.       event_loop();
  515.  
  516.       /* ----------------------------------------------------------------- */
  517.       /* Deinitialization                                                  */
  518.       /* ----------------------------------------------------------------- */
  519.  
  520.       v_clsvwk( handle );
  521.     }
  522.     appl_exit();
  523.   }
  524.   return(0);
  525. }
  526.  
  527. /* -------------------------------------------------------------------- */
  528. /*    End of NETSTAT.C                                                     */
  529. /* -------------------------------------------------------------------- */
  530.  
  531. void netstat()
  532. {
  533. COOKIE     *cookie;
  534. long (**tmp)(long,char*);
  535. INETSTAT *pi;
  536. et_stat statusblock;
  537. TCP_TCB *tcb_list;
  538. PKTQUEUE *q;
  539. UDP_CTL *udp_list;
  540.  
  541.   log("\f");
  542.   cookie = get_cookie(PKTCOOKIE);
  543.   if(!cookie || !cookie->val)
  544.   {
  545.     log("Packetdriver not installed");
  546.   }
  547.   else
  548.   {
  549.    tmp = (int(**)(long,char*))(cookie->val);
  550.    log("Packet driver statistics:");
  551.    log("-------------------------");
  552.  
  553.    (tmp[NETINFO])(sizeof(statusblock),(char*)&statusblock);
  554.  
  555.    sprintf(text,"%8ld packets sent",statusblock.st_sent);
  556.    log(text);
  557.    sprintf(text,"%8ld xmit errors",statusblock.st_xmiterr);
  558.    log(text);
  559.    sprintf(text,"%8ld collisions",statusblock.st_collision);
  560.    log(text);
  561.    sprintf(text,"%8ld packets got",statusblock.st_got);
  562.    log(text);
  563.    sprintf(text,"%8ld packets received",statusblock.st_received);
  564.    log(text);
  565.    sprintf(text,"%8ld packets missed",statusblock.st_missed);
  566.    log(text);
  567.    sprintf(text,"%8ld crc errors",statusblock.st_crc);
  568.    log(text);
  569.    sprintf(text,"%7xx general status",statusblock.st_err);
  570.    log(text);
  571.    sprintf(text,"%8d packets free",statusblock.st_free);
  572.    log(text);
  573.    sprintf(text,"%8ld interrupts processed",statusblock.st_intr);
  574.    log(text);
  575.   }
  576.   cookie = get_cookie(INETCOOKIE);
  577.   if(!cookie)
  578.   {
  579.     log("TUW-TCP not installed");
  580.   }
  581.   else
  582.   {
  583.    log(" ");
  584.    log("Active connections:");
  585.    log("--------------------");
  586.    pi = (INETSTAT*)(cookie->val);
  587. /* Original:
  588.    tcb_list = *(pi->tcpcb_list);
  589. Patch: */
  590.    tcb_list = pi->tcpcb_list==NULL ? NULL : *(pi->tcpcb_list);
  591.    log("hndl  local                        |-----  buffers  -----|");
  592.    log("  A/P port    foreign host.port     send/size   recv/size   state");
  593.    log("-------------------------------------------------------------------");
  594.    log("TCP:");
  595.    while(tcb_list)
  596.    {
  597.       print_tcb(tcb_list);
  598.       tcb_list = tcb_list->next;
  599.    }
  600.    udp_list = *(pi->udp_list);
  601.    log("UDP:");
  602.    while(udp_list)
  603.    {
  604.       print_udp(udp_list);
  605.       udp_list = udp_list->next;
  606.    }
  607.    log(" ");
  608.    log("Protocol statistics recv/sent:");
  609.    log("------------------------------");
  610.    log("       ARP             ICMP            UDP             TCP ");
  611.    sprintf(text," %7ld/%-7ld %7ld/%-7ld %7ld/%-7ld %7ld/%-7ld",
  612.    pi->arp_counts[0], pi->arp_counts[1],
  613.    pi->icmp_counts[0], pi->icmp_counts[1],
  614.    pi->udp_counts[0], pi->udp_counts[1],
  615.    pi->tcp_counts[0], pi->tcp_counts[1]);
  616.    log(text);
  617.    q = (PKTQUEUE*)(**((long***)(cookie->val)+2));
  618.    log(" ");
  619.    log("IP-buffer statistics:");
  620.    log("---------------------");
  621.    print_ipq(q);
  622. /*   
  623.    log(" ");
  624.    log("pktbuffer statistics:");
  625.    log("---------------------");
  626.    print_pktbuf( (PKTPOOL *)(tmp[NETINFO])(0L,(char*)2L));*/
  627.   }
  628.   redraw_window(0,0,0,0,0);
  629. }
  630.  
  631. void print_pktbuf(PKTPOOL * p)
  632. {
  633.   int i;
  634.   char str2[200];
  635.   str2[0]=0;
  636.   sprintf(str2,"%2d-%2d ",p->p_get,p->p_put);
  637.   for(i=0;i<p->p_nbuf;i++)
  638.   {
  639.     sprintf(str2,"%s x%04x:%02x",str2,p->p_tab[i].p_occupied,(ip_head((p->p_tab[i].p_pkt)))->protocol);
  640.   }
  641.     log(str2);
  642. }
  643.  
  644. void print_ipq(PKTQUEUE* q)
  645. {
  646. PACKET *pq;
  647. register IP     *ip;
  648. int i;
  649.  
  650.   for(i=0;i<q->q_nbuf;i++)
  651.   {
  652.     if(q->q_tab[i].q_occupied)
  653.     {
  654.       pq = (q->q_tab[i].q_pkt);
  655.       if(pq)
  656.       {
  657.        ip = ip_head(pq);
  658.        sprintf(text,"%6s from %3ld.%3ld.%3ld.%3ld (to %3ld.%3ld.%3ld.%3ld)",
  659.             pr_ipprot((int)ip->protocol),
  660.             ((ip->src_inaddr) >> 24) & 0xff,/* address of foreign host */
  661.             ((ip->src_inaddr) >> 16) & 0xff,/* address of foreign host */
  662.             ((ip->src_inaddr) >> 8) & 0xff,/* address of foreign host */
  663.             ((ip->src_inaddr)) & 0xff,/* address of foreign host */
  664.             ((ip->dst_inaddr) >> 24) & 0xff,
  665.             ((ip->dst_inaddr) >> 16) & 0xff,
  666.             ((ip->dst_inaddr) >> 8) & 0xff,
  667.             ((ip->dst_inaddr)) & 0xff);
  668.             log(text);
  669.       }
  670.     }
  671.   }
  672. }
  673.  
  674. char *pr_ipprot(int prot)
  675. {
  676. static char portstr[10];
  677.     
  678.     switch(prot)
  679.     {
  680.         case IP_ICMP:
  681.             return("ICMP");
  682.             
  683.         case IP_GGP:
  684.             return("GGP");
  685.             
  686.         case IP_ST:
  687.             return("ST");
  688.  
  689.         case IP_TCP:
  690.             return("TCP");
  691.             
  692.         case IP_UDP:
  693.             return("UDP");
  694.             
  695.         default:
  696.             return(itoa(prot,portstr,10));
  697.     }
  698. }
  699.  
  700. int print_tcb(TCP_TCB *tcb_list)
  701. {
  702. char str1[10],str2[10];
  703.  
  704. sprintf(text,"%2d %c %6s %3ld.%3ld.%3ld.%3ld.%6s %5lu/%-5lu %5lu/%-5lu %s",
  705.             tcb_list->handle,
  706.             tcb_list->active ? 'A' : 'P',    /* this connection is active/listening only */
  707.             pr_tcpport(tcb_list->lcl_port,str1),    /* my portnumber */
  708.             ((tcb_list->fhost) >> 24) & 0xff,/* address of foreign host */
  709.             ((tcb_list->fhost) >> 16) & 0xff,/* address of foreign host */
  710.             ((tcb_list->fhost) >> 8) & 0xff,/* address of foreign host */
  711.             ((tcb_list->fhost)) & 0xff,/* address of foreign host */
  712.             pr_tcpport(tcb_list->fgn_port,str2),    /* portnumber of foreign host */
  713.             q_used(&tcb_list->q_out),        /* output queue */
  714.             tcb_list->q_out.size-1,
  715.             q_used(&tcb_list->q_in),        /* input queue */
  716.             tcb_list->q_in.size-1,
  717.             pr_state(tcb_list->state));        /* statusblocke of transmission */
  718. log(text);
  719.     return(0);
  720. }
  721.  
  722. int print_udp(UDP_CTL *udp_list)
  723. {
  724. char str1[10],str2[10];
  725.  
  726. sprintf(text,"%2d U %6s %3ld.%3ld.%3ld.%3ld.%6s                 %-5u",
  727.             udp_list->handle,
  728.             pr_udpport(udp_list->lcl_port,str1),    /* my portnumber */
  729.             ((udp_list->fhost) >> 24) & 0xff,/* address of foreign host */
  730.             ((udp_list->fhost) >> 16) & 0xff,/* address of foreign host */
  731.             ((udp_list->fhost) >> 8) & 0xff,/* address of foreign host */
  732.             ((udp_list->fhost)) & 0xff,/* address of foreign host */
  733.             pr_udpport(udp_list->fgn_port,str2),    /* portnumber of foreign host */
  734.             udp_list->data_len);
  735. log(text);
  736.     return(0);
  737. }
  738.  
  739. char *pr_tcpport(int port, char portstr[10])
  740. {
  741.     switch(port)
  742.     {
  743.         case FTP_CTL:
  744.             return("ftpctl");
  745.             
  746.         case FTP_DATA:
  747.             return("ftpdta");
  748.             
  749.         case TELNET:
  750.             return("telnet");
  751.             
  752.         default:
  753.             return(ultoa(((unsigned long)port & 0xFFFF),portstr,10));
  754.     }
  755. }
  756. char *pr_udpport(int port,char portstr[10])
  757. {
  758.     
  759.     switch(port)
  760.     {
  761.         case NAMESERV_IEN116:
  762.             return("NAMIEN");
  763.             
  764.         case NAMESERV_RFC:
  765.             return("NAMRFC");
  766.             
  767.         default:
  768.             return(ultoa(((unsigned long)port & 0xFFFF),portstr,10));
  769.     }
  770. }
  771.  
  772. char *pr_state(int state)
  773. {
  774. static char *states[11]=
  775. {
  776.  "CLOSED",
  777.  "LISTEN",
  778.  "SYNSENT",
  779.  "SYNREC",
  780.  "ESTABLISHED",
  781.  "FINWAIT1",
  782.  "FINWAIT2",
  783.  "CLOSEWAIT",
  784.  "CLOSING",
  785.  "LASTACK",
  786.  "TIMEWAIT"
  787. };
  788.     return(states[state]);
  789. }
  790.