Leaked source code of windows server 2003
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.

1646 lines
46 KiB

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