本文整理汇总了C++中IN_CLASSB函数的典型用法代码示例。如果您正苦于以下问题:C++ IN_CLASSB函数的具体用法?C++ IN_CLASSB怎么用?C++ IN_CLASSB使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IN_CLASSB函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get_netmask4
/*
* Given a host-order address, calculate client's default net mask.
* Consult netmasks database to see if net is further subnetted.
* We'll only snag the first netmask that matches our criteria.
* We return the resultant netmask in host order.
*/
void
get_netmask4(const struct in_addr *n_addrp, struct in_addr *s_addrp)
{
struct in_addr hp, tp;
/*
* First check if VLSM is in use.
*/
hp.s_addr = htonl(n_addrp->s_addr);
if (getnetmaskbyaddr(hp, &tp) == 0) {
s_addrp->s_addr = ntohl(tp.s_addr);
return;
}
/*
* Fall back on standard classed networks.
*/
if (IN_CLASSA(n_addrp->s_addr))
s_addrp->s_addr = IN_CLASSA_NET;
else if (IN_CLASSB(n_addrp->s_addr))
s_addrp->s_addr = IN_CLASSB_NET;
else if (IN_CLASSC(n_addrp->s_addr))
s_addrp->s_addr = IN_CLASSC_NET;
else
s_addrp->s_addr = IN_CLASSE_NET;
}
示例2: route_netmask
/* This calculates the netmask that we should use for static routes.
* This IS different from the calculation used to calculate the netmask
* for an interface address. */
static uint32_t
route_netmask(uint32_t ip_in)
{
/* used to be unsigned long - check if error */
uint32_t p = ntohl(ip_in);
uint32_t t;
if (IN_CLASSA(p))
t = ~IN_CLASSA_NET;
else {
if (IN_CLASSB(p))
t = ~IN_CLASSB_NET;
else {
if (IN_CLASSC(p))
t = ~IN_CLASSC_NET;
else
t = 0;
}
}
while (t & p)
t >>= 1;
return (htonl(~t));
}
示例3: apply_classful_mask_ipv4
/* Utility function to convert ipv4 prefixes to Classful prefixes */
void apply_classful_mask_ipv4 (struct prefix_ipv4 *p)
{
u_int32_t destination;
destination = ntohl (p->prefix.s_addr);
if (p->prefixlen == IPV4_MAX_PREFIXLEN);
/* do nothing for host routes */
else if (IN_CLASSC (destination))
{
p->prefixlen=24;
apply_mask_ipv4(p);
}
else if (IN_CLASSB(destination))
{
p->prefixlen=16;
apply_mask_ipv4(p);
}
else
{
p->prefixlen=8;
apply_mask_ipv4(p);
}
}
示例4: in_netof
unsigned long in_netof(struct in_addr in)
{
unsigned long i, net;
struct in_ifaddr *ia;
/* Setup locals */
i = ntohl(in.s_addr);
/* Get network number */
if ( IN_CLASSA(i) )
net = i & IN_CLASSA_NET;
else if ( IN_CLASSB(i) )
net = i & IN_CLASSB_NET;
else if ( IN_CLASSC(i) )
net = i & IN_CLASSC_NET;
else if ( IN_CLASSD(i) )
net = i & IN_CLASSD_NET;
else
return 0;
/* Check if subnet */
for (ia = in_ifaddr; ia != NULL; ia = ia->ia_next)
if (net == ia->ia_net)
return (i & ia->ia_subnetmask);
return net;
}
示例5: GetMask
/*
* Return user specified netmask, modified by any mask we might determine
* for address `addr' (in network byte order).
* Here we scan through the system's list of interfaces, looking for
* any non-point-to-point interfaces which might appear to be on the same
* network as `addr'. If we find any, we OR in their netmask to the
* user-specified netmask.
*/
uint32_t
GetMask(
uint32_t addr)
{
uint32_t mask, nmask, ina;
struct ifreq *ifr, *ifend, ifreq;
struct ifconf ifc;
struct ifreq ifs[MAX_IFS];
addr = ntohl(addr);
if (IN_CLASSA(addr)) /* determine network mask for address class */
nmask = IN_CLASSA_NET;
else if (IN_CLASSB(addr))
nmask = IN_CLASSB_NET;
else
nmask = IN_CLASSC_NET;
/* class D nets are disallowed by bad_ip_adrs */
mask = netmask | htonl(nmask);
/*
* Scan through the system's network interfaces.
*/
ifc.ifc_len = sizeof(ifs);
ifc.ifc_req = ifs;
if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {
warn("ioctl(SIOCGIFCONF): %m");
return mask;
}
ifend = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
for (ifr = ifc.ifc_req; ifr < ifend; ifr = (struct ifreq *)
((char *)&ifr->ifr_addr + ifr->ifr_addr.sa_len)) {
/*
* Check the interface's internet address.
*/
if (ifr->ifr_addr.sa_family != AF_INET)
continue;
ina = ((struct sockaddr_in *) &ifr->ifr_addr)->sin_addr.s_addr;
if ((ntohl(ina) & nmask) != (addr & nmask))
continue;
/*
* Check that the interface is up, and not point-to-point or loopback.
*/
strlcpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name));
if (ioctl(sockfd, SIOCGIFFLAGS, &ifreq) < 0)
continue;
if ((ifreq.ifr_flags & (IFF_UP|IFF_POINTOPOINT|IFF_LOOPBACK))
!= IFF_UP)
continue;
/*
* Get its netmask and OR it into our mask.
*/
if (ioctl(sockfd, SIOCGIFNETMASK, &ifreq) < 0)
continue;
mask |= ((struct sockaddr_in *)&ifreq.ifr_addr)->sin_addr.s_addr;
}
return mask;
}
示例6: GetClass
/// This function uses Windows Sockets macros to get standard class information. It
/// does not know about subnetting or any classes beyond class C.
TINetSocketAddress::TINetClass TINetSocketAddress::GetClass() const
{
if (IN_CLASSA(GetNetworkAddress()))
return ClassA;
if (IN_CLASSB(GetNetworkAddress()))
return ClassB;
if (IN_CLASSC(GetNetworkAddress()))
return ClassC;
return ClassUnknown;
}
示例7: inet_lnaof
/*
* Return the local network address portion of an
* internet address; handles class a/b/c network
* number formats.
*/
in_addr_t inet_lnaof(struct in_addr in)
{
in_addr_t i = ntohl(in.s_addr);
if (IN_CLASSA(i))
return (i & IN_CLASSA_HOST);
else if (IN_CLASSB(i))
return (i & IN_CLASSB_HOST);
else
return (i & IN_CLASSC_HOST);
}
示例8: config_ip_prefix
static int config_ip_prefix(struct in_addr *addr)
{
if (IN_CLASSA(addr->s_addr))
return 32 - IN_CLASSA_NSHIFT;
if (IN_CLASSB(addr->s_addr))
return 32 - IN_CLASSB_NSHIFT;
if (IN_CLASSC(addr->s_addr))
return 32 - IN_CLASSC_NSHIFT;
return 0;
}
示例9: printk
//---------------------------------------------------------------------------
// Search the entity with the IPv4 address 'addr'
struct cx_entity *nasmt_CLASS_cx4(struct sk_buff *skb, unsigned char dscp, int *paddr_type, unsigned char *cx_index) {
//---------------------------------------------------------------------------
unsigned char cxi;
uint32_t daddr;
struct cx_entity *cx=NULL;
struct classifier_entity *pclassifier=NULL;
struct in_addr masked_addr;
#ifdef NAS_DEBUG_CLASS
printk("nasmt_CLASS_cx4: begin\n");
#endif
if (skb!=NULL) {
daddr = ((struct iphdr*)(skb_network_header(skb)))->daddr;
if (daddr != INADDR_ANY) {
#ifdef NAS_DEBUG_CLASS
printk("nasmt_CLASS_cx4: SOURCE ADDR %d.%d.%d.%d",NIPADDR(ip_hdr(skb)->saddr));
printk(" DEST ADDR %d.%d.%d.%d\n",NIPADDR(ip_hdr(skb)->daddr));
#endif
if (ipv4_is_multicast(ip_hdr(skb)->daddr)) {
// TO BE CHECKED
*paddr_type = NAS_IPV4_ADDR_MC_SIGNALLING;
} else {
if (ipv4_is_lbcast(ip_hdr(skb)->daddr)) {
// TO BE CHECKED
*paddr_type = NAS_IPV4_ADDR_BROADCAST;
} else {
if (IN_CLASSA(ip_hdr(skb)->daddr) || IN_CLASSB(ip_hdr(skb)->daddr) || IN_CLASSC(ip_hdr(skb)->daddr)) {
*paddr_type = NAS_IPV4_ADDR_UNICAST;
cxi = 0;
(*cx_index)++;
pclassifier = gpriv->cx[cxi].sclassifier[dscp];
while (pclassifier!=NULL) {
// verify that this is an IPv4 classifier
if ((pclassifier->version == NAS_VERSION_4) || (pclassifier->version == NAS_VERSION_DEFAULT)) {
nasmt_create_mask_ipv4_addr(&masked_addr, pclassifier->dplen);
if (IN_ARE_ADDR_MASKED_EQUAL(&ip_hdr(skb)->daddr, &(pclassifier->daddr.ipv4), &masked_addr)) {
#ifdef NAS_DEBUG_CLASS
printk("nasmt_CLASS_cx4: IP MASK MATCHED: found cx %d: %d.%d.%d.%d/%d\n",cxi, NIPADDR(pclassifier->daddr.ipv4), pclassifier->dplen);
#endif
return &gpriv->cx[cxi];
}
}
// goto to next classification rule for the connection
pclassifier = pclassifier->next;
}
} else {
*paddr_type = NAS_IPV4_ADDR_UNKNOWN;
}
}
}
}
}
return cx;
}
示例10: net_mask
/* XXX - should really support CIDR which means explicit masks always. */
static u_int32_t
net_mask(struct in_addr in) /*!< XXX - should really use system's version of this */
{
u_int32_t i = ntohl(in.s_addr);
if (IN_CLASSA(i))
return (htonl(IN_CLASSA_NET));
else if (IN_CLASSB(i))
return (htonl(IN_CLASSB_NET));
return (htonl(IN_CLASSC_NET));
}
示例11: inet_class_netmask
static uint32_t inet_class_netmask(uint32_t ip)
{
ip = ntohl(ip);
if (IN_CLASSA(ip))
return htonl(IN_CLASSA_NET);
if (IN_CLASSB(ip))
return htonl(IN_CLASSB_NET);
if (IN_CLASSC(ip))
return htonl(IN_CLASSC_NET);
return INADDR_ANY;
}
示例12: inet_lnaof
/*
* Return the local network address portion of an
* internet address; handles class a/b/c network
* number formats.
*/
int
inet_lnaof(struct in_addr in)
{
u_long i = ntohl(in.s_addr);
if (IN_CLASSA(i))
return ((i)&IN_CLASSA_HOST);
else if (IN_CLASSB(i))
return ((i)&IN_CLASSB_HOST);
else
return ((i)&IN_CLASSC_HOST);
}
示例13: ipaddrtonetmask
/*
* Get the netmask of an IP address. This routine is used if
* SIOCGIFNETMASK doesn't work.
*/
u_int32_t
ipaddrtonetmask(u_int32_t addr)
{
if (IN_CLASSA(addr))
return IN_CLASSA_NET;
if (IN_CLASSB(addr))
return IN_CLASSB_NET;
if (IN_CLASSC(addr))
return IN_CLASSC_NET;
error(FATAL, "unknown IP address class: %08X", addr);
/* NOTREACHED */
}
示例14: forgemask
static uint32_t
forgemask(uint32_t a)
{
uint32_t m;
if (IN_CLASSA(a))
m = IN_CLASSA_NET;
else if (IN_CLASSB(a))
m = IN_CLASSB_NET;
else
m = IN_CLASSC_NET;
return (m);
}
示例15: inet_lnaof
unsigned long
inet_lnaof(struct in_addr in)
{
unsigned long addr = ntohl(in.s_addr);
if (IN_CLASSA(addr))
addr &= IN_CLASSA_HOST;
else if (IN_CLASSB(addr))
addr &= IN_CLASSB_HOST;
else
addr &= IN_CLASSC_HOST;
return(htonl(addr));
}