📄 m2riplib.c
字号:
/* m2RipLib.c - VxWorks interface routines to RIP for SNMP Agent *//* Copyright 1984 - 2003 Wind River Systems, Inc. *//*modification history--------------------01o,14jan03,rae Merged from velocecp branch (SPR #83265)01n,15oct01,rae merge from truestack ver 01o, base 01m (VIRTUAL_STACK)01m,30jun98,spm corrected authentication to allow change to shorter key01l,26jun98,spm changed RIP_MCAST_ADDR constant from string to value; altered multicast group handling to comply with ANVL RIP tests01k,25oct97,kbw making minor man page fixes01j,06oct97,gnn cleaned up issues with IMPORT of ripState01i,15may97,gnn cleaned up some warnings; #ifdef'd out some test code01h,08may97,gnn fixed the authentication string code.01g,30apr97,kbw fiddled man page text01f,28apr97,gnn fixed some of the documentation01e,24apr97,gnn fixed an errno value01d,20apr97,kbw fixed man page format, spell check01c,17apr97,gnn modified interfaces and variable to follow standards.01b,14apr97,gnn added documentation for MIB-II stuff.01a,01apr97,gnn written.*/ /*DESCRIPTIONThis library provides routines to initialize the group, access thegroup global variables, read the table of network interfaces that RIPknows about, and change the state of such an interface. For a broaderdescription of MIB-II services, see the manual entry for m2Lib.USING THIS LIBRARYThis library can be initialized and deleted by calling m2RipInit() andm2RipDelete() respectively, if only the RIP group's services are needed.If full MIB-II support is used, this group and all other groups can beinitialized and deleted by calling m2Init() and m2Delete().The group global variables are accessed by callingm2RipGlobalCountersGet() as follows:.CS M2_RIP2_GLOBAL_GROUP ripGlobal; if (m2RipGlobalCountersGet (&ripGlobal) == OK) /@ values in ripGlobal are valid @/.CETo retrieve the RIP group statistics for a particular interface you call them2RipIfStatEntryGet() routine a pointer to an M2_RIP2_IFSTAT_ENTRY structure that contains the address of the interface you are searching for. For example:.CS M2_RIP2_IFSTAT_ENTRY ripIfStat; ripIfStat.rip2IfStatAddress = inet_addr("90.0.0.3"); if (m2RipIfStatEntryGet(M2_EXACT_VALUE, &ripIfStat) == OK) /@ values in ripIfState are valid @/.CETo retrieve the configuration statistics for a particular interface them2RipIfConfEntryGet() routine must be called with an IP address encoded in anM2_RIP2_IFSTAT_ENTRY structure which is passed as the second argument. Forexample:.CS M2_RIP2_IFCONF_ENTRY ripIfConf; ripIfConf.rip2IfConfAddress = inet_addr("90.0.0.3"); if (m2RipIfConfEntryGet(M2_EXACT_VALUE, &ripIfConf) == OK) /@ values in ripIfConf are valid @/.CETo set the values of for an interface the m2RipIfConfEntrySet() routine mustbe called with an IP address in dot notation encoded into anM2_RIP2_IFSTAT_ENTRY structure, which is passed as the second argument. Forexample:.CS M2_RIP2_IFCONF_ENTRY ripIfConf; ripIfConf.rip2IfConfAddress = inet_addr("90.0.0.3"); /@ Set the authorization type. @/ ripIfConf.rip2IfConfAuthType = M2_rip2IfConfAuthType_simplePassword; bzero(ripIfConf.rip2IfConfAuthKey, 16); bcopy("Simple Password ", ripIfConf.rip2IfConfAuthKey, 16); /@ We only accept version 1 packets. @/ ripIfConf.rip2IfConfSend = M2_rip2IfConfSend_ripVersion1; /@ We only send version 1 packets. @/ ripIfConf.rip2IfConfReceive = M2_rip2IfConfReceive_rip1; /@ Default routes have a metric of 2 @/ ripIfConf.rip2IfConfDefaultMetric = 2; /@ If the interface is invalid it is turned off, we make it valid. @/ ripIfConf.rip2IfConfStatus = M2_rip2IfConfStatus_valid; if (m2RipIfConfEntrySet(varsToSet, &ripIfConf) == OK) /@ Call succeded. @/.CEINCLUDE FILES: rip/m2RipLib.h rip/defs.hSEE ALSO:ripLib*//* includes */#include "vxWorks.h"#include "rip/m2RipLib.h"#include "rip/defs.h"#include "m2Lib.h"#include "errnoLib.h"#include "errno.h"#include "inetLib.h"#include "sockLib.h"#include "logLib.h"#ifdef VIRTUAL_STACK#include "netinet/vsLib.h"#include "netinet/vsRip.h"#endif/* defines */#define same(a1, a2) \ (memcmp((a1)->sa_data, (a2)->sa_data, 14) == 0)/* typedefs *//* globals */#ifndef VIRTUAL_STACKextern struct interface *ripIfNet;extern int routedDebug;#endif/* locals *//* forward declarations *//******************************************************************************** m2RipInit - initialize the RIP MIB support** This routine sets up the RIP MIB and should be called before any * other m2RipLib routine.** RETURNS: OK, always.**/STATUS m2RipInit (void) { return (OK); }/******************************************************************************** m2RipDelete - delete the RIP MIB support** This routine should be called after all m2RipLib calls are completed.** RETURNS: OK, always. **/STATUS m2RipDelete (void) { return (OK); }/******************************************************************************** m2RipGlobalCountersGet - get MIB-II RIP-group global counters** This routine fills in an M2_RIP2_GLOBAL_GROUP structure pointed to * by <pRipGlobal> with the values of the MIB-II RIP-group global counters.** RETURNS: OK or ERROR. ** ERRNO:* S_m2Lib_INVALID_PARAMETER** SEE ALSO:* m2RipInit()*/STATUS m2RipGlobalCountersGet ( M2_RIP2_GLOBAL_GROUP* pRipGlobal ) {#ifndef VIRTUAL_STACK extern RIP ripState;#endif if (pRipGlobal == NULL) { errnoSet(S_m2Lib_INVALID_PARAMETER); return (ERROR); } bcopy((char *)&ripState.ripGlobal, (char *)pRipGlobal, sizeof(M2_RIP2_GLOBAL_GROUP)); return (OK); }/******************************************************************************** m2RipIfStatEntryGet - get MIB-II RIP-group interface entry** This routine retrieves the interface statistics for the interface serving* the subnet of the IP address contained in the M2_RIP2_IFSTAT_ENTRY* structure. <pRipIfStat> is a pointer to an M2_RIP2_IFSTAT_ENTRY structure* which the routine will fill in upon successful completion.** This routine either returns an exact match if <search> is M2_EXACT_VALUE,* or the next value greater than or equal to the value supplied if the* <search> is M2_NEXT_VALUE.** RETURNS: OK, or ERROR if either <pRipIfStat> is invalid or an exact match* failed.** ERRNO:* S_m2Lib_INVALID_PARAMETER* S_m2Lib_ENTRY_NOT_FOUND* * SEE ALSO:* m2RipInit()*/STATUS m2RipIfStatEntryGet ( int search, M2_RIP2_IFSTAT_ENTRY* pRipIfStat ) { struct interface* pIfp; struct interface* pIfpSaved = NULL; struct sockaddr_in address; unsigned long ipAddrSaved = -1; unsigned long currIpAddr; address.sin_addr.s_addr = pRipIfStat->rip2IfStatAddress; address.sin_family = AF_INET; semTake (ripLockSem, WAIT_FOREVER); if (search == M2_EXACT_VALUE) { pIfpSaved = ripIfLookup((struct sockaddr *)&address); if (pIfpSaved == NULL) { semGive (ripLockSem); errnoSet(S_m2Lib_ENTRY_NOT_FOUND); return (ERROR); } } else { for (pIfp = ripIfNet; pIfp; pIfp = pIfp->int_next) { currIpAddr = ntohl(((struct sockaddr_in *)&pIfp->int_addr)->sin_addr.s_addr); if ((currIpAddr >= ntohl(address.sin_addr.s_addr)) && (currIpAddr < ipAddrSaved)) { pIfpSaved = pIfp; ipAddrSaved = currIpAddr; } } if (pIfpSaved == NULL) { semGive (ripLockSem); errnoSet(S_m2Lib_ENTRY_NOT_FOUND); return (ERROR); } } bcopy((char *)&pIfpSaved->ifStat, (char *)pRipIfStat, sizeof(M2_RIP2_IFSTAT_ENTRY)); semGive (ripLockSem); return (OK); }/******************************************************************************** m2RipIfConfEntryGet - get MIB-II RIP-group interface entry** This routine retrieves the interface configuration for the interface serving
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -