?? ipripng_util.c
字號:
/* * Copyright 2006 Wind River Systems, Inc. * * The right to copy, distribute, modify or otherwise make use * of this software may be licensed only pursuant to the terms * of an applicable Wind River license agreement. *//*modification history--------------------01i,05nov08,rme Used 'ipripng_sflag' in 'tobeadv' (WIND00141137)01c,27apr07,tlu Remove double variable usage, changed to long01b,24jan07,kch Remove VxWorks header file, convert VxWorks typedefs and functions to IPCOM equivalent01a,12jun06,tlu Initial creation*//* **************************************************************************** * 1 DESCRIPTION **************************************************************************** *//* **************************************************************************** * 2 CONFIGURATION **************************************************************************** */#include "ipripng_config.h"/****************************************************************************** 3 INCLUDE FILES*****************************************************************************/#define IPCOM_USE_CLIB_PROTO#include <ipcom_type.h>#include <ipcom_cstyle.h>#include <ipcom_clib.h>#include <ipcom_err.h>#include <ipcom_os.h>#include <ipcom_sock.h>#include <ipcom_sock2.h>#include <ipcom_inet.h>#include <ipcom_syslog.h>#include <ipcom_sysctl.h>#include <ipcom_shell.h>#include <ipnet_config.h>#include <ipnet.h>#include <ipnet_routesock.h>#include <ipnet_cmd.h>#include "ipripng.h"#include "ipripng_constant.h"/* **************************************************************************** * 4 DEFINES **************************************************************************** *//* Syslog priority and facility. */#define IPCOM_SYSLOG_PRIORITY IPCOM_LOG_DEBUG#define IPCOM_SYSLOG_FACILITY IPCOM_LOG_IPRIP/* **************************************************************************** * 5 TYPES **************************************************************************** *//* **************************************************************************** * 6 EXTERN PROTOTYPES **************************************************************************** *//* **************************************************************************** * 7 LOCAL PROTOTYPES **************************************************************************** *//* **************************************************************************** * 8 DATA **************************************************************************** *//* **************************************************************************** * 9 STATIC FUNCTIONS **************************************************************************** *//* **************************************************************************** * 10 GLOBAL FUNCTIONS **************************************************************************** *//* *=========================================================================== * ipripng_allocopy *=========================================================================== * Description: * Parameters: * Returns: * */IP_GLOBAL char *ipripng_allocopy(char *p){ char *q = (char *)ipcom_malloc(strlen(p) + 1); ipcom_strcpy(q, p); return q;}IP_GLOBAL struct ifc *ifc_find(char *name){ struct ifc *ifcp; for (ifcp = ipripng_ifhead(); ifcp; ifcp = ifcp->ifc_next) { if (ipcom_strcmp(name, ifcp->ifc_name) == 0) return ifcp; } return (struct ifc *)IP_NULL;}IP_GLOBAL struct iff *iff_find(struct ifc *ifcp, int type){ struct iff *iffp; for (iffp = ifcp->ifc_filter; iffp; iffp = iffp->iff_next) { if (iffp->iff_type == type) return iffp; } return IP_NULL;}IP_GLOBAL voidifflags(int flags, char *ripng_if_buf){ ipcom_strcpy(ripng_if_buf, "");#define IFFLAG(s, f) \do { \if (flags & (f)) { \ if (ripng_if_buf[0]) \ ipcom_strcat(ripng_if_buf, ","); \ ipcom_strcat(ripng_if_buf, s); \ } \} while (0) IFFLAG("UP", IP_IFF_UP);#ifdef IP_IFF_INET_UP IFFLAG("INET_UP", IP_IFF_INET_UP);#endif#ifdef IP_IFF_INET6_UP IFFLAG("INET6_UP", IP_IFF_INET6_UP);#endif IFFLAG("BROADCAST", IP_IFF_BROADCAST); IFFLAG("DEBUG", IP_IFF_DEBUG); IFFLAG("LOOPBACK", IP_IFF_LOOPBACK); IFFLAG("POINTOPOINT", IP_IFF_POINTOPOINT);#ifdef IP_IFF_NOTRAILERS IFFLAG("NOTRAILERS", IP_IFF_NOTRAILERS);#endif#ifdef IP_IFF_SMART IFFLAG("SMART", IP_IFF_SMART);#endif IFFLAG("RUNNING", IP_IFF_RUNNING); IFFLAG("NOARP", IP_IFF_NOARP); IFFLAG("PROMISC", IP_IFF_PROMISC); IFFLAG("ALLMULTI", IP_IFF_ALLMULTI); IFFLAG("OACTIVE", IP_IFF_OACTIVE); IFFLAG("SIMPLEX", IP_IFF_SIMPLEX); IFFLAG("LINK0", IP_IFF_LINK0); IFFLAG("LINK1", IP_IFF_LINK1); IFFLAG("LINK2", IP_IFF_LINK2); IFFLAG("MULTICAST", IP_IFF_MULTICAST);#undef IFFLAG}IP_GLOBAL intmask2len(const struct in6_addr *addr, int lenlim){ int i = 0, j; const Ip_u8 *p = (Ip_u8 *)addr; for (j = 0; j < lenlim; j++, p++) { if (*p != 0xff) break; i += 8; } if (j < lenlim) { switch (*p) {#define MASKLEN(m, l) case m: do { i += l; break; } while (0) MASKLEN(0xfe, 7); break; MASKLEN(0xfc, 6); break; MASKLEN(0xf8, 5); break; MASKLEN(0xf0, 4); break; MASKLEN(0xe0, 3); break; MASKLEN(0xc0, 2); break; MASKLEN(0x80, 1); break;#undef MASKLEN } } return i;}/* * Returns a pointer to ifac whose address and prefix length matches * with the address and prefix length specified in the arguments. */IP_GLOBAL struct ifac *ifa_match(const struct ifc *ifcp, const struct in6_addr *ia, int plen){ struct ifac *ifa; for (ifa = ifcp->ifc_addr; ifa; ifa = ifa->ifa_next) { if (IP_IN6_ARE_ADDR_EQUAL(&ifa->ifa_addr, (struct in6_addr *)ia) && ifa->ifa_plen == plen) break; } return ifa;}IP_GLOBAL intgetifmtu(int ifindex){ int mib[6]; char *buf; Ip_size_t msize; struct Ipnet_if_msghdr *ifm; int mtu; mib[0] = IP_CTL_NET; mib[1] = IP_PF_ROUTE; mib[2] = 0; mib[3] = IP_AF_INET6; mib[4] = IP_NET_RT_IFLIST; mib[5] = ifindex; if (ipcom_sysctl(mib, 6, IP_NULL, &msize, IP_NULL, 0) < 0) { IPCOM_LOG0(ERR, "sysctl estimate NET_RT_IFLIST in getifmtu"); return (-1); } if ((buf = (char *)ipcom_malloc(msize)) == IP_NULL) { IPCOM_LOG0(ERR, "malloc failed in getifmtu"); return (-1); } if (ipcom_sysctl(mib, 6, buf, &msize, IP_NULL, 0) < 0) { IPCOM_LOG0(ERR, "sysctl NET_RT_IFLIST in getifmtu"); ipcom_free (buf); return (-1); } ifm = (struct Ipnet_if_msghdr *)buf; mtu = ifm->ifm_data.ifi_mtu; ipcom_free(buf); return mtu;}static const Ip_u8 plent[8] = { 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe};IP_GLOBAL voidapplyplen(struct in6_addr *ia, int plen){ Ip_u8 *p; int i;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -