home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / NETTOOLS.ZIP / InetThread.cpp next >
Encoding:
C/C++ Source or Header  |  1997-12-30  |  36.3 KB  |  1,752 lines

  1. // InetThread.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "nettools.h"
  6. #include <snmp.h>
  7. #include <winsock.h>
  8. #include "InetThreadParms.h"
  9. #include "InetThread.h"
  10.  
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. struct TCPStates
  18. {
  19.     CHAR state[12];
  20. };
  21.  
  22. struct TCPStates StateTable[12] =
  23. {
  24.     {"Closed     "},
  25.     {"Listen     "},
  26.     {"SynSent    "},
  27.     {"SynReceived"},
  28.     {"Established"},
  29.     {"FinWait1   "},
  30.     {"FinWait2   "},
  31.     {"CloseWait  "},
  32.     {"LastAck    "},
  33.     {"Closing    "},
  34.     {"TimeWait   "},
  35.     {"DeleteTCB  "}
  36. };
  37.  
  38. //typedef BOOL (CALLBACK* SEQUERY)(BYTE,RFC1157VarBindList*,AsnInteger*,AsnInteger*);
  39. //typedef BOOL (CALLBACK* SEINIT)(DWORD,HANDLE*,AsnObjectIdentifier*);
  40.  
  41.  
  42. //WSADATA Inetwsad;
  43. //HANDLE snmpevent = NULL;
  44. //SEINIT SnmpExtensionInit;
  45. //SEQUERY SnmpExtensionQuery;
  46. //HINSTANCE inetdll;
  47.  
  48. UINT CInetThreadProc(LPVOID pParam)
  49. {
  50.     CInetThreadParms *lpInetParms;
  51.     CInetThread *mythread;
  52.  
  53.     lpInetParms = (CInetThreadParms*)pParam;
  54.     mythread = (CInetThread*)lpInetParms->m_mythread;
  55.  
  56.     while (TRUE)
  57.     {
  58.  
  59.     
  60.     
  61.  
  62.         // Wait until the main application thread asks this thread to do
  63.         //      another calculation.
  64.         if (WaitForSingleObject(lpInetParms->m_hEventStartInet,
  65.                                 INFINITE) != WAIT_OBJECT_0)
  66.             break;
  67.  
  68.         // Exit the thread if the main application sets the "kill recalc"
  69.         // event. The main application will set the "start recalc" event
  70.         // before setting the "kill recalc" event.
  71.  
  72.         if (WaitForSingleObject(lpInetParms->m_hEventKillInet, 0)
  73.             == WAIT_OBJECT_0)
  74.             break; // Terminate this thread by existing the proc.
  75.  
  76.         // Reset event to indicate "not done", that is, recalculation is in progress.
  77.         //ResetEvent(lpInetParms->m_hEventInetDone);
  78.  
  79.     
  80.         mythread->RunInet(lpInetParms);
  81.             
  82.  
  83.         // Set event to indicate that recalculation is done (i.e., no longer in progres),
  84.         // even if perhaps interrupted by "kill recalc" event detected in the SlowAdd function.
  85.         SetEvent(lpInetParms->m_hEventInetDone);
  86.  
  87.         //if (!bPingThreadComplete)  // If interrupted by kill then...
  88.         //    break; // terminate this thread by exiting the proc.
  89.  
  90.         ::PostMessage(lpInetParms->m_hwndNotifyInetDone,
  91.             WM_USER_INET_DONE, 0, (LONG)lpInetParms);
  92.     }
  93.  
  94.     //if (!bPingThreadComplete)
  95.     
  96.     SetEvent(lpInetParms->m_hEventInetDead);
  97.  
  98.     return 0;
  99. }
  100.  
  101. /////////////////////////////////////////////////////////////////////////////
  102. // CInetThread
  103.  
  104. IMPLEMENT_DYNCREATE(CInetThread, CWinThread)
  105.  
  106. CInetThread::CInetThread()
  107. {
  108. }
  109.  
  110. CInetThread::CInetThread(CInetThreadParms *inetparms)
  111. {
  112.     
  113.     inetparms->m_mythread = this;
  114.     m_bAutoDelete = FALSE;
  115.     m_pfnThreadProc = CInetThreadProc;
  116.     m_pThreadParams = inetparms;
  117.  
  118. }
  119.  
  120. CInetThread::~CInetThread()
  121. {
  122. }
  123.  
  124. BOOL CInetThread::InitInstance()
  125. {
  126.     WSADATA Inetwsad;
  127.     // TODO:  perform and per-thread initialization here
  128.     inetdll = LoadLibrary("INETMIB1.DLL");
  129.     if(!inetdll)
  130.     {
  131.         
  132.         return FALSE;
  133.     }
  134.     
  135.     
  136.     SnmpExtensionQuery = (SEQUERY)GetProcAddress(inetdll,"SnmpExtensionQuery");
  137.     SnmpExtensionInit = (SEINIT)GetProcAddress(inetdll,"SnmpExtensionInit");
  138.  
  139.       if (SnmpExtensionQuery == NULL || SnmpExtensionInit == NULL)
  140.         return FALSE;
  141.  
  142.  
  143.     
  144.     AsnObjectIdentifier mview;
  145.     DWORD mtime;
  146.     mtime = GetCurrentTime();
  147.     snmpevent = NULL;
  148.     BOOL rc;
  149.     rc = (*SnmpExtensionInit)(mtime,&snmpevent,&mview);
  150.     if (!rc)
  151.     {
  152.         
  153.         return FALSE;
  154.     }
  155.  
  156.     WSAStartup(0x0101,&Inetwsad);
  157.     return TRUE;
  158. }
  159.  
  160. int CInetThread::ExitInstance()
  161. {
  162.     // TODO:  perform any per-thread cleanup here
  163.     return CWinThread::ExitInstance();
  164. }
  165.  
  166. BEGIN_MESSAGE_MAP(CInetThread, CWinThread)
  167.     //{{AFX_MSG_MAP(CInetThread)
  168.         // NOTE - the ClassWizard will add and remove mapping macros here.
  169.     //}}AFX_MSG_MAP
  170. END_MESSAGE_MAP()
  171.  
  172. /////////////////////////////////////////////////////////////////////////////
  173. // CInetThread message handlers
  174.  
  175. BOOL CInetThread::Start()
  176. {
  177.     BOOL rc = TRUE;
  178.     bKill = FALSE;
  179.     rc = CreateThread();
  180.     if (!rc)
  181.         return rc;
  182.  
  183.     rc = InitInstance();
  184.     if (!rc)
  185.         return rc;
  186.  
  187.     return rc;
  188.     
  189.  
  190. }
  191.  
  192. BOOL CInetThread::RunInet(CInetThreadParms *inetparms)
  193. {
  194.     //
  195.     // setup default tabs. some routines will change as needed
  196.     //
  197.  
  198.     
  199.     
  200.     bKill = FALSE;
  201.     
  202.     if (inetparms->allopts)
  203.     {
  204.         inetparms->connections = TRUE;
  205.         inetparms->icmpstats = TRUE;
  206.         inetparms->ifstats = TRUE;
  207.         inetparms->ipstats = TRUE;
  208.         inetparms->routtable = TRUE;
  209.         inetparms->tcpstats = TRUE;
  210.         inetparms->udpstats = TRUE;
  211.     }
  212.  
  213.     INT Tabs1[7]  = {32,32,32,32,32,32,32};
  214.     
  215.  
  216.     ::SendMessage(inetparms->m_hwndNotifyInetDone,
  217.                 WM_USER_INET_TABS, 0, (LONG)Tabs1);
  218.  
  219.  
  220.     if (inetparms->connections)
  221.         DoConnections(inetparms);
  222.     
  223.     if (bKill)
  224.         return TRUE;
  225.  
  226.     if(inetparms->routtable)
  227.         DoRouteTable(inetparms);
  228.  
  229.     if (bKill)
  230.         return TRUE;
  231.  
  232.     INT Tabs[7]  = {100,100,100,100,100,100,100};
  233.     ::SendMessage(inetparms->m_hwndNotifyInetDone,
  234.                 WM_USER_INET_TABS, 0, (LONG)Tabs);
  235.  
  236.     if(inetparms->icmpstats)
  237.         DoIcmpStats(inetparms);
  238.  
  239.     if (bKill)
  240.         return TRUE;
  241.  
  242.     if(inetparms->ifstats)
  243.         DoIfStats(inetparms);
  244.  
  245.     if (bKill)
  246.         return TRUE;
  247.  
  248.     if(inetparms->ipstats)
  249.         DoIpStats(inetparms);
  250.  
  251.     if (bKill)
  252.         return TRUE;
  253.  
  254.  
  255.     if(inetparms->tcpstats)
  256.         DoTcpStats(inetparms);
  257.  
  258.     if (bKill)
  259.         return TRUE;
  260.  
  261.     if(inetparms->udpstats)
  262.         DoUdpStats(inetparms);
  263.  
  264.     
  265.  
  266.     return TRUE;
  267.  
  268.  
  269.  
  270.  
  271. }
  272.  
  273. void CInetThread::Free_Var(RFC1157VarBind *var)
  274. {
  275.         // For NT we must SnmpMemFree the name and value.
  276.   // for 95 the name we allocated ourselves, and the value
  277.   // is static
  278.   SnmpUtilMemFree(var->name.ids);
  279.     // Free the mem block in the value bit depending on what it is...
  280.   switch(var->value.asnType)
  281.   {
  282.     case ASN_SEQUENCE:
  283.     case ASN_OCTETSTRING:
  284.     case ASN_RFC1155_IPADDRESS:
  285.     case ASN_RFC1155_OPAQUE:
  286.       // AsnOctetString is the base type for all the complex types.
  287.     if(var->value.asnValue.string.dynamic)
  288.         SnmpUtilMemFree(var->value.asnValue.string.stream);
  289.   }
  290.   
  291.  
  292. }
  293.  
  294. void CInetThread::Make_Oid(AsnObjectIdentifier* dst,UINT n, UINT* src)
  295. {
  296.             // Fill in the length
  297.     dst->idLength = n;
  298.     dst->ids = NULL;
  299.     dst->ids = (UINT*)SnmpUtilMemAlloc(sizeof(UINT)*n);
  300.     CopyMemory(dst->ids,src,sizeof(UINT)*n);
  301.  
  302. }
  303.  
  304. BOOL CInetThread::DoConnections(CInetThreadParms *inetparms)
  305. {
  306.     int requestType;
  307.     AsnInteger errorStatus;
  308.     AsnInteger errorIndex;
  309.     UINT ids_tcpconn[8] = {1,3,6,1,2,1,6,13};
  310.     UINT ids_udpconn[8] = {1,3,6,1,2,1,7,5};
  311.     AsnObjectIdentifier saveobj;
  312.     RFC1157VarBind Getnextlist[1];
  313.     RFC1157VarBindList Getnextbindlist = {Getnextlist,1};
  314.     
  315.     
  316.  
  317.     BOOL rc;
  318.     CHAR textbuf[255];
  319.  
  320.     
  321.     // pick up all the tcp connections
  322.     Make_Oid(&Getnextlist[0].name,8,ids_tcpconn);
  323.  
  324.     Getnextlist[0].value.asnType = ASN_NULL;
  325.    
  326.       
  327.     requestType = ASN_RFC1157_GETNEXTREQUEST;
  328.  
  329.     strcpy(textbuf,"Connection Information");
  330.     PrintLine(inetparms,textbuf);
  331.     PrintLine(inetparms,":");
  332.  
  333.     strcpy(textbuf,
  334.     "Proto     Local Address\tForeign Address\tState");
  335.     PrintLine(inetparms,textbuf);
  336.  
  337.    
  338.     while(1)
  339.     {
  340.  
  341.         
  342.         rc = (*SnmpExtensionQuery)(requestType, &Getnextbindlist,
  343.                            &errorStatus, &errorIndex);
  344.  
  345.         if (!rc)
  346.  
  347.             {
  348.             // The API is indicating an error.
  349.             wsprintf(textbuf,"SNMP Error Status = %d Index = %d",
  350.                         errorStatus,errorIndex);
  351.  
  352.             PrintLine(inetparms,textbuf);
  353.  
  354.             break;
  355.             }
  356.         else
  357.             {
  358.             // The API succeeded, errors may be indicated from the remote
  359.             // agent.
  360.  
  361.  
  362.             // Test for end of subtree or end of MIB.
  363.  
  364.             if (errorStatus == SNMP_ERRORSTATUS_NOSUCHNAME)
  365.             {
  366.             
  367.                 break;
  368.             }
  369.             
  370.             if (Getnextlist[0].value.asnType == 
  371.                 ASN_RFC1155_IPADDRESS)
  372.             {
  373.                 
  374.                 break;
  375.  
  376.             }
  377.  
  378.  
  379.  
  380.             // Test for general error conditions or sucesss.
  381.  
  382.             if (errorStatus > 0)
  383.             {
  384.                 wsprintf(textbuf,"SNMP Error Status = %d Index = %d",
  385.                         errorStatus,errorIndex);
  386.  
  387.                 PrintLine(inetparms,textbuf);
  388.             
  389.                 break;
  390.             }
  391.             else
  392.             {
  393.                 PrintConnInfo(inetparms,
  394.                               &Getnextlist[0].name,
  395.                               "TCP");
  396.                 
  397.             }
  398.  
  399.         } // end if
  400.  
  401.  
  402.         if (bKill)
  403.         {
  404.             Free_Var(&Getnextlist[0]);
  405.             PrintLine(inetparms,"Netstat Interupt!");
  406.             return TRUE;
  407.             break;
  408.         }
  409.         SnmpUtilOidCpy(&saveobj,&Getnextlist[0].name);
  410.                      
  411.         Free_Var(&Getnextlist[0]);
  412.     
  413.         Make_Oid(&Getnextlist[0].name,saveobj.idLength,saveobj.ids);    
  414.         
  415.  
  416.         Getnextlist[0].value.asnType = ASN_NULL;
  417.         SnmpUtilOidFree(&saveobj);
  418.     
  419.         
  420.     } // end while()
  421.  
  422.     // get all UDP Connections
  423.  
  424.     Make_Oid(&Getnextlist[0].name,8,ids_udpconn);
  425.  
  426.     Getnextlist[0].value.asnType = ASN_NULL;
  427.    
  428.       
  429.     requestType = ASN_RFC1157_GETNEXTREQUEST;
  430.  
  431.     
  432.     while(1)
  433.     {
  434.  
  435.         
  436.         rc = (*SnmpExtensionQuery)(requestType, &Getnextbindlist,
  437.                            &errorStatus, &errorIndex);
  438.  
  439.         if (!rc)
  440.  
  441.             {
  442.             // The API is indicating an error.
  443.  
  444.             wsprintf(textbuf,"SNMP Error Status = %d Index = %d",
  445.                         errorStatus,errorIndex);
  446.  
  447.             PrintLine(inetparms,textbuf);
  448.  
  449.             break;
  450.             }
  451.         else
  452.             {
  453.             // The API succeeded, errors may be indicated from the remote
  454.             // agent.
  455.  
  456.  
  457.             // Test for end of subtree or end of MIB.
  458.  
  459.             if (errorStatus == SNMP_ERRORSTATUS_NOSUCHNAME)
  460.             {
  461.             
  462.                 break;
  463.             }
  464.             
  465.             if (Getnextlist[0].value.asnType == ASN_INTEGER)
  466.             {
  467.                 
  468.                 break;
  469.  
  470.             }
  471.  
  472.  
  473.  
  474.             // Test for general error conditions or sucesss.
  475.  
  476.             if (errorStatus > 0)
  477.             {
  478.                 wsprintf(textbuf,"SNMP Error Status = %d Index = %d",
  479.                         errorStatus,errorIndex);
  480.  
  481.                 PrintLine(inetparms,textbuf);
  482.             
  483.                 break;
  484.             }
  485.             else
  486.             {
  487.                 PrintConnInfo(inetparms,
  488.                     &Getnextlist[0].name,"UDP");
  489.                 
  490.             }
  491.  
  492.         } // end if
  493.  
  494.         if (bKill)
  495.         {
  496.             Free_Var(&Getnextlist[0]);
  497.             PrintLine(inetparms,"Netstat Interupt!");
  498.             return TRUE;
  499.             break;
  500.         }
  501.         SnmpUtilOidCpy(&saveobj,&Getnextlist[0].name);
  502.                      
  503.         Free_Var(&Getnextlist[0]);
  504.     
  505.         Make_Oid(&Getnextlist[0].name,saveobj.idLength,saveobj.ids);    
  506.         
  507.  
  508.         Getnextlist[0].value.asnType = ASN_NULL;
  509.         SnmpUtilOidFree(&saveobj);
  510.     
  511.         
  512.     } // end while()
  513.  
  514.     PrintLine(inetparms,":");
  515.     return TRUE;
  516.  
  517. }
  518.  
  519. BOOL CInetThread::PrintConnInfo(CInetThreadParms *inetparms,
  520.                                 AsnObjectIdentifier * obj,
  521.                                 CHAR * conntype)
  522. {
  523.  
  524.     INT tcpvarbinds = 5;
  525.     INT udpvarbinds = 2;
  526.     INT q;
  527.     AsnInteger dispstate;
  528.     AsnInteger localport;
  529.     AsnInteger remoteport;
  530.  
  531.     AsnInteger errorStatus;
  532.     AsnInteger errorIndex;
  533.     
  534.     RFC1157VarBind tcplist[5];
  535.     RFC1157VarBindList tcpbindlist = {tcplist,tcpvarbinds};
  536.     RFC1157VarBind udplist[2];
  537.     RFC1157VarBindList udpbindlist = {udplist,udpvarbinds};
  538.     CHAR textbuf[255];
  539.     BYTE *routes;
  540.     u_long localaddr;
  541.     u_long remoteaddr;
  542.     CHAR szlocaladdr[128];
  543.     CHAR szremoteaddr[128];
  544.     CHAR szlocalhost[128];
  545.     CHAR *szTempName;
  546.     struct in_addr convaddr;
  547.     struct hostent *resolve_addr;
  548.     int rc;
  549.  
  550.     rc = strcmp(conntype,"TCP");
  551.     if (rc == 0)
  552.     {
  553.         for(q = 0; q<tcpvarbinds; q++)   // for for #of var binds
  554.         {
  555.             
  556.             Make_Oid(&tcplist[q].name,obj->idLength,obj->ids);
  557.             tcplist[q].name.ids[9] = q+1;
  558.             tcplist[q].value.asnType = ASN_NULL;
  559.         }
  560.     
  561.         
  562.  
  563.         rc = (*SnmpExtensionQuery)(ASN_RFC1157_GETREQUEST,
  564.                         &tcpbindlist,
  565.                         &errorStatus,
  566.                         &errorIndex);
  567.  
  568.  
  569.         if (!rc)
  570.  
  571.             {
  572.             // The API is indicating an error.
  573.  
  574.             wsprintf(textbuf,"SNMP Error Status = %d Index = %d",
  575.                         errorStatus,errorIndex);
  576.  
  577.             PrintLine(inetparms,textbuf);
  578.  
  579.             return FALSE;
  580.             }
  581.  
  582.         //
  583.         // build connstate table to look up the name. 
  584.         // convert the ip addr from BYTE* to u_long then inet_ntoa
  585.         // the ports are int values.
  586.         //
  587.         
  588.  
  589.         dispstate = tcplist[0].value.asnValue.number;    // State 
  590.  
  591.         
  592.         // local address
  593.         routes = tcplist[1].value.asnValue.string.stream;
  594.  
  595.         //
  596.         // convert to ULONG leave net order in tact
  597.         //
  598.  
  599.         localaddr = (*routes<<24) | (*(routes+1)<<16) |
  600.                              (*(routes+2)<<8) | *(routes+3);
  601.                     
  602.         //values1 = list[1].value.asnValue.;
  603.         // local port
  604.         localport = tcplist[2].value.asnValue.number;
  605.  
  606.         // remote address
  607.  
  608.         routes = tcplist[3].value.asnValue.string.stream;
  609.         remoteaddr = (*routes<<24) | (*(routes+1)<<16) |
  610.                              (*(routes+2)<<8) | *(routes+3);
  611.         
  612.  
  613.         localaddr = ntohl(localaddr);
  614.         remoteaddr = ntohl(remoteaddr);
  615.  
  616.         convaddr.s_addr = localaddr;
  617.         szTempName = inet_ntoa(convaddr);
  618.         strcpy(szlocaladdr,szTempName);
  619.  
  620.         convaddr.s_addr = remoteaddr;
  621.         szTempName = inet_ntoa(convaddr);
  622.         strcpy(szremoteaddr,szTempName);
  623.  
  624.         if (inetparms->resolveaddrs)
  625.         {
  626.             rc = strncmp(szlocaladdr,"127",3);
  627.             if ((localaddr == INADDR_ANY) ||  //0.0.0.0
  628.                 (rc == 0))
  629.                  
  630.             {
  631.                   gethostname(szlocalhost,sizeof(szlocalhost));
  632.                  strcpy(szlocaladdr,szlocalhost);
  633.             }
  634.             else
  635.             {
  636.                 resolve_addr = gethostbyaddr((CHAR *)&localaddr,
  637.                                                 4,AF_INET);
  638.                 if (resolve_addr)
  639.                     strcpy(szlocaladdr,resolve_addr->h_name);
  640.             }
  641.  
  642.             if (remoteaddr != INADDR_ANY)
  643.             {
  644.                 remoteport = tcplist[4].value.asnValue.number;
  645.                 resolve_addr = gethostbyaddr((CHAR *)&remoteaddr,
  646.                                                 4,AF_INET);
  647.                 if (resolve_addr)
  648.                     strcpy(szremoteaddr,resolve_addr->h_name);
  649.             }
  650.             else
  651.                 remoteport = 0;
  652.  
  653.  
  654.         }
  655.             // remote port
  656.         
  657.         
  658.  
  659.  
  660.         
  661.  
  662.         wsprintf(textbuf,"TCP     %s:%d \t%s:%d \t%s",
  663.             szlocaladdr,
  664.             localport,
  665.             szremoteaddr,
  666.             remoteport,
  667.             StateTable[dispstate - 1].state);
  668.  
  669.         PrintLine(inetparms,textbuf);
  670.  
  671.             
  672.         for(int x=0; x<tcpvarbinds; x++)
  673.         Free_Var(&tcplist[x]);
  674.  
  675.         return TRUE;
  676.     } // end if TCP
  677.  
  678.     rc = strcmp(conntype,"UDP");
  679.     if (rc == 0)
  680.     
  681.     {
  682.         for(q = 0; q<udpvarbinds; q++)   // for for #of var binds
  683.         {
  684.             
  685.             Make_Oid(&udplist[q].name,obj->idLength,obj->ids);
  686.             udplist[q].name.ids[9] = q+1;
  687.             udplist[q].value.asnType = ASN_NULL;
  688.         }
  689.     
  690.       
  691.         rc = (*SnmpExtensionQuery)(ASN_RFC1157_GETREQUEST,
  692.                         &udpbindlist,
  693.                         &errorStatus,
  694.                         &errorIndex);
  695.  
  696.  
  697.         if (!rc)
  698.  
  699.             {
  700.             // The API is indicating an error.
  701.  
  702.             wsprintf(textbuf,"SNMP Error Status = %d Index = %d",
  703.                         errorStatus,errorIndex);
  704.  
  705.             PrintLine(inetparms,textbuf);
  706.  
  707.             return FALSE;
  708.             }
  709.         // local address
  710.         routes = udplist[0].value.asnValue.string.stream;
  711.  
  712.         //
  713.         // convert to ULONG leave net order in tact
  714.         //
  715.  
  716.         localaddr = (*routes<<24) | (*(routes+1)<<16) |
  717.                              (*(routes+2)<<8) | *(routes+3);
  718.                     
  719.  
  720.         // local port
  721.         localport = udplist[1].value.asnValue.number;
  722.  
  723.         
  724.  
  725.         localaddr = ntohl(localaddr);
  726.         
  727.  
  728.         convaddr.s_addr = localaddr;
  729.         szTempName = inet_ntoa(convaddr);
  730.         strcpy(szlocaladdr,szTempName);
  731.  
  732.         strcpy(szremoteaddr,"*:*");
  733.  
  734.         if (inetparms->resolveaddrs)
  735.         {
  736.             rc = strncmp(szlocaladdr,"127",3);
  737.             if ((localaddr == INADDR_ANY) ||  //0.0.0.0
  738.                 (rc == 0))
  739.                  
  740.             {
  741.                   gethostname(szlocalhost,sizeof(szlocalhost));
  742.                  strcpy(szlocaladdr,szlocalhost);
  743.             }
  744.             else
  745.             {
  746.                 resolve_addr = gethostbyaddr((CHAR *)&localaddr,
  747.                                                 4,AF_INET);
  748.                 if (resolve_addr)
  749.                     strcpy(szlocaladdr,resolve_addr->h_name);
  750.             }
  751.         }
  752.         
  753.  
  754.         wsprintf(textbuf,"UDP    %s:%i\t%s",
  755.             szlocaladdr,
  756.             localport,
  757.             szremoteaddr);
  758.         
  759.  
  760.         PrintLine(inetparms,textbuf);
  761.  
  762.             
  763.         for(int x=0; x<udpvarbinds; x++)
  764.         Free_Var(&udplist[x]);
  765.  
  766.         return TRUE;
  767.     } // end if UDP
  768.  
  769.     // no type 
  770.     return FALSE;
  771.  
  772. }
  773.  
  774. BOOL CInetThread::PrintLine(CInetThreadParms *inetparms,
  775.                             CHAR * line)
  776. {
  777.     ::SendMessage(inetparms->m_hwndNotifyInetDone,
  778.                 WM_USER_INET_PRINT, 0, (LONG)line);
  779.  
  780.     return TRUE;
  781. }
  782.  
  783. BOOL CInetThread::DoIcmpStats(CInetThreadParms *inetparms)
  784. {
  785.  
  786.     int numvarbinds = 26;
  787.     DWORD value1;
  788.     DWORD value2;
  789.     DWORD values;
  790.     CHAR textbuf[256];
  791.     int startpt = 0;  // start 1 less makes logic better
  792.     
  793.  
  794.  
  795.     AsnInteger errorStatus;
  796.     AsnInteger errorIndex;
  797.     
  798.     RFC1157VarBind list[26];
  799.     RFC1157VarBindList bindlist = {list,26};
  800.     UINT ids_icmpstats[9] = {1,3,6,1,2,1,5,0,0};
  801.     int q;
  802.     int rc;
  803.     
  804.     
  805.     for(q = 0; q<numvarbinds; q++)   // for for #of var binds
  806.     {
  807.         ids_icmpstats[7] = ++startpt;  // plug byte 7
  808.         Make_Oid(&list[q].name,9,ids_icmpstats);
  809.         list[q].value.asnType = ASN_NULL;
  810.         
  811.     }
  812.     
  813.     
  814.  
  815.     
  816.       
  817.     rc = (*SnmpExtensionQuery)(ASN_RFC1157_GETREQUEST,
  818.                         &bindlist,
  819.                         &errorStatus,
  820.                         &errorIndex);
  821.  
  822.     if (!rc)
  823.         {
  824.             // The API is indicating an error.
  825.  
  826.             wsprintf(textbuf,"SNMP Error Status = %d Index = %d",
  827.                         errorStatus,errorIndex);
  828.  
  829.             PrintLine(inetparms,textbuf);
  830.  
  831.             return FALSE;
  832.         }
  833.  
  834.       
  835.     wsprintf(textbuf,"ICMP Statistics:\tSend\tRecv");  
  836.     PrintLine(inetparms,textbuf);
  837.  
  838.     value1 = list[13].value.asnValue.counter;
  839.     value2 = list[0].value.asnValue.counter;
  840.     wsprintf(textbuf,"MSGS \t%d\t%d",
  841.              value1,
  842.              value2);
  843.     PrintLine(inetparms,textbuf);
  844.  
  845.     
  846.         
  847.     value1 = list[14].value.asnValue.counter;
  848.     value2 = list[1].value.asnValue.counter;
  849.     
  850.     wsprintf(textbuf,"Errors \t%d\t%d",
  851.             value1,
  852.             value2);
  853.     PrintLine(inetparms,textbuf);
  854.  
  855.     
  856.     value1 = list[15].value.asnValue.counter;    
  857.     value2 = list[2].value.asnValue.counter;
  858.     wsprintf(textbuf,"Dest Unreach \t%d\t%d",
  859.             value1,
  860.             value2);
  861.     PrintLine(inetparms,textbuf);
  862.  
  863.     value1 = list[16].value.asnValue.counter;     
  864.     value2 = list[3].value.asnValue.counter;
  865.     wsprintf(textbuf,"Time Exceeded \t%d\t%d",
  866.             value1,
  867.             value2);
  868.     PrintLine(inetparms,textbuf);
  869.  
  870.  
  871.     values = list[17].value.asnValue.counter;    
  872.     values = list[4].value.asnValue.counter;
  873.     wsprintf(textbuf,"Parm Problems \t%d\t%d",
  874.             value1,
  875.             value2);
  876.     PrintLine(inetparms,textbuf);
  877.  
  878.     
  879.     value1 = list[18].value.asnValue.counter;
  880.     value2 = list[5].value.asnValue.counter;
  881.     wsprintf(textbuf,"Source Quenches \t%d\t%d",
  882.             value1,
  883.             value2);
  884.     PrintLine(inetparms,textbuf);
  885.  
  886.     
  887.     value1 = list[19].value.asnValue.counter;    
  888.     value2 = list[6].value.asnValue.counter;
  889.     wsprintf(textbuf,"Redirects \t%d\t%d",
  890.             value1,
  891.             value2);
  892.     PrintLine(inetparms,textbuf);
  893.  
  894.  
  895.     value1 = list[20].value.asnValue.counter;       
  896.     value2 = list[7].value.asnValue.counter;
  897.     wsprintf(textbuf,"Echos \t%d\t%d",
  898.             value1,
  899.             value2);
  900.     PrintLine(inetparms,textbuf);
  901.  
  902.     value1 = list[21].value.asnValue.counter;
  903.     value2 = list[8].value.asnValue.counter;
  904.     wsprintf(textbuf,"Echo Replies \t%d\t%d",
  905.             value1,
  906.             value2);
  907.     PrintLine(inetparms,textbuf);
  908.  
  909.     value1 = list[22].value.asnValue.counter;
  910.     value2 = list[9].value.asnValue.counter;
  911.     wsprintf(textbuf,"Timestamps \t%d\t%d",
  912.             value1,
  913.             value2);
  914.     PrintLine(inetparms,textbuf);
  915.  
  916.     value1 = list[23].value.asnValue.counter;
  917.     value2 = list[10].value.asnValue.counter;
  918.     wsprintf(textbuf,"Timestamp Replies \t%d\t%d",
  919.             value1,
  920.             value2);
  921.     PrintLine(inetparms,textbuf);
  922.     
  923.     value1 = list[24].value.asnValue.counter;
  924.     value2 = list[11].value.asnValue.counter;
  925.     wsprintf(textbuf,"Addr Mask Req \t%d\t%d",
  926.             value1,
  927.             value2);
  928.     PrintLine(inetparms,textbuf);
  929.  
  930.     value1 = list[25].value.asnValue.counter;
  931.     value2 = list[12].value.asnValue.counter;
  932.     wsprintf(textbuf,"Addr Mask Replies \t%d\t%d",
  933.             value1,
  934.             value2);
  935.     PrintLine(inetparms,textbuf);
  936.  
  937.     
  938.     PrintLine(inetparms,":");
  939.     
  940.     for(int x=0; x<numvarbinds; x++)
  941.         Free_Var(&list[x]);
  942.  
  943.     return TRUE;
  944.  
  945. }
  946.  
  947. BOOL CInetThread::DoIfStats(CInetThreadParms *inetparms)
  948. {
  949.     int numvarbinds = 12;
  950.     AsnCounter values1;
  951.     AsnCounter values2;
  952.     AsnInteger numofinterfaces;
  953.     CHAR textbuf[256];
  954.     CHAR catbuf[256];
  955.     int startpt = 9;  // start 1 less makes logic better
  956.     
  957.     UINT reqids[12] = {2,10,16,11,17,12,18,13,19,14,20,15};
  958.  
  959.  
  960.     AsnInteger errorStatus;
  961.     AsnInteger errorIndex;
  962.     
  963.     RFC1157VarBind list[12];
  964.     RFC1157VarBindList bindlist = {list,12};
  965.  
  966.     //
  967.     UINT ids_ifstats[11] = {1,3,6,1,2,1,2,2,1,0,0};
  968.     //                                        x n
  969.     //                           where x = mibtype (offset =9) 
  970.     //                                 n = interface # (off = 10)
  971.     UINT ifstatlen = 11;
  972.  
  973.     UINT ids_ifnumber[9] = {1,3,6,1,2,1,2,1,0};
  974.     RFC1157VarBind Singlelist[1];
  975.     RFC1157VarBindList Singlebindlist = {Singlelist,1};
  976.     int q;
  977.     int rc;
  978.     
  979.  
  980.     //
  981.     // get number of interfaces
  982.     //
  983.  
  984.     Make_Oid(&Singlelist[0].name,9,ids_ifnumber);
  985.     Singlelist[0].value.asnType = ASN_NULL;
  986.  
  987.     rc = (*SnmpExtensionQuery)(ASN_RFC1157_GETREQUEST,
  988.                         &Singlebindlist,
  989.                         &errorStatus,
  990.                         &errorIndex);
  991.     
  992.  
  993.     if (!rc)
  994.         {
  995.             // The API is indicating an error.
  996.  
  997.             wsprintf(textbuf,"SNMP Error Status = %d Index = %d",
  998.                         errorStatus,errorIndex);
  999.  
  1000.             PrintLine(inetparms,textbuf);
  1001.  
  1002.             return FALSE;
  1003.         }
  1004.     numofinterfaces = Singlelist[0].value.asnValue.number;
  1005.     Free_Var(&Singlelist[0]);
  1006.  
  1007.     wsprintf(textbuf,"Interface Statistics:");  
  1008.     PrintLine(inetparms,textbuf);
  1009.     
  1010.     while(numofinterfaces)
  1011.     {
  1012.  
  1013.     
  1014.  
  1015.         for(q = 0; q<numvarbinds; q++)   // for for #of var binds
  1016.         {
  1017.             ids_ifstats[9] = reqids[q];
  1018.             ids_ifstats[10] = numofinterfaces;  
  1019.             Make_Oid(&list[q].name,ifstatlen,ids_ifstats);
  1020.             list[q].value.asnType = ASN_NULL;
  1021.         }
  1022.     
  1023.       
  1024.         rc = (*SnmpExtensionQuery)(ASN_RFC1157_GETREQUEST,
  1025.                         &bindlist,
  1026.                         &errorStatus,
  1027.                         &errorIndex);
  1028.  
  1029.         if (!rc)
  1030.             {
  1031.             // The API is indicating an error.
  1032.  
  1033.             wsprintf(textbuf,"SNMP Error Status = %d Index = %d",
  1034.                         errorStatus,errorIndex);
  1035.  
  1036.             PrintLine(inetparms,textbuf);
  1037.  
  1038.             return FALSE;
  1039.             }
  1040.  
  1041.  
  1042.  
  1043.     
  1044.         
  1045.         lstrcpyn(textbuf,
  1046.                 (LPCTSTR)list[0].value.asnValue.string.stream,
  1047.                 list[0].value.asnValue.string.length+1);
  1048.         wsprintf(catbuf,"%s\tSend\tRecv",textbuf);
  1049.         PrintLine(inetparms,catbuf);
  1050.         PrintLine(inetparms," ");
  1051.     
  1052.     
  1053.         values1 = list[1].value.asnValue.counter;
  1054.         values2 = list[2].value.asnValue.counter;
  1055.         wsprintf(textbuf,"Bytes \t%d\t%d",
  1056.             values2,
  1057.             values1);
  1058.         
  1059.         PrintLine(inetparms,textbuf);
  1060.  
  1061.         
  1062.         values1 = list[3].value.asnValue.counter;
  1063.         values2 = list[4].value.asnValue.counter;
  1064.         wsprintf(textbuf,"Unicast \t%d\t%d",
  1065.             values2,
  1066.             values1);
  1067.         PrintLine(inetparms,textbuf);
  1068.  
  1069.         values1 = list[5].value.asnValue.counter;
  1070.         values2 = list[6].value.asnValue.counter;
  1071.         wsprintf(textbuf,"Non-Unicast \t%d\t%d",
  1072.             values2,
  1073.             values1);
  1074.         
  1075.         PrintLine(inetparms,textbuf);
  1076.  
  1077.         values1 = list[7].value.asnValue.counter;
  1078.         values2 = list[8].value.asnValue.counter;
  1079.         wsprintf(textbuf,"Discards \t%d\t%d",
  1080.             values2,
  1081.             values1);
  1082.         
  1083.         PrintLine(inetparms,textbuf);
  1084.  
  1085.         values1 = list[9].value.asnValue.counter;
  1086.         values2 = list[10].value.asnValue.counter;
  1087.         wsprintf(textbuf,"Errors \t%d\t%d",
  1088.             values2,
  1089.             values1);
  1090.         
  1091.         PrintLine(inetparms,textbuf);
  1092.  
  1093.         values1 = list[11].value.asnValue.counter;
  1094.         values2 = 0;
  1095.         wsprintf(textbuf,"UnknownProtos \t%d\t%d",
  1096.             values2,
  1097.             values1);
  1098.             
  1099.         PrintLine(inetparms,textbuf);
  1100.     
  1101.         for (int x=0;x<numvarbinds;x++)
  1102.         {
  1103.             Free_Var(&list[x]);
  1104.         }
  1105.  
  1106.         PrintLine(inetparms,":");
  1107.         numofinterfaces--;
  1108.  
  1109.     } // end WHILE
  1110.  
  1111.     return TRUE;
  1112.  
  1113. }
  1114.  
  1115. BOOL CInetThread::DoIpStats(CInetThreadParms *inetparms)
  1116. {
  1117.  
  1118.     int numvarbinds = 17;
  1119.     DWORD values;
  1120.     CHAR textbuf[256];
  1121.     int startpt = 0;  // start 1 less makes logic better
  1122.     
  1123.     int rc;
  1124.  
  1125.     AsnInteger errorStatus;
  1126.     AsnInteger errorIndex;
  1127.     
  1128.     RFC1157VarBind list[17];
  1129.     RFC1157VarBindList bindlist = {list,17};
  1130.     UINT ids_ipstats[9] = {1,3,6,1,2,1,4,0,0};
  1131.     UINT ids_ipvals[17] = {3,4,5,6,7,8,9,10,11,12,14,15,
  1132.                            16,17,18,19,23};
  1133.     int q;
  1134.     
  1135.     
  1136.     for(q = 0; q<numvarbinds; q++)   // for for #of var binds
  1137.     {
  1138.         ids_ipstats[7] = ids_ipvals[q];  // plug byte 7
  1139.         Make_Oid(&list[q].name,9,ids_ipstats);
  1140.         list[q].value.asnType = ASN_NULL;
  1141.         
  1142.     }
  1143.     
  1144.     
  1145.  
  1146.     
  1147.       
  1148.     rc = (*SnmpExtensionQuery)(ASN_RFC1157_GETREQUEST,
  1149.                         &bindlist,
  1150.                         &errorStatus,
  1151.                         &errorIndex);
  1152.  
  1153.     if (!rc)
  1154.         {
  1155.             // The API is indicating an error.
  1156.  
  1157.             wsprintf(textbuf,"SNMP Error Status = %d Index = %d",
  1158.                         errorStatus,errorIndex);
  1159.  
  1160.             PrintLine(inetparms,textbuf);
  1161.  
  1162.             return FALSE;
  1163.         }
  1164.       
  1165.       
  1166.     PrintLine(inetparms,"IP Statistics:");
  1167.     values = list[0].value.asnValue.counter;
  1168.     wsprintf(textbuf,"Packets Received \t%d",values);
  1169.     PrintLine(inetparms,textbuf);
  1170.  
  1171.         
  1172.     values = list[1].value.asnValue.counter;
  1173.     wsprintf(textbuf,"Received HDR Errors \t%d",values);
  1174.     PrintLine(inetparms,textbuf);
  1175.  
  1176.         
  1177.     values = list[2].value.asnValue.counter;
  1178.     wsprintf(textbuf,"Received ADDR Errors \t%d",values);
  1179.     PrintLine(inetparms,textbuf);
  1180.  
  1181.     values = list[3].value.asnValue.counter;
  1182.     wsprintf(textbuf,"Datagrams Forwarded \t%d",values);
  1183.     PrintLine(inetparms,textbuf);
  1184.     
  1185.  
  1186.     values = list[4].value.asnValue.counter;
  1187.     wsprintf(textbuf,"Unknown Protos Received \t%d",values);
  1188.     PrintLine(inetparms,textbuf);
  1189.  
  1190.     
  1191.     values = list[5].value.asnValue.counter;
  1192.     wsprintf(textbuf,"Received Packets Discarded \t%d",values);
  1193.     PrintLine(inetparms,textbuf);
  1194.  
  1195.     
  1196.     values = list[6].value.asnValue.counter;
  1197.     wsprintf(textbuf,"Received Packets Delivered \t%d",values);
  1198.     PrintLine(inetparms,textbuf);
  1199.  
  1200.     
  1201.     values = list[7].value.asnValue.counter;
  1202.     wsprintf(textbuf,"Output Requests \t%d",values);
  1203.     PrintLine(inetparms,textbuf);
  1204.  
  1205.     
  1206.     values = list[8].value.asnValue.counter;
  1207.     wsprintf(textbuf,"Routing Discards \t%d",values);
  1208.     PrintLine(inetparms,textbuf);
  1209.  
  1210.     
  1211.     values = list[9].value.asnValue.counter;
  1212.     wsprintf(textbuf,"Discarded Output Packets \t%d",values);
  1213.     PrintLine(inetparms,textbuf);
  1214.  
  1215.     
  1216.     values = list[10].value.asnValue.counter;
  1217.     wsprintf(textbuf,"Output Packet No Route \t%d",values);
  1218.     PrintLine(inetparms,textbuf);
  1219.  
  1220.     values = list[11].value.asnValue.counter;
  1221.     wsprintf(textbuf,"Reassembly Required \t%d",values);
  1222.     PrintLine(inetparms,textbuf);
  1223.  
  1224.  
  1225.     values = list[12].value.asnValue.counter;
  1226.     wsprintf(textbuf,"Reassembly Successful \t%d",values);
  1227.     PrintLine(inetparms,textbuf);
  1228.  
  1229.     values = list[13].value.asnValue.counter;
  1230.     wsprintf(textbuf,"Reassembly Failures \t%d",values);
  1231.     PrintLine(inetparms,textbuf);
  1232. //
  1233.     values = list[14].value.asnValue.counter;
  1234.     wsprintf(textbuf,"Successfully Fragmented \t%d",values);
  1235.     PrintLine(inetparms,textbuf);
  1236. //
  1237.     values = list[15].value.asnValue.counter;
  1238.     wsprintf(textbuf,"Failing Fragmentation \t%d",values);
  1239.     PrintLine(inetparms,textbuf);
  1240.  
  1241.     values = list[16].value.asnValue.counter;
  1242.     wsprintf(textbuf,"Fragments Created \t%d",values);
  1243.     PrintLine(inetparms,textbuf);
  1244.  
  1245.     PrintLine(inetparms,":");
  1246.     
  1247.     for(int x=0; x<numvarbinds; x++)
  1248.         Free_Var(&list[x]);
  1249.     return TRUE;
  1250.  
  1251. }
  1252.  
  1253. BOOL CInetThread::DoRouteTable(CInetThreadParms *inetparms)
  1254. {
  1255.     int requestType;
  1256.     AsnInteger errorStatus;
  1257.     AsnInteger errorIndex;
  1258.     UINT ids_iproutes[8] = {1,3,6,1,2,1,4,21};
  1259.     AsnObjectIdentifier saveobj;
  1260.     RFC1157VarBind Getnextlist[1];
  1261.     RFC1157VarBindList Getnextbindlist = {Getnextlist,1};
  1262.  
  1263.  
  1264.     BOOL rc;
  1265.     CHAR textbuf[255];
  1266.  
  1267.  
  1268.  
  1269.     // pick up all the tcp connections
  1270.     Make_Oid(&Getnextlist[0].name,8,ids_iproutes);
  1271.  
  1272.     Getnextlist[0].value.asnType = ASN_NULL;
  1273.    
  1274.       
  1275.     requestType = ASN_RFC1157_GETNEXTREQUEST;
  1276.  
  1277.     strcpy(textbuf,"Routing Table Information");
  1278.     PrintLine(inetparms,textbuf);
  1279.     PrintLine(inetparms,":");
  1280.     strcpy(textbuf,
  1281.     "Net Address\tMask Address\tGateway Address\tInterface");
  1282.     PrintLine(inetparms,textbuf);
  1283.  
  1284.    
  1285.     while(1)
  1286.     {
  1287.  
  1288.         
  1289.         rc = (*SnmpExtensionQuery)(requestType, &Getnextbindlist,
  1290.                            &errorStatus, &errorIndex);
  1291.  
  1292.         if (!rc)
  1293.  
  1294.             {
  1295.             // The API is indicating an error.
  1296.  
  1297.             wsprintf(textbuf,"SNMP Error Status = %d Index = %d",
  1298.                         errorStatus,errorIndex);
  1299.  
  1300.             PrintLine(inetparms,textbuf);
  1301.  
  1302.             break;
  1303.             }
  1304.         else
  1305.             {
  1306.             // The API succeeded, errors may be indicated from the remote
  1307.             // agent.
  1308.  
  1309.  
  1310.             // Test for end of subtree or end of MIB.
  1311.  
  1312.             if (errorStatus == SNMP_ERRORSTATUS_NOSUCHNAME)
  1313.             {
  1314.             
  1315.                 break;
  1316.             }
  1317.             
  1318.             if (Getnextlist[0].value.asnType == 
  1319.                 ASN_INTEGER)
  1320.             {
  1321.                 
  1322.                 break;
  1323.  
  1324.             }
  1325.  
  1326.  
  1327.  
  1328.             // Test for general error conditions or sucesss.
  1329.  
  1330.             if (errorStatus > 0)
  1331.             {
  1332.                 wsprintf(textbuf,"SNMP Error Status = %d Index = %d",
  1333.                         errorStatus,errorIndex);
  1334.  
  1335.                 PrintLine(inetparms,textbuf);
  1336.                 break;
  1337.             }
  1338.             else
  1339.             {
  1340.                 PrintRouteInfo(inetparms,&Getnextlist[0].name);
  1341.                 
  1342.             }
  1343.  
  1344.         } // end if
  1345.  
  1346.         if (bKill)
  1347.         {
  1348.             Free_Var(&Getnextlist[0]);
  1349.             PrintLine(inetparms,"Netstat Interupt!");
  1350.             break;
  1351.         }
  1352.         SnmpUtilOidCpy(&saveobj,&Getnextlist[0].name);
  1353.                      
  1354.         Free_Var(&Getnextlist[0]);
  1355.     
  1356.         Make_Oid(&Getnextlist[0].name,saveobj.idLength,saveobj.ids);    
  1357.         
  1358.  
  1359.         Getnextlist[0].value.asnType = ASN_NULL;
  1360.         SnmpUtilOidFree(&saveobj);
  1361.     
  1362.         
  1363.     } // end while()
  1364.  
  1365.     PrintLine(inetparms,":");
  1366.     return TRUE;
  1367.  
  1368. }
  1369.  
  1370. BOOL CInetThread::PrintRouteInfo(CInetThreadParms *inetparms,AsnObjectIdentifier *obj)
  1371. {
  1372.     //struct hostent *resolve_addr;
  1373.     INT ipvarbinds = 5;
  1374.     
  1375.     INT q;
  1376.     AsnInteger metric;
  1377.     
  1378.  
  1379.     AsnInteger errorStatus;
  1380.     AsnInteger errorIndex;
  1381.  
  1382.     RFC1157VarBind iplist[5];
  1383.     RFC1157VarBindList ipbindlist = {iplist,ipvarbinds};
  1384.     RFC1157VarBind iflist[1];
  1385.     RFC1157VarBindList ifbindlist = {iflist,1};
  1386.     UINT ifreq[11] = {1,3,6,1,2,1,2,2,1,6,0};
  1387.     INT reqids[5] = {1,2,3,7,11};
  1388.     CHAR textbuf[255];
  1389.     BYTE *routes;
  1390.     u_long interfaceaddr;
  1391.     u_long gatewayaddr;
  1392.     u_long netaddr;
  1393.     u_long maskaddr;
  1394.     CHAR szinterfaceaddr[128];
  1395.     CHAR szgatewayaddr[128];
  1396.     CHAR sznetaddr[128];
  1397.     CHAR szmaskaddr[128];
  1398.     CHAR *szTempName;
  1399.     struct in_addr convaddr;
  1400.     int rc;
  1401.  
  1402.  
  1403.  
  1404.     for(q = 0; q<ipvarbinds; q++)   // for for #of var binds
  1405.     {
  1406.         
  1407.         Make_Oid(&iplist[q].name,obj->idLength,obj->ids);
  1408.         iplist[q].name.ids[9] = reqids[q];
  1409.         iplist[q].value.asnType = ASN_NULL;
  1410.     }
  1411.  
  1412.   
  1413.     rc = (*SnmpExtensionQuery)(ASN_RFC1157_GETREQUEST,
  1414.                     &ipbindlist,
  1415.                     &errorStatus,
  1416.                     &errorIndex);
  1417.  
  1418.  
  1419.     if (!rc)
  1420.     {
  1421.         wsprintf(textbuf,"SNMP Error Status = %d Index = %d",
  1422.                         errorStatus,errorIndex);
  1423.  
  1424.         PrintLine(inetparms,textbuf);
  1425.  
  1426.         return FALSE;
  1427.     }
  1428.     //
  1429.     // set up call for interface mib physaddr
  1430.     //
  1431.  
  1432.     ifreq[10] = iplist[1].value.asnValue.number;
  1433.     Make_Oid(&iflist[0].name,11,ifreq);
  1434.     iflist[0].value.asnType = ASN_NULL;
  1435.  
  1436.     rc = (*SnmpExtensionQuery)(ASN_RFC1157_GETREQUEST,
  1437.                     &ifbindlist,
  1438.                     &errorStatus,
  1439.                     &errorIndex);
  1440.  
  1441.  
  1442.     if (!rc)
  1443.     {
  1444.         wsprintf(textbuf,"SNMP Error Status = %d Index = %d",
  1445.                         errorStatus,errorIndex);
  1446.  
  1447.         PrintLine(inetparms,textbuf);
  1448.  
  1449.         return FALSE;
  1450.     }
  1451.  
  1452.     //
  1453.     // if physaddr exists use it else use gateway
  1454.     //
  1455.     if (iflist[0].value.asnValue.string.length != 0)
  1456.     {
  1457.         routes = iflist[0].value.asnValue.string.stream;
  1458.         
  1459.     }
  1460.     else
  1461.     {
  1462.         routes = iplist[3].value.asnValue.string.stream;
  1463.         
  1464.     }
  1465.     interfaceaddr = (*routes<<24) | (*(routes+1)<<16) |
  1466.                          (*(routes+2)<<8) | *(routes+3);
  1467.  
  1468.  
  1469.     //
  1470.     // build connstate table to look up the name. 
  1471.     // convert the ip addr from BYTE* to u_long then inet_ntoa
  1472.     // the ports are int values.
  1473.     //
  1474.     
  1475.  
  1476.     
  1477.  
  1478.     
  1479.     // local address
  1480.     routes = iplist[0].value.asnValue.string.stream;
  1481.  
  1482.     //
  1483.     // convert to ULONG leave net order in tact
  1484.     //
  1485.  
  1486.     netaddr = (*routes<<24) | (*(routes+1)<<16) |
  1487.                          (*(routes+2)<<8) | *(routes+3);
  1488.                 
  1489.     
  1490.     // gateway address
  1491.  
  1492.     routes = iplist[3].value.asnValue.string.stream;
  1493.     gatewayaddr = (*routes<<24) | (*(routes+1)<<16) |
  1494.                          (*(routes+2)<<8) | *(routes+3);
  1495.     
  1496.  
  1497.     // mask address
  1498.  
  1499.     routes = iplist[4].value.asnValue.string.stream;
  1500.     maskaddr = (*routes<<24) | (*(routes+1)<<16) |
  1501.                          (*(routes+2)<<8) | *(routes+3);
  1502.  
  1503.      
  1504.     metric = iplist[2].value.asnValue.number;
  1505.  
  1506.     gatewayaddr = ntohl(gatewayaddr);
  1507.     maskaddr = ntohl(maskaddr);
  1508.     netaddr = ntohl(netaddr);
  1509.     interfaceaddr = ntohl(interfaceaddr);
  1510.  
  1511.     convaddr.s_addr = maskaddr;
  1512.     szTempName = inet_ntoa(convaddr);
  1513.     strcpy(szmaskaddr ,szTempName);
  1514.  
  1515.     //
  1516.     
  1517.         
  1518.     convaddr.s_addr = gatewayaddr;
  1519.     szTempName = inet_ntoa(convaddr);
  1520.     strcpy(szgatewayaddr,szTempName);
  1521.  
  1522.     convaddr.s_addr = netaddr;
  1523.     szTempName = inet_ntoa(convaddr);
  1524.     strcpy(sznetaddr ,szTempName);
  1525.  
  1526.     convaddr.s_addr = interfaceaddr;
  1527.     szTempName = inet_ntoa(convaddr);
  1528.     strcpy(szinterfaceaddr ,szTempName);
  1529.  
  1530.  
  1531.  
  1532.         
  1533.  
  1534.     wsprintf(textbuf,"%s \t%s \t%s \t%s",
  1535.         sznetaddr,
  1536.         szmaskaddr,
  1537.         szgatewayaddr,
  1538.         szinterfaceaddr);
  1539.         //metric);
  1540.  
  1541.     PrintLine(inetparms,textbuf);
  1542.  
  1543.         
  1544.     for(int x=0; x<ipvarbinds; x++)
  1545.     {
  1546.         Free_Var(&iplist[x]);
  1547.     }
  1548.  
  1549.     Free_Var(&iflist[0]);
  1550.     return TRUE;
  1551.  
  1552. }
  1553.  
  1554. BOOL CInetThread::DoTcpStats(CInetThreadParms *inetparms)
  1555. {
  1556.     int numvarbinds = 8;
  1557.     DWORD values;
  1558.     CHAR textbuf[256];
  1559.     int startpt = 4;  // start 1 less makes logic better
  1560.  
  1561.  
  1562.  
  1563.     AsnInteger errorStatus;
  1564.     AsnInteger errorIndex;
  1565.     
  1566.     RFC1157VarBind list[8];
  1567.     RFC1157VarBindList bindlist = {list,8};
  1568.     UINT ids_tcpstats[9] = {1,3,6,1,2,1,6,0,0};
  1569.     int rc;
  1570.  
  1571.      
  1572.     
  1573.     for(int q = 0; q<numvarbinds; q++)   // for for #of var binds
  1574.     {
  1575.         ids_tcpstats[7] = ++startpt;  // plug byte 7
  1576.         Make_Oid(&list[q].name,9,ids_tcpstats);
  1577.         list[q].value.asnType = ASN_NULL;
  1578.     }
  1579.  
  1580.     
  1581.       
  1582.     rc = (*SnmpExtensionQuery)(ASN_RFC1157_GETREQUEST,
  1583.                         &bindlist,
  1584.                         &errorStatus,
  1585.                         &errorIndex);
  1586.  
  1587.      
  1588.     if (!rc)
  1589.     {
  1590.     
  1591.         wsprintf(textbuf,"SNMP Error Status = %d Index = %d",
  1592.                         errorStatus,errorIndex);
  1593.  
  1594.         PrintLine(inetparms,textbuf);
  1595.  
  1596.         return FALSE;
  1597.     }
  1598.     
  1599.     PrintLine(inetparms,"TCP Statistics:");
  1600.       // Set the value "active opens"
  1601.     values = list[0].value.asnValue.counter;
  1602.       
  1603.     wsprintf(textbuf,"Active opens \t%d",values);
  1604.     PrintLine(inetparms,textbuf);
  1605.       
  1606.     
  1607.     // Set the value "passive opens"
  1608.     values = list[1].value.asnValue.counter;
  1609.     wsprintf(textbuf,"Passive opens \t%d",values);
  1610.     PrintLine(inetparms,textbuf);
  1611.  
  1612.       
  1613.  
  1614.       // Set the value "attempts failed
  1615.     values = list[2].value.asnValue.counter;
  1616.     wsprintf(textbuf,"Attempts Failed \t%d",values);
  1617.     PrintLine(inetparms,textbuf);
  1618.     
  1619.  
  1620.       // set the value "ressets established"
  1621.     values = list[3].value.asnValue.counter;
  1622.     wsprintf(textbuf,"Resets Established \t%d",values);
  1623.     PrintLine(inetparms,textbuf);
  1624.     
  1625.       
  1626.     // Set  value "connections currently established"
  1627.     // check guage
  1628.     values = list[4].value.asnValue.counter;
  1629.     wsprintf(textbuf,"Current Sessions Established \t%d",values);
  1630.     PrintLine(inetparms,textbuf);
  1631.     
  1632.  
  1633.       // Set value "tcp in segs"
  1634.     values = list[5].value.asnValue.counter;
  1635.     wsprintf(textbuf,"Segments Received \t%d",values);
  1636.     PrintLine(inetparms,textbuf);
  1637.     
  1638.  
  1639.     // Set the "tcp out segs".
  1640.     values = list[6].value.asnValue.counter;
  1641.     wsprintf(textbuf,"Segments Sent \t%d",values);
  1642.     PrintLine(inetparms,textbuf);
  1643.     
  1644.   
  1645.       // set retrans
  1646.     values = list[7].value.asnValue.counter;
  1647.     wsprintf(textbuf,"Retransmitted Segments \t%d",values);
  1648.     PrintLine(inetparms,textbuf);
  1649.     
  1650.     PrintLine(inetparms,":");
  1651.  
  1652.     for(int x=0; x<numvarbinds; x++)
  1653.         Free_Var(&list[x]);
  1654.  
  1655.     return TRUE;
  1656.  
  1657. }
  1658.  
  1659. BOOL CInetThread::DoUdpStats(CInetThreadParms *inetparms)
  1660. {
  1661.     int numvarbinds = 4;
  1662.     DWORD values;
  1663.     CHAR textbuf[256];
  1664.     int startpt = 0;  // start 1 less makes logic better
  1665.     
  1666.  
  1667.     int rc;
  1668.  
  1669.     AsnInteger errorStatus;
  1670.     AsnInteger errorIndex;
  1671.     
  1672.     RFC1157VarBind list[4];
  1673.     RFC1157VarBindList bindlist = {list,4};
  1674.     UINT ids_udpstats[9] = {1,3,6,1,2,1,7,0,0};
  1675.     int q;
  1676.     
  1677.     
  1678.     for(q = 0; q<numvarbinds; q++)   // for for #of var binds
  1679.     {
  1680.         ids_udpstats[7] = ++startpt;  // plug byte 7
  1681.         Make_Oid(&list[q].name,9,ids_udpstats);
  1682.         list[q].value.asnType = ASN_NULL;
  1683.         
  1684.     }
  1685.     
  1686.     
  1687.  
  1688.     
  1689.       
  1690.     rc = (*SnmpExtensionQuery)(ASN_RFC1157_GETREQUEST,
  1691.                         &bindlist,
  1692.                         &errorStatus,
  1693.                         &errorIndex);
  1694.  
  1695.      
  1696.     if (!rc)
  1697.     {
  1698.         wsprintf(textbuf,"SNMP Error Status = %d Index = %d",
  1699.                         errorStatus,errorIndex);
  1700.  
  1701.         PrintLine(inetparms,textbuf);
  1702.  
  1703.         return FALSE;
  1704.     }
  1705.       
  1706.     PrintLine(inetparms,"UDP Statistics:");
  1707.     values = list[0].value.asnValue.counter;
  1708.     wsprintf(textbuf,"Datagrams Received \t%d",values);
  1709.     PrintLine(inetparms,textbuf);
  1710.  
  1711.         
  1712.     values = list[1].value.asnValue.counter;
  1713.     wsprintf(textbuf,"No Ports \t%d",values);
  1714.     PrintLine(inetparms,textbuf);
  1715.  
  1716.         
  1717.     values = list[2].value.asnValue.counter;
  1718.     wsprintf(textbuf,"Receive Errors \t%d",values);
  1719.     PrintLine(inetparms,textbuf);
  1720.  
  1721.     values = list[3].value.asnValue.counter;
  1722.     wsprintf(textbuf,"Datagrams Sent \t%d",values);
  1723.     PrintLine(inetparms,textbuf);
  1724.     
  1725.  
  1726.     
  1727.     PrintLine(inetparms,":");
  1728.     
  1729.     for(int x=0; x<numvarbinds; x++)
  1730.         Free_Var(&list[x]);
  1731.  
  1732.     return TRUE;
  1733.  
  1734.     
  1735.  
  1736. }
  1737.  
  1738. BOOL CInetThread::CleanUp()
  1739. {
  1740.     FreeLibrary(inetdll);
  1741.     WSACleanup();
  1742.     return TRUE;
  1743.  
  1744.  
  1745. }
  1746.  
  1747. void CInetThread::Kill()
  1748. {
  1749.     bKill = TRUE;
  1750.  
  1751. }
  1752.