📄 m2riplib.c
字号:
* the subnet of the IP address contained in the M2_RIP2_IFCONF_ENTRY structure* passed to it. <pRipIfConf> is a pointer to an M2_RIP2_IFCONF_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 <pRipIfConf> was invalid or the interface was* not found.** ERRNO:* S_m2Lib_INVALID_PARAMETER* S_m2Lib_ENTRY_NOT_FOUND** SEE ALSO:* m2RipInit()*/STATUS m2RipIfConfEntryGet ( int search, M2_RIP2_IFCONF_ENTRY* pRipIfConf ) { struct interface* pIfp; struct sockaddr_in address; struct interface* pIfpSaved = NULL; unsigned long ipAddrSaved = -1; unsigned long currIpAddr; address.sin_addr.s_addr = pRipIfConf->rip2IfConfAddress; 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->ifConf, (char *)pRipIfConf, sizeof(M2_RIP2_IFCONF_ENTRY)); semGive (ripLockSem); return (OK); }#if 0void m2RipIfConfTest ( char* pIpAddr ) { M2_RIP2_IFCONF_ENTRY ripIfConf; ripIfConf.rip2IfConfAddress = inet_addr(pIpAddr); if (m2RipIfConfEntryGet(M2_EXACT_VALUE, &ripIfConf) != OK) return; printf("IP Address: %s\nAuthType: %ld\nAuthKey: %s\nSend: %ld\n", inet_ntoa(ripIfConf.rip2IfConfAddress), ripIfConf.rip2IfConfAuthType, ripIfConf.rip2IfConfAuthKey, ripIfConf.rip2IfConfSend); printf("Receive: %ld\nDefault Metric: %ld\nStatus: %ld\n", ripIfConf.rip2IfConfReceive, ripIfConf.rip2IfConfDefaultMetric, ripIfConf.rip2IfConfStatus); }#endif/******************************************************************************** m2RipIfConfEntrySet - set MIB-II RIP-group interface entry** This routine sets the interface configuration for the interface serving* the subnet of the IP address contained in the M2_RIP2_IFCONF_ENTRY structure.** <pRipIfConf> is a pointer to an M2_RIP2_IFCONF_ENTRY structure which the* routine places into the system based on the <varToSet> value. ** RETURNS: OK, or ERROR if <pRipIfConf> is invalid or the interface cannot* be found.** ERRNO:* S_m2Lib_INVALID_PARAMETER* S_m2Lib_ENTRY_NOT_FOUND** SEE ALSO:* m2RipInit()*/STATUS m2RipIfConfEntrySet ( unsigned int varToSet, M2_RIP2_IFCONF_ENTRY* pRipIfConf ) { struct interface* pIfp; struct sockaddr_in address;#ifndef VIRTUAL_STACK IMPORT RIP ripState;#endif BOOL changeFlag = FALSE; /* Changing receive control switch? */ address.sin_addr.s_addr = pRipIfConf->rip2IfConfAddress; address.sin_family = AF_INET; semTake (ripLockSem, WAIT_FOREVER); pIfp = ripIfLookup((struct sockaddr *)&address); if (pIfp == NULL) { semGive (ripLockSem); errnoSet(S_m2Lib_ENTRY_NOT_FOUND); return (ERROR); } if (varToSet & M2_RIP2_IF_CONF_DOMAIN) { bcopy(pRipIfConf->rip2IfConfDomain, pIfp->ifConf.rip2IfConfDomain, 2); } if (varToSet & M2_RIP2_IF_CONF_AUTH_TYPE) { pIfp->ifConf.rip2IfConfAuthType = pRipIfConf->rip2IfConfAuthType; } if (varToSet & M2_RIP2_IF_CONF_AUTH_KEY) { bzero (pIfp->ifConf.rip2IfConfAuthKey, AUTHKEYLEN); strncpy(pIfp->ifConf.rip2IfConfAuthKey, pRipIfConf->rip2IfConfAuthKey, AUTHKEYLEN); } if (varToSet & M2_RIP2_IF_CONF_SEND) { pIfp->ifConf.rip2IfConfSend = pRipIfConf->rip2IfConfSend; } if (varToSet & M2_RIP2_IF_CONF_RECEIVE) { if (pIfp->ifConf.rip2IfConfReceive != pRipIfConf->rip2IfConfReceive) changeFlag = TRUE; if (changeFlag) { struct ip_mreq ipMreq; UINT32 addr; addr = ((struct sockaddr_in *) &(pIfp->int_addr))->sin_addr.s_addr; ipMreq.imr_multiaddr.s_addr = htonl (RIP_MCAST_ADDR); ipMreq.imr_interface.s_addr = addr; /* * If switching from rip1OrRip2 or rip2 to rip1 or doNotReceive, * delete the multicast membership since multicast is not supported * in rip1. */ if (((pIfp->ifConf.rip2IfConfReceive == M2_rip2IfConfReceive_rip2) || (pIfp->ifConf.rip2IfConfReceive == M2_rip2IfConfReceive_rip1OrRip2)) && ((pRipIfConf->rip2IfConfReceive == M2_rip2IfConfReceive_rip1) || (pRipIfConf->rip2IfConfReceive == M2_rip2IfConfReceive_doNotReceive))) { if ((addr == 0) || (ripState.s < 0) || (setsockopt (ripState.s, IPPROTO_IP, IP_DROP_MEMBERSHIP, (char *)&ipMreq, sizeof (ipMreq)) < 0)) if (routedDebug) logMsg ("setsockopt IP_DROP_MEMBERSHIP error.\n", 0, 0, 0, 0, 0, 0); } /* * If switching from rip1 or doNotReceive to rip1OrRip2 or rip2, * add the multicast membership. */ if (((pIfp->ifConf.rip2IfConfReceive == M2_rip2IfConfReceive_rip1) || (pIfp->ifConf.rip2IfConfReceive == M2_rip2IfConfReceive_doNotReceive)) && ((pRipIfConf->rip2IfConfReceive == M2_rip2IfConfReceive_rip2) || (pRipIfConf->rip2IfConfReceive == M2_rip2IfConfReceive_rip1OrRip2))) { if ((addr == 0) || (ripState.s < 0) || (setsockopt (ripState.s, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&ipMreq, sizeof (ipMreq)) < 0)) if (routedDebug) logMsg ("setsockopt IP_ADD_MEMBERSHIP error.\n", 0, 0, 0, 0, 0, 0); } pIfp->ifConf.rip2IfConfReceive = pRipIfConf->rip2IfConfReceive; } } if (varToSet & M2_RIP2_IF_CONF_DEFAULT_METRIC) { pIfp->ifConf.rip2IfConfDefaultMetric = pRipIfConf->rip2IfConfDefaultMetric; } if (varToSet & M2_RIP2_IF_CONF_STATUS) { pIfp->ifConf.rip2IfConfStatus = pRipIfConf->rip2IfConfStatus; } semGive (ripLockSem); return (OK); }#if 0 void m2RipIfConfSetTest ( char* pIpAddr, long authType, /* Authentication type */ char authKey[15], /* Key */ long send, /* What version to send */ long receive, /* What version to listen to */ long defaultMetric, /* Default metric for default route */ long status /* Putting M2_rip2IfConfStatus_invalid */ /* here turns the interface off */ ) { M2_RIP2_IFCONF_ENTRY ripIfConf; ripIfConf.rip2IfConfAddress = inet_addr(pIpAddr); ripIfConf.rip2IfConfAuthType = authType; bzero(ripIfConf.rip2IfConfAuthKey, 16); strcpy(ripIfConf.rip2IfConfAuthKey, authKey); ripIfConf.rip2IfConfSend = send; ripIfConf.rip2IfConfReceive = receive; ripIfConf.rip2IfConfDefaultMetric = defaultMetric; ripIfConf.rip2IfConfStatus = status; if (m2RipIfConfEntrySet(0xff, &ripIfConf) != OK) return; if (m2RipIfConfEntryGet(M2_EXACT_VALUE, &ripIfConf) != OK) return; printf("IP Address: %s\nAuthType: %ld\nAuthKey: %s\nSend: %ld\n", inet_ntoa(ripIfConf.rip2IfConfAddress), ripIfConf.rip2IfConfAuthType, ripIfConf.rip2IfConfAuthKey, ripIfConf.rip2IfConfSend); printf ("Receive: %ld\nDefault Metric: %ld\nStatus: %ld\n", ripIfConf.rip2IfConfReceive, ripIfConf.rip2IfConfDefaultMetric, ripIfConf.rip2IfConfStatus); }#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -