Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1910 lines
52 KiB

  1. //*****************************************************************************
  2. //
  3. // Name: snmpinfo.c
  4. //
  5. // Description: Provides functions to read tables of data from snmp.
  6. //
  7. // Used by: netstat.exe, arp.exe, route.exe
  8. //
  9. // History:
  10. // 01/12/94 JayPh Created.
  11. // 18-Feb-97 MohsinA Fixing.
  12. //
  13. //*****************************************************************************
  14. //*****************************************************************************
  15. //
  16. // Copyright (c) 1994 by Microsoft Corp. All rights reserved.
  17. //
  18. //*****************************************************************************
  19. // #define DEBUG
  20. //
  21. // Include Files
  22. //
  23. #include <time.h>
  24. #include <nt.h>
  25. #include <ntrtl.h>
  26. #include <nturtl.h>
  27. #include <snmp.h>
  28. #include <stdio.h>
  29. #include <winsock2.h>
  30. #include <ws2tcpip.h>
  31. #include "ipexport.h"
  32. #include "llinfo.h"
  33. #include "ipinfo.h"
  34. #include "tcpinfo.h"
  35. #include "common2.h"
  36. #include "mdebug.h"
  37. #include "iprtrmib.h"
  38. #include "ntddip.h"
  39. #include "iphlpstk.h"
  40. ulong verbose = 0;
  41. //
  42. // Definitions
  43. //
  44. #define MGMTAPI_DLL "mgmtapi.dll"
  45. #define INETMIB1_DLL "inetmib1.dll"
  46. #define MAX_ID_LENGTH 50
  47. #define MAX_RETRY_COUNT 10
  48. // Interface ID values
  49. #define ID_IF_INDEX 1
  50. #define ID_IF_DESC 2
  51. #define ID_IF_TYPE 3
  52. #define ID_IF_MTU 4
  53. #define ID_IF_SPEED 5
  54. #define ID_IF_PHYSADDR 6
  55. #define ID_IF_ADMINSTATUS 7
  56. #define ID_IF_OPERSTATUS 8
  57. #define ID_IF_LASTCHANGE 9
  58. #define ID_IF_INOCTETS 10
  59. #define ID_IF_INUCASTPKTS 11
  60. #define ID_IF_INNUCASTPKTS 12
  61. #define ID_IF_INDISCARDS 13
  62. #define ID_IF_INERRORS 14
  63. #define ID_IF_INUKNOWNPROTOS 15
  64. #define ID_IF_OUTOCTETS 16
  65. #define ID_IF_OUTUCASTPKTS 17
  66. #define ID_IF_OUTNUCASTPKTS 18
  67. #define ID_IF_OUTDISCARDS 19
  68. #define ID_IF_OUTERRORS 20
  69. #define ID_IF_OUTQLEN 21
  70. // IP ID Values
  71. #define ID_IP_FORWARDING 1
  72. #define ID_IP_DEFAULTTTL 2
  73. #define ID_IP_INRECEIVES 3
  74. #define ID_IP_INHDRERRORS 4
  75. #define ID_IP_INADDRERRORS 5
  76. #define ID_IP_FORWDATAGRAMS 6
  77. #define ID_IP_INUNKNOWNPROTOS 7
  78. #define ID_IP_INDISCARDS 8
  79. #define ID_IP_INDELIVERS 9
  80. #define ID_IP_OUTREQUESTS 10
  81. #define ID_IP_OUTDISCARDS 11
  82. #define ID_IP_OUTNOROUTES 12
  83. #define ID_IP_REASMTIMEOUTS 13
  84. #define ID_IP_REASMREQDS 14
  85. #define ID_IP_REASMOKS 15
  86. #define ID_IP_REASMFAILS 16
  87. #define ID_IP_FRAGOKS 17
  88. #define ID_IP_FRAGFAILS 18
  89. #define ID_IP_FRAGCREATES 19
  90. #define ID_IP_ADDRTABLE 20
  91. #define ID_IP_ROUTETABLE 21
  92. #define ID_IP_ARPTABLE 22
  93. #define ID_IP_ROUTINGDISCARDS 23
  94. // IPAddr ID Values
  95. #define ID_IPADDR_ADDR 1
  96. #define ID_IPADDR_INDEX 2
  97. #define ID_IPADDR_MASK 3
  98. #define ID_IPADDR_BCASTADDR 4
  99. #define ID_IPADDR_REASMSIZE 5
  100. // Route ID values
  101. #define ID_ROUTE_DEST 1
  102. #define ID_ROUTE_IFINDEX 2
  103. #define ID_ROUTE_METRIC1 3
  104. #define ID_ROUTE_METRIC2 4
  105. #define ID_ROUTE_METRIC3 5
  106. #define ID_ROUTE_METRIC4 6
  107. #define ID_ROUTE_NEXTHOP 7
  108. #define ID_ROUTE_TYPE 8
  109. #define ID_ROUTE_PROTO 9
  110. #define ID_ROUTE_AGE 10
  111. #define ID_ROUTE_MASK 11
  112. #define ID_ROUTE_METRIC5 12
  113. // ARP ID Values
  114. #define ID_ARP_IFINDEX 1
  115. #define ID_ARP_PHYSADDR 2
  116. #define ID_ARP_NETADDR 3
  117. #define ID_ARP_TYPE 4
  118. // ICMP ID Values
  119. #define ID_ICMP_INMSGS 1
  120. #define ID_ICMP_INERRORS 2
  121. #define ID_ICMP_INDESTUNREACHES 3
  122. #define ID_ICMP_INTIMEEXCDS 4
  123. #define ID_ICMP_INPARMPROBS 5
  124. #define ID_ICMP_INSRCQUENCHS 6
  125. #define ID_ICMP_INREDIRECTS 7
  126. #define ID_ICMP_INECHOS 8
  127. #define ID_ICMP_INECHOREPS 9
  128. #define ID_ICMP_INTIMESTAMPS 10
  129. #define ID_ICMP_INTIMESTAMPREPS 11
  130. #define ID_ICMP_INADDRMASKS 12
  131. #define ID_ICMP_INADDRMASKREPS 13
  132. #define ID_ICMP_OUTMSGS 14
  133. #define ID_ICMP_OUTERRORS 15
  134. #define ID_ICMP_OUTDESTUNREACHES 16
  135. #define ID_ICMP_OUTTIMEEXCDS 17
  136. #define ID_ICMP_OUTPARMPROBS 18
  137. #define ID_ICMP_OUTSRCQUENCHS 19
  138. #define ID_ICMP_OUTREDIRECTS 20
  139. #define ID_ICMP_OUTECHOS 21
  140. #define ID_ICMP_OUTECHOREPS 22
  141. #define ID_ICMP_OUTTIMESTAMPS 23
  142. #define ID_ICMP_OUTTIMESTAMPREPS 24
  143. #define ID_ICMP_OUTADDRMASKS 25
  144. #define ID_ICMP_OUTADDRMASKREPS 26
  145. // TCP ID Values
  146. #define ID_TCP_RTOALGORITHM 1
  147. #define ID_TCP_RTOMIN 2
  148. #define ID_TCP_RTOMAX 3
  149. #define ID_TCP_MAXCONN 4
  150. #define ID_TCP_ACTIVEOPENS 5
  151. #define ID_TCP_PASSIVEOPENS 6
  152. #define ID_TCP_ATTEMPTFAILS 7
  153. #define ID_TCP_ESTABRESETS 8
  154. #define ID_TCP_CURRESTABS 9
  155. #define ID_TCP_INSEGS 10
  156. #define ID_TCP_OUTSEGS 11
  157. #define ID_TCP_RETRANSSEGS 12
  158. #define ID_TCP_CONNTABLE 13
  159. #define ID_TCP_INERRS 14
  160. #define ID_TCP_OUTRSTS 15
  161. // TCP CONN ID Values
  162. #define ID_TCPCONN_STATE 1
  163. #define ID_TCPCONN_LOCALADDR 2
  164. #define ID_TCPCONN_LOCALPORT 3
  165. #define ID_TCPCONN_REMOTEADDR 4
  166. #define ID_TCPCONN_REMOTEPORT 5
  167. // TCP New CONN ID Values (both IPv4 and IPv6)
  168. #define ID_TCPNEWCONN_LOCALADDRTYPE 1
  169. #define ID_TCPNEWCONN_LOCALADDR 2
  170. #define ID_TCPNEWCONN_LOCALPORT 3
  171. #define ID_TCPNEWCONN_REMOTEADDRTYPE 4
  172. #define ID_TCPNEWCONN_REMOTEADDR 5
  173. #define ID_TCPNEWCONN_REMOTEPORT 6
  174. #define ID_TCPNEWCONN_STATE 7
  175. // UDP ID Values
  176. #define ID_UDP_INDATAGRAMS 1
  177. #define ID_UDP_NOPORTS 2
  178. #define ID_UDP_INERRORS 3
  179. #define ID_UDP_OUTDATAGRAMS 4
  180. #define ID_UDP_CONNTABLE 5
  181. // UDP CONN ID Values
  182. #define ID_UDPCONN_LOCALADDR 1
  183. #define ID_UDPCONN_LOCALPORT 2
  184. // UDP LISTENER ID Values (both IPv4 and IPv6)
  185. #define ID_UDPLISTENER_LOCALADDRTYPE 1
  186. #define ID_UDPLISTENER_LOCALADDR 2
  187. #define ID_UDPLISTENER_LOCALPORT 3
  188. //
  189. // Structure Definitions
  190. //
  191. typedef struct _OIDdef {
  192. ulong Length;
  193. ulong Val[MAX_ID_LENGTH];
  194. ulong EntElemOffset;
  195. ulong BackOffset;
  196. } OIDdef;
  197. //
  198. // Local Function Prototypes
  199. //
  200. ulong ReadTable( GenericTable *pList, ulong Type, ulong Size );
  201. void SaveData_IF( GenericTable *pEntry,
  202. RFC1157VarBind item,
  203. OIDdef *pOid );
  204. void SaveData_IP( GenericTable *pEntry,
  205. RFC1157VarBind item,
  206. OIDdef *pOid );
  207. void SaveData_IPAddr( GenericTable *pEntry,
  208. RFC1157VarBind item,
  209. OIDdef *pOid );
  210. void SaveData_ROUTE( GenericTable *pEntry,
  211. RFC1157VarBind item,
  212. OIDdef *pOid );
  213. void SaveData_ARP( GenericTable *pEntry,
  214. RFC1157VarBind item,
  215. OIDdef *pOid );
  216. void SaveData_ICMP( GenericTable *pEntry,
  217. RFC1157VarBind item,
  218. OIDdef *pOid );
  219. void SaveData_TCP( GenericTable *pEntry,
  220. RFC1157VarBind item,
  221. OIDdef *pOid );
  222. void SaveData_TCPCONN( GenericTable *pEntry,
  223. RFC1157VarBind item,
  224. OIDdef *pOid );
  225. void SaveData_TCP6CONN( GenericTable *pEntry,
  226. RFC1157VarBind item,
  227. OIDdef *pOid );
  228. void SaveData_UDP( GenericTable *pEntry,
  229. RFC1157VarBind item,
  230. OIDdef *pOid );
  231. void SaveData_UDPCONN( GenericTable *pEntry,
  232. RFC1157VarBind item,
  233. OIDdef *pOid );
  234. void SaveData_UDP6LISTENER( GenericTable *pEntry,
  235. RFC1157VarBind item,
  236. OIDdef *pOid );
  237. //
  238. // Global Variables
  239. //
  240. // These are used to create object id's
  241. OIDdef PreambleDef = { 6, { 1, 3, 6, 1, 2, 1 }, 0, 0 };
  242. OIDdef IfInfoDef = { 4, { 2, 2, 1, 1 }, 9, 2 };
  243. OIDdef IPInfoDef = { 2, { 4, 1 }, 7, 1 };
  244. OIDdef IPAddrInfoDef = { 4, { 4, 20, 1, 1 }, 9, 2 };
  245. OIDdef RouteInfoDef = { 4, { 4, 21, 1, 1 }, 9, 2 };
  246. OIDdef ARPInfoDef = { 4, { 4, 22, 1, 1 }, 9, 2 };
  247. OIDdef ICMPInfoDef = { 2, { 5, 1, }, 7, 1 };
  248. OIDdef TCPConnDef = { 4, { 6, 13, 1, 1 }, 9, 2 };
  249. OIDdef UDPConnDef = { 4, { 7, 5, 1, 1 }, 9, 2 };
  250. //
  251. // In the current MIB drafts, the TCP/UDP stats are combined for both IPv4
  252. // and IPv6. As a result, we can't query the MIB objects any more if
  253. // we want to show separate stats for IPv4 vs IPv6.
  254. //
  255. // OIDdef TCPInfoDef = { 2, { 6, 1 }, 7, 1 };
  256. // OIDdef UDPInfoDef = { 2, { 7, 1 }, 7, 1 };
  257. OIDdef TCP6ConnDef = { 4, { 6, 19, 1, 1 }, 9, 2 };
  258. OIDdef UDP6ListenerDef={ 4, { 7, 7, 1, 1 }, 9, 2 };
  259. // These are used to hold the addresses of the functions we use in inetmib1.dll
  260. FARPROC gQueryAddr;
  261. FARPROC gInitAddr;
  262. //
  263. // From //ORVILLE/RAZZLE/src/net/snmp/agent/mgmtapi/mgmtapi.c
  264. // See //ORVILLE/RAZZLE/src/public/sdk/inc/snmp.h
  265. // SNMP_FUNC_TYPE is WINAPI.
  266. //
  267. // These pointer to functions are imported from mgmtapi.dll (available
  268. // on nt server only with snmp service, but can be copied).
  269. // - MohsinA, 11-Mar-97.
  270. //
  271. BOOL (SNMP_FUNC_TYPE * pSnmpMgrOidToStr )( IN AsnObjectIdentifier *oid,
  272. OUT LPSTR *string );
  273. //
  274. // Exported Functions
  275. //
  276. //*****************************************************************************
  277. //
  278. // Name: InitSnmp
  279. //
  280. // Description: Set up to use inetmib1.dll. Load the DLL, and get addresses
  281. // for the interesting procedures.
  282. // NOTE: This function must be called before calling GetTable().
  283. //
  284. // Parameters: void.
  285. //
  286. // Returns: ulong: NO_ERROR if successful, error code otherwise.
  287. //
  288. // History:
  289. // 12/20/93 JayPh Created.
  290. //
  291. //*****************************************************************************
  292. ulong InitSnmp( void )
  293. {
  294. HANDLE hExtension;
  295. ulong TimeZeroReference;
  296. HANDLE hPollForTrapEvent;
  297. AsnObjectIdentifier SupportedView;
  298. HANDLE mgmtapi_dll;
  299. CHAR Path[MAX_PATH + 1 + max(sizeof(MGMTAPI_DLL),
  300. sizeof(INETMIB1_DLL))
  301. + 2];
  302. CHAR *FileName;
  303. TimeZeroReference = (ulong)time( (time_t *)0 );
  304. if (GetSystemDirectory(Path, MAX_PATH) == 0) {
  305. return GetLastError();
  306. }
  307. FileName = Path + strlen(Path);
  308. // Load the management apis, only on servers, but useful for
  309. // figuring out snmp jargon.
  310. if( verbose ){
  311. strcpy( FileName, "\\" MGMTAPI_DLL );
  312. mgmtapi_dll = LoadLibraryA( Path );
  313. if( mgmtapi_dll ){
  314. pSnmpMgrOidToStr
  315. = (LPVOID) GetProcAddress( mgmtapi_dll, "SnmpMgrOidToStr" );
  316. }
  317. if( !mgmtapi_dll || !pSnmpMgrOidToStr ){
  318. DEBUG_PRINT((
  319. "InitSnmp: mgmtapi.dll:pSnmpMgrOidToStr() not found.\n"
  320. ));
  321. }
  322. }
  323. // Load inetmib1.dll and get proc address for SnmpExtensionQuery
  324. strcpy( FileName, "\\" INETMIB1_DLL );
  325. hExtension = LoadLibraryA( Path );
  326. if ( hExtension == NULL )
  327. {
  328. DEBUG_PRINT(("InitSnmp: cannot load inetmib1.dll\n"));
  329. return ( ERROR_FILE_NOT_FOUND );
  330. }
  331. gInitAddr = GetProcAddress( hExtension, "SnmpExtensionInit" );
  332. if ( gInitAddr == NULL )
  333. {
  334. DEBUG_PRINT(("InitSnmp: inetmib1.dll:SnmpExtensionInit missing.\n"));
  335. return ( ERROR_FILE_NOT_FOUND );
  336. }
  337. gQueryAddr = GetProcAddress( hExtension, "SnmpExtensionQuery" );
  338. if ( gQueryAddr == NULL )
  339. {
  340. DEBUG_PRINT(("InitSnmp: inetmib1.dll:SnmpExtensionQuery missing.\n"));
  341. return ( ERROR_FILE_NOT_FOUND );
  342. }
  343. // Initialize the extension DLL
  344. (*gInitAddr)( TimeZeroReference, &hPollForTrapEvent, &SupportedView );
  345. return ( NO_ERROR );
  346. }
  347. //*****************************************************************************
  348. //
  349. // Name: GetTable
  350. //
  351. // Description: Gets a consistent table from snmp. Consistency is achieved by
  352. // reading the table, reading the table a second time and
  353. // comparing the two. If they match, we are done. If they don't
  354. // match, we read the table again and compare again. Repeating
  355. // until we have a match, or our retry count exceeds a threshold.
  356. //
  357. // Parameters: ulong Type: type of table to get.
  358. // ulong *pResult: pointer to location to receive the result code.
  359. //
  360. // Returns: void *: NULL if some error, otherwise pointer to table.
  361. //
  362. // History:
  363. // 01/12/94 JayPh Created.
  364. // 18-Feb-97 MohsinA Removed while loop and pList1.
  365. //*****************************************************************************
  366. void *GetTable( ulong Type, ulong *pResult )
  367. {
  368. GenericTable *pList2;
  369. ulong Result;
  370. ulong RetryCount = 0;
  371. ulong Size;
  372. if( verbose ){
  373. fprintf(stderr, "GetTable: type = %d\n", Type );
  374. }
  375. if ( Type > TYPE_MAX )
  376. {
  377. *pResult = ERROR_INVALID_PARAMETER;
  378. return ( NULL );
  379. }
  380. // Allocate memory for the list heads
  381. switch ( Type )
  382. {
  383. case TYPE_IF:
  384. Size = sizeof( IfEntry ) + MAX_IFDESCR_LEN;
  385. break;
  386. case TYPE_IP:
  387. case TYPE_IP6:
  388. Size = sizeof( IpEntry );
  389. break;
  390. case TYPE_IPADDR:
  391. Size = sizeof( IpAddrEntry );
  392. break;
  393. case TYPE_ROUTE:
  394. Size = sizeof( RouteEntry );
  395. break;
  396. case TYPE_ARP:
  397. Size = sizeof( ArpEntry );
  398. break;
  399. case TYPE_ICMP:
  400. Size = sizeof( IcmpEntry );
  401. break;
  402. case TYPE_ICMP6:
  403. Size = sizeof( Icmp6Entry );
  404. break;
  405. case TYPE_TCP:
  406. case TYPE_TCP6:
  407. Size = sizeof( TcpEntry );
  408. break;
  409. case TYPE_TCPCONN:
  410. Size = sizeof( TcpConnEntry );
  411. break;
  412. case TYPE_TCP6CONN:
  413. Size = sizeof( Tcp6ConnEntry );
  414. break;
  415. case TYPE_UDP:
  416. case TYPE_UDP6:
  417. Size = sizeof( UdpEntry );
  418. break;
  419. case TYPE_UDPCONN:
  420. Size = sizeof( UdpConnEntry );
  421. break;
  422. case TYPE_UDP6LISTENER:
  423. Size = sizeof( Udp6ListenerEntry );
  424. break;
  425. }
  426. // Don't need pList1 - MohsinA, 18-Feb-97.
  427. pList2 = (GenericTable *)SNMP_malloc( Size );
  428. if ( pList2 == NULL )
  429. {
  430. *pResult = ERROR_NOT_ENOUGH_MEMORY;
  431. return ( NULL );
  432. }
  433. InitializeListHead( &pList2->ListEntry );
  434. // Read the table into List2
  435. Result = ReadTable( pList2, Type, Size );
  436. if ( Result != NO_ERROR )
  437. {
  438. FreeTable( pList2 );
  439. *pResult = Result;
  440. return ( NULL );
  441. }
  442. // Useless while loop removed. - MohsinA, 18-Feb-97.
  443. *pResult = NO_ERROR;
  444. return ( pList2 );
  445. }
  446. //*****************************************************************************
  447. //
  448. // Name: FreeTable
  449. //
  450. // Description: Free all entries in the list, including the list head.
  451. //
  452. // Parameters: GenericTable *pList: pointer to head of list.
  453. //
  454. // Returns: void.
  455. //
  456. // History:
  457. // 01/12/94 JayPh Created.
  458. //
  459. //*****************************************************************************
  460. void FreeTable( GenericTable *pList )
  461. {
  462. GenericTable *pTmp;
  463. LIST_ENTRY *pTmpList;
  464. while ( !IsListEmpty( &pList->ListEntry ) )
  465. {
  466. pTmpList = RemoveHeadList( &pList->ListEntry );
  467. pTmp = CONTAINING_RECORD( pTmpList,
  468. GenericTable,
  469. ListEntry );
  470. SNMP_free( pTmp );
  471. }
  472. SNMP_free( pList );
  473. }
  474. //*****************************************************************************
  475. //
  476. // Name: MapSnmpErrorToNt
  477. //
  478. // Description: Given an Snmp error, return the 'equivalent' Nt error.
  479. //
  480. // Parameters: ulong ErrCode: Snmp error code.
  481. //
  482. // Returns: ulong: Nt error code.
  483. //
  484. // History:
  485. // 01/05/93 JayPh Created.
  486. //
  487. //*****************************************************************************
  488. ulong MapSnmpErrorToNt( ulong ErrCode )
  489. {
  490. switch ( ErrCode )
  491. {
  492. case SNMP_ERRORSTATUS_NOERROR:
  493. return ( NO_ERROR );
  494. case SNMP_ERRORSTATUS_TOOBIG:
  495. return ( ERROR_INVALID_PARAMETER );
  496. case SNMP_ERRORSTATUS_NOSUCHNAME:
  497. return ( ERROR_INVALID_PARAMETER );
  498. case SNMP_ERRORSTATUS_BADVALUE:
  499. return ( ERROR_INVALID_PARAMETER );
  500. case SNMP_ERRORSTATUS_READONLY:
  501. return ( ERROR_INVALID_ACCESS );
  502. case SNMP_ERRORSTATUS_GENERR:
  503. return ( ERROR_INVALID_PARAMETER );
  504. }
  505. return ( ERROR_INVALID_PARAMETER );
  506. }
  507. //
  508. // Internal Functions
  509. //
  510. //*****************************************************************************
  511. //
  512. // Name: ReadTable
  513. //
  514. // Description: Queries the MIB and builds a table representing the data we are
  515. // interested in.
  516. //
  517. // Parameters: GenericTable *pList: address of uninitialized head of the entry
  518. // list.
  519. // ulong Type: type of table we want.
  520. // ulong Size: size of a table entry.
  521. //
  522. // Returns: ulong: NO_ERROR if no error, and table is built.
  523. //
  524. // History:
  525. // 01/12/94 JayPh Created.
  526. //
  527. //*****************************************************************************
  528. ulong ReadTable( GenericTable *pList, ulong Type, ulong Size )
  529. {
  530. AsnInteger GetNextReq = ASN_RFC1157_GETNEXTREQUEST;
  531. RFC1157VarBind item;
  532. RFC1157VarBindList VarBinds = { &item, 1 };
  533. AsnObjectIdentifier oidBackup;
  534. AsnInteger ErrorStatus = 0;
  535. AsnInteger ErrorIndex = 0;
  536. ulong *pId;
  537. GenericTable *pTable;
  538. ulong LastField = 0;
  539. uchar *pTmp;
  540. ulong i;
  541. OIDdef *pOid;
  542. ulong BreakLoop = FALSE;
  543. if( verbose ){
  544. fprintf(stderr,"ReadTable: type = %d\n", Type);
  545. }
  546. switch (Type) {
  547. case TYPE_IP6: {
  548. IpEntry *pIp = (IpEntry*)pList;
  549. // IPStats are the same, but not in contiguous MIB oids,
  550. // so it's non-trivial to get them from the MIB in this
  551. // structure. Instead, rather than going the long way
  552. // around, we can just get them directly here.
  553. return GetIpStatsFromStackEx((PMIB_IPSTATS)&pIp->Info, AF_INET6);
  554. }
  555. case TYPE_ICMP6: {
  556. Icmp6Entry *pIcmp = (Icmp6Entry*)pList;
  557. return GetIcmpStatsFromStackEx((PVOID)&pIcmp->InInfo, AF_INET6);
  558. }
  559. case TYPE_TCP: {
  560. TcpEntry *pTcp = (TcpEntry*)pList;
  561. // TCP stats for IPv4-only aren't in the MIB, so get them
  562. // directly from the stack.
  563. return GetTcpStatsFromStackEx((PMIB_TCPSTATS)&pTcp->Info, AF_INET);
  564. }
  565. case TYPE_TCP6: {
  566. TcpEntry *pTcp = (TcpEntry*)pList;
  567. // TCP stats for IPv6-only aren't in the MIB, so get them
  568. // directly from the stack.
  569. return GetTcpStatsFromStackEx((PMIB_TCPSTATS)&pTcp->Info, AF_INET6);
  570. }
  571. case TYPE_UDP: {
  572. UdpEntry *pUdp = (UdpEntry*)pList;
  573. // UDP stats for IPv4-only aren't in the MIB, so get them
  574. // directly from the stack.
  575. return GetUdpStatsFromStackEx((PMIB_UDPSTATS)&pUdp->Info, AF_INET);
  576. }
  577. case TYPE_UDP6: {
  578. UdpEntry *pUdp = (UdpEntry*)pList;
  579. // UDP stats for IPv6-only aren't in the MIB, so get them
  580. // directly from the stack.
  581. return GetUdpStatsFromStackEx((PMIB_UDPSTATS)&pUdp->Info, AF_INET6);
  582. }
  583. }
  584. // Walk SNMP database, building local table.
  585. pId = (ulong *)SNMP_malloc( (sizeof( ulong ) * MAX_ID_LENGTH) );
  586. if ( pId == NULL )
  587. {
  588. return ( ERROR_NOT_ENOUGH_MEMORY );
  589. }
  590. item.name.ids = pId;
  591. // Build OID from preamble and table-specific suffix
  592. // Copy preamble
  593. for ( i = 0; i < PreambleDef.Length; i++ )
  594. {
  595. *pId++ = PreambleDef.Val[i];
  596. }
  597. // Get pointer to table-specific info
  598. switch ( Type )
  599. {
  600. case TYPE_IF:
  601. pOid = &IfInfoDef;
  602. break;
  603. case TYPE_IP:
  604. pOid = &IPInfoDef;
  605. break;
  606. case TYPE_IPADDR:
  607. pOid = &IPAddrInfoDef;
  608. break;
  609. case TYPE_ROUTE:
  610. pOid = &RouteInfoDef;
  611. break;
  612. case TYPE_ARP:
  613. pOid = &ARPInfoDef;
  614. break;
  615. case TYPE_ICMP:
  616. pOid = &ICMPInfoDef;
  617. break;
  618. case TYPE_TCPCONN:
  619. pOid = &TCPConnDef;
  620. break;
  621. case TYPE_TCP6CONN:
  622. pOid = &TCP6ConnDef;
  623. break;
  624. case TYPE_UDPCONN:
  625. pOid = &UDPConnDef;
  626. break;
  627. case TYPE_UDP6LISTENER:
  628. pOid = &UDP6ListenerDef;
  629. break;
  630. }
  631. // Copy table-specific info
  632. for ( i = 0; i < pOid->Length; i++ )
  633. {
  634. *pId++ = pOid->Val[i];
  635. }
  636. item.name.idLength = PreambleDef.Length + pOid->Length;
  637. item.value.asnType = ASN_NULL;
  638. pTable = pList;
  639. // Walk the mib until the table-specific termination condition is met.
  640. while( 1 )
  641. {
  642. // Get next
  643. (*gQueryAddr)( GetNextReq, &VarBinds, &ErrorStatus, &ErrorIndex );
  644. if( verbose )
  645. {
  646. int q;
  647. fprintf(stderr,"value=%8d oid= ", item.value.asnValue.number );
  648. //
  649. // Print the object name, use mgmtapi.dll.
  650. //
  651. if( pSnmpMgrOidToStr ){
  652. LPSTR String = NULL;
  653. int err;
  654. err = (* pSnmpMgrOidToStr )( &item.name, &String );
  655. if( SNMPAPI_ERROR != err ){
  656. fprintf(stderr," %s ", String );
  657. }
  658. SnmpUtilMemFree( String );
  659. }
  660. if( !pSnmpMgrOidToStr || (verbose > 1) ){
  661. //
  662. // Print the oid, in ``1.3.6.1.2.1'' style.
  663. //
  664. for ( q = 0; q < (int) item.name.idLength; q++ ){
  665. // Must align the output to read huge tables.
  666. if( q < 6 ){
  667. fprintf( stderr,"%d.", item.name.ids[q]);
  668. }else if( q < 9 ){
  669. fprintf( stderr,"%2d.", item.name.ids[q]);
  670. }else{
  671. fprintf( stderr,"%3d.", item.name.ids[q]);
  672. }
  673. }
  674. }
  675. fprintf(stderr,"\n");
  676. }
  677. if ( ErrorStatus != 0 )
  678. {
  679. SnmpUtilVarBindFree( &item );
  680. return ( MapSnmpErrorToNt( ErrorStatus ) );
  681. }
  682. // We want to break out of this while loop if the defining part of the
  683. // OID changes
  684. if ( item.name.idLength < ( PreambleDef.Length + pOid->Length ) )
  685. {
  686. break;
  687. }
  688. for ( i = PreambleDef.Length;
  689. i < PreambleDef.Length + pOid->Length - pOid->BackOffset;
  690. i++ )
  691. {
  692. if ( item.name.ids[i] != pOid->Val[i - PreambleDef.Length] )
  693. {
  694. BreakLoop = TRUE;
  695. break;
  696. }
  697. }
  698. if ( BreakLoop )
  699. {
  700. break;
  701. }
  702. // We want to ignore certain entries. EG: the TCP statistics will also
  703. // return the TCP connection table, which we don't want (there is a
  704. // separate Type code for that).
  705. switch ( Type )
  706. {
  707. case TYPE_IP:
  708. if ( ( item.name.ids[pOid->EntElemOffset] == ID_IP_ADDRTABLE ) ||
  709. ( item.name.ids[pOid->EntElemOffset] == ID_IP_ROUTETABLE ) ||
  710. ( item.name.ids[pOid->EntElemOffset] == ID_IP_ARPTABLE ) )
  711. {
  712. continue;
  713. }
  714. break;
  715. case TYPE_TCP:
  716. if ( item.name.ids[pOid->EntElemOffset] == ID_TCP_CONNTABLE )
  717. {
  718. continue;
  719. }
  720. break;
  721. case TYPE_UDP:
  722. if ( item.name.ids[pOid->EntElemOffset] == ID_UDP_CONNTABLE )
  723. {
  724. continue;
  725. }
  726. break;
  727. case TYPE_TCP6CONN:
  728. if ( item.name.ids[10] != 2 )
  729. {
  730. // ignore non-IPv6 entries
  731. continue;
  732. }
  733. break;
  734. case TYPE_UDP6LISTENER:
  735. if ( item.name.ids[10] != 2 )
  736. {
  737. // ignore non-IPv6 entries
  738. continue;
  739. }
  740. break;
  741. }
  742. // Entry handling:
  743. //
  744. // There are 3 cases to consider:
  745. // 1. If the list is empty, OR at the end of the list AND the
  746. // CurrField == LastField.
  747. // Then add a new entry to the list.
  748. // 2. CurrField != LastField.
  749. // Then reset pointer to start of the list.
  750. // 3. Otherwise
  751. // Then go to next entry in the list.
  752. if ( ( pTable == pList ) ||
  753. ( ( pTable->ListEntry.Flink == &pList->ListEntry ) &&
  754. ( item.name.ids[pOid->EntElemOffset] == LastField ) ) )
  755. {
  756. // Add new entry to table
  757. pTable = (GenericTable *)SNMP_malloc( Size );
  758. if ( pTable == NULL )
  759. {
  760. SnmpUtilVarBindFree( &item );
  761. return ( ERROR_NOT_ENOUGH_MEMORY );
  762. }
  763. InsertTailList( &pList->ListEntry, &pTable->ListEntry );
  764. }
  765. else if ( item.name.ids[pOid->EntElemOffset] != LastField )
  766. {
  767. // Reset pointer to start of list
  768. pTable = CONTAINING_RECORD( pList->ListEntry.Flink,
  769. GenericTable,
  770. ListEntry );
  771. }
  772. else
  773. {
  774. // Move pointer to next entry in list
  775. pTable = CONTAINING_RECORD( pTable->ListEntry.Flink,
  776. GenericTable,
  777. ListEntry );
  778. }
  779. LastField = item.name.ids[pOid->EntElemOffset];
  780. // Save info in our list. pTable points to desired entry.
  781. switch ( Type )
  782. {
  783. case TYPE_IF:
  784. SaveData_IF( pTable, item, pOid );
  785. break;
  786. case TYPE_IP:
  787. SaveData_IP( pTable, item, pOid );
  788. break;
  789. case TYPE_IPADDR:
  790. SaveData_IPAddr( pTable, item, pOid );
  791. break;
  792. case TYPE_ROUTE:
  793. SaveData_ROUTE( pTable, item, pOid );
  794. break;
  795. case TYPE_ARP:
  796. SaveData_ARP( pTable, item, pOid );
  797. break;
  798. case TYPE_ICMP:
  799. SaveData_ICMP( pTable, item, pOid );
  800. break;
  801. case TYPE_TCP:
  802. case TYPE_TCP6:
  803. SaveData_TCP( pTable, item, pOid );
  804. break;
  805. case TYPE_TCPCONN:
  806. SaveData_TCPCONN( pTable, item, pOid );
  807. break;
  808. case TYPE_TCP6CONN:
  809. SaveData_TCP6CONN( pTable, item, pOid );
  810. break;
  811. case TYPE_UDP:
  812. case TYPE_UDP6:
  813. SaveData_UDP( pTable, item, pOid );
  814. break;
  815. case TYPE_UDPCONN:
  816. SaveData_UDPCONN( pTable, item, pOid );
  817. break;
  818. case TYPE_UDP6LISTENER:
  819. SaveData_UDP6LISTENER( pTable, item, pOid );
  820. break;
  821. }
  822. SnmpUtilOidCpy( &oidBackup, &(item.name));
  823. SnmpUtilVarBindFree( &item );
  824. item.name.idLength = oidBackup.idLength;
  825. item.name.ids = oidBackup.ids;
  826. }
  827. SnmpUtilVarBindFree( &item );
  828. return ( NO_ERROR );
  829. }
  830. //*****************************************************************************
  831. //
  832. // Name: SaveData_IF
  833. //
  834. // Description: Saves an element of the data in the interface table.
  835. //
  836. // Parameters: GenericTable *pEntry; pointer to table entry.
  837. // RFC1157VarBind item: contains value returned from mib.
  838. // OIDdef *pOid: contains table-specific data.
  839. //
  840. // Returns: void.
  841. //
  842. // History:
  843. // 01/12/94 JayPh Created.
  844. //
  845. //*****************************************************************************
  846. void SaveData_IF( GenericTable *pEntry,
  847. RFC1157VarBind item,
  848. OIDdef *pOid )
  849. {
  850. IfEntry *pIf = ( IfEntry *)pEntry;
  851. uchar *pTmp;
  852. ulong i;
  853. switch ( item.name.ids[pOid->EntElemOffset] )
  854. {
  855. case ID_IF_INDEX:
  856. pIf->Info.if_index = item.value.asnValue.number;
  857. break;
  858. case ID_IF_DESC:
  859. pIf->Info.if_descrlen = item.value.asnValue.string.length;
  860. for ( i = 0; i < pIf->Info.if_descrlen; i++ )
  861. {
  862. pIf->Info.if_descr[i] = item.value.asnValue.string.stream[i];
  863. }
  864. break;
  865. case ID_IF_TYPE:
  866. pIf->Info.if_type = item.value.asnValue.number;
  867. break;
  868. case ID_IF_MTU:
  869. pIf->Info.if_mtu = item.value.asnValue.number;
  870. break;
  871. case ID_IF_SPEED:
  872. pIf->Info.if_speed = item.value.asnValue.number;
  873. break;
  874. case ID_IF_PHYSADDR:
  875. pIf->Info.if_physaddrlen = item.value.asnValue.string.length;
  876. for ( i = 0; i < pIf->Info.if_physaddrlen; i++ )
  877. {
  878. pIf->Info.if_physaddr[i] = item.value.asnValue.string.stream[i];
  879. }
  880. break;
  881. case ID_IF_ADMINSTATUS:
  882. pIf->Info.if_adminstatus = item.value.asnValue.number;
  883. break;
  884. case ID_IF_OPERSTATUS:
  885. pIf->Info.if_operstatus = item.value.asnValue.number;
  886. break;
  887. case ID_IF_LASTCHANGE:
  888. pIf->Info.if_lastchange = item.value.asnValue.number;
  889. break;
  890. case ID_IF_INOCTETS:
  891. pIf->Info.if_inoctets = item.value.asnValue.number;
  892. break;
  893. case ID_IF_INUCASTPKTS:
  894. pIf->Info.if_inucastpkts = item.value.asnValue.number;
  895. break;
  896. case ID_IF_INNUCASTPKTS:
  897. pIf->Info.if_innucastpkts = item.value.asnValue.number;
  898. break;
  899. case ID_IF_INDISCARDS:
  900. pIf->Info.if_indiscards = item.value.asnValue.number;
  901. break;
  902. case ID_IF_INERRORS:
  903. pIf->Info.if_inerrors = item.value.asnValue.number;
  904. break;
  905. case ID_IF_INUKNOWNPROTOS:
  906. pIf->Info.if_inunknownprotos = item.value.asnValue.number;
  907. break;
  908. case ID_IF_OUTOCTETS:
  909. pIf->Info.if_outoctets = item.value.asnValue.number;
  910. break;
  911. case ID_IF_OUTUCASTPKTS:
  912. pIf->Info.if_outucastpkts = item.value.asnValue.number;
  913. break;
  914. case ID_IF_OUTNUCASTPKTS:
  915. pIf->Info.if_outnucastpkts = item.value.asnValue.number;
  916. break;
  917. case ID_IF_OUTDISCARDS:
  918. pIf->Info.if_outdiscards = item.value.asnValue.number;
  919. break;
  920. case ID_IF_OUTERRORS:
  921. pIf->Info.if_outerrors = item.value.asnValue.number;
  922. break;
  923. case ID_IF_OUTQLEN:
  924. pIf->Info.if_outqlen = item.value.asnValue.number;
  925. break;
  926. }
  927. }
  928. //*****************************************************************************
  929. //
  930. // Name: SaveData_IP
  931. //
  932. // Description: Saves an element of the data in the IP table.
  933. //
  934. // Parameters: GenericTable *pEntry; pointer to table entry.
  935. // RFC1157VarBind item: contains value returned from mib.
  936. // OIDdef *pOid: contains table-specific data.
  937. //
  938. // Returns: void.
  939. //
  940. // History:
  941. // 01/12/94 JayPh Created.
  942. //
  943. //*****************************************************************************
  944. void SaveData_IP( GenericTable *pEntry,
  945. RFC1157VarBind item,
  946. OIDdef *pOid )
  947. {
  948. IpEntry *pIp = (IpEntry *)pEntry;
  949. uchar *pTmp;
  950. switch ( item.name.ids[pOid->EntElemOffset] )
  951. {
  952. case ID_IP_FORWARDING:
  953. pIp->Info.ipsi_forwarding = item.value.asnValue.number;
  954. break;
  955. case ID_IP_DEFAULTTTL:
  956. pIp->Info.ipsi_defaultttl = item.value.asnValue.number;
  957. break;
  958. case ID_IP_INRECEIVES:
  959. pIp->Info.ipsi_inreceives = item.value.asnValue.number;
  960. break;
  961. case ID_IP_INHDRERRORS:
  962. pIp->Info.ipsi_inhdrerrors = item.value.asnValue.number;
  963. break;
  964. case ID_IP_INADDRERRORS:
  965. pIp->Info.ipsi_inaddrerrors = item.value.asnValue.number;
  966. break;
  967. case ID_IP_FORWDATAGRAMS:
  968. pIp->Info.ipsi_forwdatagrams = item.value.asnValue.number;
  969. break;
  970. case ID_IP_INUNKNOWNPROTOS:
  971. pIp->Info.ipsi_inunknownprotos = item.value.asnValue.number;
  972. break;
  973. case ID_IP_INDISCARDS:
  974. pIp->Info.ipsi_indiscards = item.value.asnValue.number;
  975. break;
  976. case ID_IP_INDELIVERS:
  977. pIp->Info.ipsi_indelivers = item.value.asnValue.number;
  978. break;
  979. case ID_IP_OUTREQUESTS:
  980. pIp->Info.ipsi_outrequests = item.value.asnValue.number;
  981. break;
  982. case ID_IP_OUTDISCARDS:
  983. pIp->Info.ipsi_outdiscards = item.value.asnValue.number;
  984. break;
  985. case ID_IP_OUTNOROUTES:
  986. pIp->Info.ipsi_outnoroutes = item.value.asnValue.number;
  987. break;
  988. case ID_IP_REASMTIMEOUTS:
  989. pIp->Info.ipsi_reasmtimeout = item.value.asnValue.number;
  990. break;
  991. case ID_IP_REASMREQDS:
  992. pIp->Info.ipsi_reasmreqds = item.value.asnValue.number;
  993. break;
  994. case ID_IP_REASMOKS:
  995. pIp->Info.ipsi_reasmoks = item.value.asnValue.number;
  996. break;
  997. case ID_IP_REASMFAILS:
  998. pIp->Info.ipsi_reasmfails = item.value.asnValue.number;
  999. break;
  1000. case ID_IP_FRAGOKS:
  1001. pIp->Info.ipsi_fragoks = item.value.asnValue.number;
  1002. break;
  1003. case ID_IP_FRAGFAILS:
  1004. pIp->Info.ipsi_fragfails = item.value.asnValue.number;
  1005. break;
  1006. case ID_IP_FRAGCREATES:
  1007. pIp->Info.ipsi_fragcreates = item.value.asnValue.number;
  1008. break;
  1009. }
  1010. }
  1011. //*****************************************************************************
  1012. //
  1013. // Name: SaveData_IPAddr
  1014. //
  1015. // Description: Saves an element of the data in the IP table.
  1016. //
  1017. // Parameters: GenericTable *pEntry; pointer to table entry.
  1018. // RFC1157VarBind item: contains value returned from mib.
  1019. // OIDdef *pOid: contains table-specific data.
  1020. //
  1021. // Returns: void.
  1022. //
  1023. // History:
  1024. // 01/12/94 JayPh Created.
  1025. //
  1026. //*****************************************************************************
  1027. void SaveData_IPAddr( GenericTable *pEntry,
  1028. RFC1157VarBind item,
  1029. OIDdef *pOid )
  1030. {
  1031. IpAddrEntry *pIpAddr = (IpAddrEntry *)pEntry;
  1032. uchar *pTmp;
  1033. switch ( item.name.ids[pOid->EntElemOffset] )
  1034. {
  1035. case ID_IPADDR_ADDR:
  1036. pTmp = (uchar *)&(pIpAddr->Info.iae_addr);
  1037. pTmp[0] = item.value.asnValue.string.stream[0];
  1038. pTmp[1] = item.value.asnValue.string.stream[1];
  1039. pTmp[2] = item.value.asnValue.string.stream[2];
  1040. pTmp[3] = item.value.asnValue.string.stream[3];
  1041. break;
  1042. case ID_IPADDR_INDEX:
  1043. pIpAddr->Info.iae_index = item.value.asnValue.number;
  1044. break;
  1045. case ID_IPADDR_MASK:
  1046. pTmp = (uchar *)&(pIpAddr->Info.iae_mask);
  1047. pTmp[0] = item.value.asnValue.string.stream[0];
  1048. pTmp[1] = item.value.asnValue.string.stream[1];
  1049. pTmp[2] = item.value.asnValue.string.stream[2];
  1050. pTmp[3] = item.value.asnValue.string.stream[3];
  1051. break;
  1052. case ID_IPADDR_BCASTADDR:
  1053. pIpAddr->Info.iae_bcastaddr = item.value.asnValue.number;
  1054. break;
  1055. case ID_IPADDR_REASMSIZE:
  1056. pIpAddr->Info.iae_reasmsize = item.value.asnValue.number;
  1057. break;
  1058. }
  1059. }
  1060. //*****************************************************************************
  1061. //
  1062. // Name: SaveData_ROUTE
  1063. //
  1064. // Description: Saves an element of the data in the ROUTE table.
  1065. //
  1066. // Parameters: GenericTable *pEntry; pointer to table entry.
  1067. // RFC1157VarBind item: contains value returned from mib.
  1068. // OIDdef *pOid: contains table-specific data.
  1069. //
  1070. // Returns: void.
  1071. //
  1072. // History:
  1073. // 01/12/94 JayPh Created.
  1074. //
  1075. //*****************************************************************************
  1076. void SaveData_ROUTE( GenericTable *pEntry,
  1077. RFC1157VarBind item,
  1078. OIDdef *pOid )
  1079. {
  1080. RouteEntry *pRoute = (RouteEntry *)pEntry;
  1081. uchar *pTmp;
  1082. switch ( item.name.ids[pOid->EntElemOffset] )
  1083. {
  1084. case ID_ROUTE_DEST:
  1085. pTmp = (uchar *)&(pRoute->Info.ire_dest);
  1086. pTmp[0] = item.value.asnValue.string.stream[0];
  1087. pTmp[1] = item.value.asnValue.string.stream[1];
  1088. pTmp[2] = item.value.asnValue.string.stream[2];
  1089. pTmp[3] = item.value.asnValue.string.stream[3];
  1090. break;
  1091. case ID_ROUTE_IFINDEX:
  1092. pRoute->Info.ire_index = item.value.asnValue.number;
  1093. break;
  1094. case ID_ROUTE_METRIC1:
  1095. pRoute->Info.ire_metric1 = item.value.asnValue.number;
  1096. break;
  1097. case ID_ROUTE_METRIC2:
  1098. pRoute->Info.ire_metric2 = item.value.asnValue.number;
  1099. break;
  1100. case ID_ROUTE_METRIC3:
  1101. pRoute->Info.ire_metric3 = item.value.asnValue.number;
  1102. break;
  1103. case ID_ROUTE_METRIC4:
  1104. pRoute->Info.ire_metric4 = item.value.asnValue.number;
  1105. break;
  1106. case ID_ROUTE_NEXTHOP:
  1107. pTmp = (uchar *)&(pRoute->Info.ire_nexthop);
  1108. pTmp[0] = item.value.asnValue.string.stream[0];
  1109. pTmp[1] = item.value.asnValue.string.stream[1];
  1110. pTmp[2] = item.value.asnValue.string.stream[2];
  1111. pTmp[3] = item.value.asnValue.string.stream[3];
  1112. break;
  1113. case ID_ROUTE_TYPE:
  1114. pRoute->Info.ire_type = item.value.asnValue.number;
  1115. break;
  1116. case ID_ROUTE_PROTO:
  1117. pRoute->Info.ire_proto = item.value.asnValue.number;
  1118. break;
  1119. case ID_ROUTE_AGE:
  1120. pRoute->Info.ire_age = item.value.asnValue.number;
  1121. break;
  1122. case ID_ROUTE_MASK:
  1123. pTmp = (uchar *)&(pRoute->Info.ire_mask);
  1124. pTmp[0] = item.value.asnValue.string.stream[0];
  1125. pTmp[1] = item.value.asnValue.string.stream[1];
  1126. pTmp[2] = item.value.asnValue.string.stream[2];
  1127. pTmp[3] = item.value.asnValue.string.stream[3];
  1128. break;
  1129. case ID_ROUTE_METRIC5:
  1130. pRoute->Info.ire_metric5 = item.value.asnValue.number;
  1131. break;
  1132. }
  1133. }
  1134. //*****************************************************************************
  1135. //
  1136. // Name: SaveData_ARP
  1137. //
  1138. // Description: Saves an element of the data in the ARP table.
  1139. //
  1140. // Parameters: GenericTable *pEntry; pointer to table entry.
  1141. // RFC1157VarBind item: contains value returned from mib.
  1142. // OIDdef *pOid: contains table-specific data.
  1143. //
  1144. // Returns: void.
  1145. //
  1146. // History:
  1147. // 01/12/94 JayPh Created.
  1148. //
  1149. //*****************************************************************************
  1150. void SaveData_ARP( GenericTable *pEntry,
  1151. RFC1157VarBind item,
  1152. OIDdef *pOid )
  1153. {
  1154. ArpEntry *pArp = (ArpEntry *)pEntry;
  1155. uchar *pTmp;
  1156. ulong i;
  1157. switch ( item.name.ids[pOid->EntElemOffset] )
  1158. {
  1159. case ID_ARP_IFINDEX:
  1160. pArp->Info.inme_index = item.value.asnValue.number;
  1161. break;
  1162. case ID_ARP_PHYSADDR:
  1163. pArp->Info.inme_physaddrlen = item.value.asnValue.string.length;
  1164. for ( i = 0; i < pArp->Info.inme_physaddrlen; i++ )
  1165. {
  1166. pArp->Info.inme_physaddr[i] = item.value.asnValue.string.stream[i];
  1167. }
  1168. break;
  1169. case ID_ARP_NETADDR:
  1170. pTmp = (uchar *)&(pArp->Info.inme_addr);
  1171. pTmp[0] = item.value.asnValue.string.stream[0];
  1172. pTmp[1] = item.value.asnValue.string.stream[1];
  1173. pTmp[2] = item.value.asnValue.string.stream[2];
  1174. pTmp[3] = item.value.asnValue.string.stream[3];
  1175. break;
  1176. case ID_ARP_TYPE:
  1177. pArp->Info.inme_type = item.value.asnValue.number;
  1178. break;
  1179. }
  1180. }
  1181. //*****************************************************************************
  1182. //
  1183. // Name: SaveData_ICMP
  1184. //
  1185. // Description: Saves an element of the data in the ICMP table.
  1186. //
  1187. // Parameters: GenericTable *pEntry; pointer to table entry.
  1188. // RFC1157VarBind item: contains value returned from mib.
  1189. // OIDdef *pOid: contains table-specific data.
  1190. //
  1191. // Returns: void.
  1192. //
  1193. // History:
  1194. // 01/12/94 JayPh Created.
  1195. //
  1196. //*****************************************************************************
  1197. void SaveData_ICMP( GenericTable *pEntry,
  1198. RFC1157VarBind item,
  1199. OIDdef *pOid )
  1200. {
  1201. IcmpEntry *pIcmp = (IcmpEntry *)pEntry;
  1202. uchar *pTmp;
  1203. switch ( item.name.ids[pOid->EntElemOffset] )
  1204. {
  1205. case ID_ICMP_INMSGS:
  1206. pIcmp->InInfo.icmps_msgs = item.value.asnValue.number;
  1207. break;
  1208. case ID_ICMP_INERRORS:
  1209. pIcmp->InInfo.icmps_errors = item.value.asnValue.number;
  1210. break;
  1211. case ID_ICMP_INDESTUNREACHES:
  1212. pIcmp->InInfo.icmps_destunreachs = item.value.asnValue.number;
  1213. break;
  1214. case ID_ICMP_INTIMEEXCDS:
  1215. pIcmp->InInfo.icmps_timeexcds = item.value.asnValue.number;
  1216. break;
  1217. case ID_ICMP_INPARMPROBS:
  1218. pIcmp->InInfo.icmps_parmprobs = item.value.asnValue.number;
  1219. break;
  1220. case ID_ICMP_INSRCQUENCHS:
  1221. pIcmp->InInfo.icmps_srcquenchs = item.value.asnValue.number;
  1222. break;
  1223. case ID_ICMP_INREDIRECTS:
  1224. pIcmp->InInfo.icmps_redirects = item.value.asnValue.number;
  1225. break;
  1226. case ID_ICMP_INECHOS:
  1227. pIcmp->InInfo.icmps_echos = item.value.asnValue.number;
  1228. break;
  1229. case ID_ICMP_INECHOREPS:
  1230. pIcmp->InInfo.icmps_echoreps = item.value.asnValue.number;
  1231. break;
  1232. case ID_ICMP_INTIMESTAMPS:
  1233. pIcmp->InInfo.icmps_timestamps = item.value.asnValue.number;
  1234. break;
  1235. case ID_ICMP_INTIMESTAMPREPS:
  1236. pIcmp->InInfo.icmps_timestampreps = item.value.asnValue.number;
  1237. break;
  1238. case ID_ICMP_INADDRMASKS:
  1239. pIcmp->InInfo.icmps_addrmasks = item.value.asnValue.number;
  1240. break;
  1241. case ID_ICMP_INADDRMASKREPS:
  1242. pIcmp->InInfo.icmps_addrmaskreps = item.value.asnValue.number;
  1243. break;
  1244. case ID_ICMP_OUTMSGS:
  1245. pIcmp->OutInfo.icmps_msgs = item.value.asnValue.number;
  1246. break;
  1247. case ID_ICMP_OUTERRORS:
  1248. pIcmp->OutInfo.icmps_errors = item.value.asnValue.number;
  1249. break;
  1250. case ID_ICMP_OUTDESTUNREACHES:
  1251. pIcmp->OutInfo.icmps_destunreachs = item.value.asnValue.number;
  1252. break;
  1253. case ID_ICMP_OUTTIMEEXCDS:
  1254. pIcmp->OutInfo.icmps_timeexcds = item.value.asnValue.number;
  1255. break;
  1256. case ID_ICMP_OUTPARMPROBS:
  1257. pIcmp->OutInfo.icmps_parmprobs = item.value.asnValue.number;
  1258. break;
  1259. case ID_ICMP_OUTSRCQUENCHS:
  1260. pIcmp->OutInfo.icmps_srcquenchs = item.value.asnValue.number;
  1261. break;
  1262. case ID_ICMP_OUTREDIRECTS:
  1263. pIcmp->OutInfo.icmps_redirects = item.value.asnValue.number;
  1264. break;
  1265. case ID_ICMP_OUTECHOS:
  1266. pIcmp->OutInfo.icmps_echos = item.value.asnValue.number;
  1267. break;
  1268. case ID_ICMP_OUTECHOREPS:
  1269. pIcmp->OutInfo.icmps_echoreps = item.value.asnValue.number;
  1270. break;
  1271. case ID_ICMP_OUTTIMESTAMPS:
  1272. pIcmp->OutInfo.icmps_timestamps = item.value.asnValue.number;
  1273. break;
  1274. case ID_ICMP_OUTTIMESTAMPREPS:
  1275. pIcmp->OutInfo.icmps_timestampreps = item.value.asnValue.number;
  1276. break;
  1277. case ID_ICMP_OUTADDRMASKS:
  1278. pIcmp->OutInfo.icmps_addrmasks = item.value.asnValue.number;
  1279. break;
  1280. case ID_ICMP_OUTADDRMASKREPS:
  1281. pIcmp->OutInfo.icmps_addrmaskreps = item.value.asnValue.number;
  1282. break;
  1283. }
  1284. }
  1285. //*****************************************************************************
  1286. //
  1287. // Name: SaveData_TCP
  1288. //
  1289. // Description: Saves an element of the data in the TCP table.
  1290. //
  1291. // Parameters: GenericTable *pEntry; pointer to table entry.
  1292. // RFC1157VarBind item: contains value returned from mib.
  1293. // OIDdef *pOid: contains table-specific data.
  1294. //
  1295. // Returns: void.
  1296. //
  1297. // History:
  1298. // 01/12/94 JayPh Created.
  1299. //
  1300. //*****************************************************************************
  1301. void SaveData_TCP( GenericTable *pEntry,
  1302. RFC1157VarBind item,
  1303. OIDdef *pOid )
  1304. {
  1305. TcpEntry *pTcp = (TcpEntry *)pEntry;
  1306. uchar *pTmp;
  1307. switch ( item.name.ids[pOid->EntElemOffset] )
  1308. {
  1309. case ID_TCP_RTOALGORITHM:
  1310. pTcp->Info.ts_rtoalgorithm = item.value.asnValue.number;
  1311. break;
  1312. case ID_TCP_RTOMIN:
  1313. pTcp->Info.ts_rtomin = item.value.asnValue.number;
  1314. break;
  1315. case ID_TCP_RTOMAX:
  1316. pTcp->Info.ts_rtomax = item.value.asnValue.number;
  1317. break;
  1318. case ID_TCP_MAXCONN:
  1319. pTcp->Info.ts_maxconn = item.value.asnValue.number;
  1320. break;
  1321. case ID_TCP_ACTIVEOPENS:
  1322. pTcp->Info.ts_activeopens = item.value.asnValue.number;
  1323. break;
  1324. case ID_TCP_PASSIVEOPENS:
  1325. pTcp->Info.ts_passiveopens = item.value.asnValue.number;
  1326. break;
  1327. case ID_TCP_ATTEMPTFAILS:
  1328. pTcp->Info.ts_attemptfails = item.value.asnValue.number;
  1329. break;
  1330. case ID_TCP_ESTABRESETS:
  1331. pTcp->Info.ts_estabresets = item.value.asnValue.number;
  1332. break;
  1333. case ID_TCP_CURRESTABS:
  1334. pTcp->Info.ts_currestab = item.value.asnValue.number;
  1335. break;
  1336. case ID_TCP_INSEGS:
  1337. pTcp->Info.ts_insegs = item.value.asnValue.number;
  1338. break;
  1339. case ID_TCP_OUTSEGS:
  1340. pTcp->Info.ts_outsegs = item.value.asnValue.number;
  1341. break;
  1342. case ID_TCP_RETRANSSEGS:
  1343. pTcp->Info.ts_retranssegs = item.value.asnValue.number;
  1344. break;
  1345. case ID_TCP_INERRS:
  1346. pTcp->Info.ts_inerrs = item.value.asnValue.number;
  1347. break;
  1348. case ID_TCP_OUTRSTS:
  1349. pTcp->Info.ts_outrsts = item.value.asnValue.number;
  1350. break;
  1351. }
  1352. }
  1353. //*****************************************************************************
  1354. //
  1355. // Name: SaveData_TCPCONN
  1356. //
  1357. // Description: Saves an element of the data in the TCP connection table.
  1358. //
  1359. // Parameters: GenericTable *pEntry; pointer to table entry.
  1360. // RFC1157VarBind item: contains value returned from mib.
  1361. // OIDdef *pOid: contains table-specific data.
  1362. //
  1363. // Returns: void.
  1364. //
  1365. // History:
  1366. // 01/12/94 JayPh Created.
  1367. //
  1368. //*****************************************************************************
  1369. void SaveData_TCPCONN( GenericTable *pEntry,
  1370. RFC1157VarBind item,
  1371. OIDdef *pOid )
  1372. {
  1373. TcpConnEntry *pTcp = (TcpConnEntry *)pEntry;
  1374. uchar *pTmp;
  1375. switch ( item.name.ids[pOid->EntElemOffset] )
  1376. {
  1377. case ID_TCPCONN_STATE:
  1378. pTcp->Info.tct_state = item.value.asnValue.number;
  1379. break;
  1380. case ID_TCPCONN_LOCALADDR:
  1381. pTmp = (uchar *)&(pTcp->Info.tct_localaddr);
  1382. pTmp[0] = item.value.asnValue.string.stream[0];
  1383. pTmp[1] = item.value.asnValue.string.stream[1];
  1384. pTmp[2] = item.value.asnValue.string.stream[2];
  1385. pTmp[3] = item.value.asnValue.string.stream[3];
  1386. break;
  1387. case ID_TCPCONN_LOCALPORT:
  1388. pTcp->Info.tct_localport = item.value.asnValue.number;
  1389. break;
  1390. case ID_TCPCONN_REMOTEADDR:
  1391. pTmp = (uchar *)&(pTcp->Info.tct_remoteaddr);
  1392. pTmp[0] = item.value.asnValue.string.stream[0];
  1393. pTmp[1] = item.value.asnValue.string.stream[1];
  1394. pTmp[2] = item.value.asnValue.string.stream[2];
  1395. pTmp[3] = item.value.asnValue.string.stream[3];
  1396. break;
  1397. case ID_TCPCONN_REMOTEPORT:
  1398. pTcp->Info.tct_remoteport = item.value.asnValue.number;
  1399. break;
  1400. }
  1401. }
  1402. void SaveData_TCP6CONN( GenericTable *pEntry,
  1403. RFC1157VarBind item,
  1404. OIDdef *pOid )
  1405. {
  1406. Tcp6ConnEntry *pTcp = (Tcp6ConnEntry *)pEntry;
  1407. uchar *pTmp;
  1408. int len, i, curr = 10;
  1409. switch ( item.name.ids[pOid->EntElemOffset] )
  1410. {
  1411. case ID_TCPNEWCONN_STATE:
  1412. // skip local address type
  1413. curr++;
  1414. len = item.name.ids[curr++];
  1415. for ( i = 0; i < sizeof(IN6_ADDR); i++ )
  1416. {
  1417. pTcp->Info.tct_localaddr.s6_bytes[i] = (BYTE)item.name.ids[curr++];
  1418. }
  1419. if ( len > sizeof(IN6_ADDR) )
  1420. {
  1421. pTmp = (uchar*)&pTcp->Info.tct_localscopeid;
  1422. for ( i = 0; i < sizeof(ULONG); i++ )
  1423. {
  1424. pTmp[i] = (BYTE)item.name.ids[curr++];
  1425. }
  1426. pTcp->Info.tct_localscopeid = ntohl(pTcp->Info.tct_localscopeid);
  1427. }
  1428. pTcp->Info.tct_localport = item.name.ids[curr++];
  1429. // skip remote address type
  1430. curr++;
  1431. len = item.name.ids[curr++];
  1432. for ( i = 0; i < sizeof(IN6_ADDR); i++ )
  1433. {
  1434. pTcp->Info.tct_remoteaddr.s6_bytes[i] = (BYTE)item.name.ids[curr++];
  1435. }
  1436. if ( len > sizeof(IN6_ADDR) ) {
  1437. pTmp = (uchar*)&pTcp->Info.tct_remotescopeid;
  1438. for ( i = 0; i < sizeof(ULONG); i++ )
  1439. {
  1440. pTmp[i] = (BYTE)item.name.ids[curr++];
  1441. }
  1442. pTcp->Info.tct_remotescopeid = ntohl(pTcp->Info.tct_remotescopeid);
  1443. }
  1444. pTcp->Info.tct_remoteport = item.name.ids[curr++];
  1445. pTcp->Info.tct_state = item.value.asnValue.number;
  1446. break;
  1447. }
  1448. }
  1449. //*****************************************************************************
  1450. //
  1451. // Name: SaveData_UDP
  1452. //
  1453. // Description: Saves an element of the data in the UDP table.
  1454. //
  1455. // Parameters: GenericTable *pEntry; pointer to table entry.
  1456. // RFC1157VarBind item: contains value returned from mib.
  1457. // OIDdef *pOid: contains table-specific data.
  1458. //
  1459. // Returns: void.
  1460. //
  1461. // History:
  1462. // 01/12/94 JayPh Created.
  1463. //
  1464. //*****************************************************************************
  1465. void SaveData_UDP( GenericTable *pEntry,
  1466. RFC1157VarBind item,
  1467. OIDdef *pOid )
  1468. {
  1469. UdpEntry *pUdp = (UdpEntry *)pEntry;
  1470. uchar *pTmp;
  1471. switch ( item.name.ids[pOid->EntElemOffset] )
  1472. {
  1473. case ID_UDP_INDATAGRAMS:
  1474. pUdp->Info.us_indatagrams = item.value.asnValue.number;
  1475. break;
  1476. case ID_UDP_NOPORTS:
  1477. pUdp->Info.us_noports = item.value.asnValue.number;
  1478. break;
  1479. case ID_UDP_INERRORS:
  1480. pUdp->Info.us_inerrors = item.value.asnValue.number;
  1481. break;
  1482. case ID_UDP_OUTDATAGRAMS:
  1483. pUdp->Info.us_outdatagrams = item.value.asnValue.number;
  1484. break;
  1485. }
  1486. }
  1487. //*****************************************************************************
  1488. //
  1489. // Name: SaveData_UDPCONN
  1490. //
  1491. // Description: Saves an element of the data in the UDP connection table.
  1492. //
  1493. // Parameters: GenericTable *pEntry; pointer to table entry.
  1494. // RFC1157VarBind item: contains value returned from mib.
  1495. // OIDdef *pOid: contains table-specific data.
  1496. //
  1497. // Returns: void.
  1498. //
  1499. // History:
  1500. // 01/12/94 JayPh Created.
  1501. //
  1502. //*****************************************************************************
  1503. void SaveData_UDPCONN( GenericTable *pEntry,
  1504. RFC1157VarBind item,
  1505. OIDdef *pOid )
  1506. {
  1507. UdpConnEntry *pUdp = (UdpConnEntry *)pEntry;
  1508. uchar *pTmp;
  1509. switch ( item.name.ids[pOid->EntElemOffset] )
  1510. {
  1511. case ID_UDPCONN_LOCALADDR:
  1512. pTmp = (uchar *)&(pUdp->Info.ue_localaddr);
  1513. pTmp[0] = item.value.asnValue.string.stream[0];
  1514. pTmp[1] = item.value.asnValue.string.stream[1];
  1515. pTmp[2] = item.value.asnValue.string.stream[2];
  1516. pTmp[3] = item.value.asnValue.string.stream[3];
  1517. break;
  1518. case ID_UDPCONN_LOCALPORT:
  1519. pUdp->Info.ue_localport = item.value.asnValue.number;
  1520. break;
  1521. }
  1522. }
  1523. void SaveData_UDP6LISTENER( GenericTable *pEntry,
  1524. RFC1157VarBind item,
  1525. OIDdef *pOid )
  1526. {
  1527. Udp6ListenerEntry *pUdp = (Udp6ListenerEntry *)pEntry;
  1528. uchar *pTmp;
  1529. int len, i, curr = 10;
  1530. switch ( item.name.ids[pOid->EntElemOffset] )
  1531. {
  1532. case ID_UDPLISTENER_LOCALPORT:
  1533. // skip local address type
  1534. curr++;
  1535. len = item.name.ids[curr++];
  1536. for ( i = 0; i < sizeof(IN6_ADDR); i++ )
  1537. {
  1538. pUdp->Info.ule_localaddr.s6_bytes[i] = (BYTE)item.name.ids[curr++];
  1539. }
  1540. if ( len > sizeof(IN6_ADDR) ) {
  1541. pTmp = (uchar*)&pUdp->Info.ule_localscopeid;
  1542. for ( i = 0; i < sizeof(ULONG); i++ )
  1543. {
  1544. pTmp[i] = (BYTE)item.name.ids[curr++];
  1545. }
  1546. pUdp->Info.ule_localscopeid = ntohl(pUdp->Info.ule_localscopeid);
  1547. }
  1548. pUdp->Info.ule_localport = item.value.asnValue.number;
  1549. break;
  1550. }
  1551. }