当前位置: 首页>>代码示例>>C++>>正文


C++ IN6_IS_ADDR_MC_LINKLOCAL函数代码示例

本文整理汇总了C++中IN6_IS_ADDR_MC_LINKLOCAL函数的典型用法代码示例。如果您正苦于以下问题:C++ IN6_IS_ADDR_MC_LINKLOCAL函数的具体用法?C++ IN6_IS_ADDR_MC_LINKLOCAL怎么用?C++ IN6_IS_ADDR_MC_LINKLOCAL使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了IN6_IS_ADDR_MC_LINKLOCAL函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: setScopeFromAddress

/** Determines the IPv6 scope of a specified address.
 *
 * @param[in] v6Addr - The IPv6 address to be checked.
 *
 * @return The ipv6 scope of the address.
 *
 * @remarks The @p v6Addr parameter must be pointer to a 16-byte IPv6 
 *    address in binary form.
 * 
 * @internal
 */
static int setScopeFromAddress(const struct in6_addr * v6Addr)
{
   if (IN6_IS_ADDR_MULTICAST(v6Addr))
   {
      if (IN6_IS_ADDR_MC_GLOBAL(v6Addr))
         return SLP_SCOPE_GLOBAL;

      if (IN6_IS_ADDR_MC_ORGLOCAL(v6Addr))
         return SLP_SCOPE_ORG_LOCAL;

      if (IN6_IS_ADDR_MC_SITELOCAL(v6Addr))
         return SLP_SCOPE_SITE_LOCAL;

      if (IN6_IS_ADDR_MC_NODELOCAL(v6Addr))
         return SLP_SCOPE_NODE_LOCAL;

      if (IN6_IS_ADDR_MC_LINKLOCAL(v6Addr))
         return SLP_SCOPE_LINK_LOCAL;
   }
   if (IN6_IS_ADDR_SITELOCAL(v6Addr))
      return SLP_SCOPE_SITE_LOCAL;

   if (SLP_IN6_IS_ADDR_LOOPBACK(v6Addr))
      return SLP_SCOPE_NODE_LOCAL;

   if (IN6_IS_ADDR_LINKLOCAL(v6Addr))
      return SLP_SCOPE_LINK_LOCAL;

   return 0;
}
开发者ID:Distrotech,项目名称:openslp,代码行数:41,代码来源:slp_net.c

示例2: ifa_make_sockaddr

static void 
ifa_make_sockaddr(sa_family_t family, 
		  struct sockaddr *sa, 
		  void *p, size_t len,
		  uint32_t scope, uint32_t scopeid)
{
  if (sa == NULL) return;
  switch(family){
  case AF_INET:
    memcpy(&((struct sockaddr_in*)sa)->sin_addr, (char *)p, len);
    break;
  case AF_INET6:
    memcpy(&((struct sockaddr_in6*)sa)->sin6_addr, (char *)p, len);
    if (IN6_IS_ADDR_LINKLOCAL(p) ||
	IN6_IS_ADDR_MC_LINKLOCAL(p)){
      ((struct sockaddr_in6*)sa)->sin6_scope_id = scopeid;
    }
    break;
  case AF_PACKET:
    memcpy(((struct sockaddr_ll*)sa)->sll_addr, (char *)p, len);
    ((struct sockaddr_ll*)sa)->sll_halen = len;
    break;
  default:
    memcpy(sa->sa_data, p, len);	/*XXX*/
    break;
  }
  sa->sa_family = family;
#ifdef HAVE_SOCKADDR_SA_LEN
  sa->sa_len = ifa_sa_len(family, len);
#endif
}
开发者ID:alexshavelev,项目名称:lldpd,代码行数:31,代码来源:getifaddrs.c

示例3: copy_addr

static void copy_addr(struct sockaddr** r,
                      int af,
                      union sockany* sa,
                      void* addr,
                      size_t addrlen,
                      int ifindex) {
  uint8_t* dst;
  int len;

  switch (af) {
    case AF_INET:
      dst = (uint8_t*)&sa->v4.sin_addr;
      len = 4;
      break;
    case AF_INET6:
      dst = (uint8_t*)&sa->v6.sin6_addr;
      len = 16;
      if (IN6_IS_ADDR_LINKLOCAL(addr) || IN6_IS_ADDR_MC_LINKLOCAL(addr))
        sa->v6.sin6_scope_id = ifindex;
      break;
    default:
      return;
  }
  if (addrlen < len)
    return;
  sa->sa.sa_family = af;
  memcpy(dst, addr, len);
  *r = &sa->sa;
}
开发者ID:freiling,项目名称:mojo,代码行数:29,代码来源:getifaddrs.c

示例4: __inet6_scopeid_pton

/* Parse SOURCE as a scope ID for ADDRESS.  Return 0 on success and -1
   on error.  */
internal_function int
__inet6_scopeid_pton (const struct in6_addr *address, const char *scope,
                      uint32_t *result)
{
  if (IN6_IS_ADDR_LINKLOCAL (address)
      || IN6_IS_ADDR_MC_LINKLOCAL (address))
    {
      uint32_t number = __if_nametoindex (scope);
      if (number != 0)
        {
          *result = number;
          return 0;
        }
    }

  if (isdigit_l (scope[0], _nl_C_locobj_ptr))
    {
      char *end;
      unsigned long long number
        = ____strtoull_l_internal (scope, &end, /*base */ 10, /* group */ 0,
                                   _nl_C_locobj_ptr);
      if (*end == '\0' && number <= UINT32_MAX)
        {
          *result = number;
          return 0;
        }
    }

  __set_errno (EINVAL);
  return -1;
}
开发者ID:siddhesh,项目名称:glibc,代码行数:33,代码来源:inet6_scopeid_pton.c

示例5: defined

const char *
ACE_INET_Addr::get_host_addr (char *dst, int size) const
{
#if defined (ACE_HAS_IPV6)
  if (this->get_type () == AF_INET6)
    {
      // [email protected] - Aug-26, 2005
      // I don't think this should be done because it results in a decimal address
      // representation which is not distinguishable from the IPv4 form which makes
      // it impossible to resolve back to an IPv6 INET_Addr without prior knowledge
      // that this was such an address to begin with.

      //if (IN6_IS_ADDR_V4MAPPED (&this->inet_addr_.in6_.sin6_addr))
      //{
      //  ACE_UINT32 addr;
      //  addr = this->get_ip_address();
      //  addr = ACE_HTONL (addr);
      //  return ACE_OS::inet_ntop (AF_INET, &addr, dst, size);
      //}

#  if defined (ACE_WIN32)
      if (0 == ::getnameinfo (reinterpret_cast<const sockaddr*> (&this->inet_addr_.in6_),
                              this->get_size (),
                              dst,
                              size,
                              0, 0,    // Don't want service name
                              NI_NUMERICHOST))
        return dst;
      ACE_OS::set_errno_to_wsa_last_error ();
      return 0;
#  else
      const char *ch = ACE_OS::inet_ntop (AF_INET6,
                                          &this->inet_addr_.in6_.sin6_addr,
                                          dst,
                                          size);
#if defined (__linux__)
      if ((IN6_IS_ADDR_LINKLOCAL (&this->inet_addr_.in6_.sin6_addr) ||
           IN6_IS_ADDR_MC_LINKLOCAL (&this->inet_addr_.in6_.sin6_addr)) &&
          this->inet_addr_.in6_.sin6_scope_id != 0)
        {
          char scope_buf[32];
          ACE_OS::sprintf (scope_buf, "%%%u", this->inet_addr_.in6_.sin6_scope_id);
          if ((ACE_OS::strlen (ch)+ACE_OS::strlen (scope_buf)) < (size_t)size)
            {
              ACE_OS::strcat (dst, scope_buf);
            }
        }
#endif
      return ch;
#  endif /* ACE_WIN32 */
    }
#endif /* ACE_HAS_IPV6 */

  return ACE_OS::inet_ntop (AF_INET,
          &this->inet_addr_.in4_.sin_addr,
          dst,
          size);
}
开发者ID:Akenyshka,项目名称:MythCore,代码行数:58,代码来源:INET_Addr.cpp

示例6: _SC_string_to_sockaddr

struct sockaddr *
_SC_string_to_sockaddr(const char *str, sa_family_t af, void *buf, size_t bufLen)
{
	union {
		void			*buf;
		struct sockaddr		*sa;
		struct sockaddr_in	*sin;
		struct sockaddr_in6	*sin6;
	} addr;

	if (buf == NULL) {
		bufLen = sizeof(struct sockaddr_storage);
		addr.buf = CFAllocatorAllocate(NULL, bufLen, 0);
	} else {
		addr.buf = buf;
	}

	bzero(addr.buf, bufLen);
	if (((af == AF_UNSPEC) || (af == AF_INET)) &&
	    (bufLen >= sizeof(struct sockaddr_in)) &&
	    inet_aton(str, &addr.sin->sin_addr) == 1) {
		// if IPv4 address
		addr.sin->sin_len    = sizeof(struct sockaddr_in);
		addr.sin->sin_family = AF_INET;
	} else if (((af == AF_UNSPEC) || (af == AF_INET6)) &&
		   (bufLen >= sizeof(struct sockaddr_in6)) &&
		   inet_pton(AF_INET6, str, &addr.sin6->sin6_addr) == 1) {
		// if IPv6 address
		char	*p;

		addr.sin6->sin6_len    = sizeof(struct sockaddr_in6);
		addr.sin6->sin6_family = AF_INET6;

		p = strchr(buf, '%');
		if (p != NULL) {
			addr.sin6->sin6_scope_id = if_nametoindex(p + 1);
		}

		if (IN6_IS_ADDR_LINKLOCAL(&addr.sin6->sin6_addr) ||
		    IN6_IS_ADDR_MC_LINKLOCAL(&addr.sin6->sin6_addr)) {
			uint16_t	if_index;

			if_index = ntohs(addr.sin6->sin6_addr.__u6_addr.__u6_addr16[1]);
			addr.sin6->sin6_addr.__u6_addr.__u6_addr16[1] = 0;
			if (addr.sin6->sin6_scope_id == 0) {
				// use the scope id that was embedded in the [link local] IPv6 address
				addr.sin6->sin6_scope_id = if_index;
			}
		}
	} else {
		if (addr.buf != buf) {
			CFAllocatorDeallocate(NULL, addr.buf);
		}
		addr.buf = NULL;
	}

	return addr.sa;
}
开发者ID:010001111,项目名称:darling,代码行数:58,代码来源:SCDPrivate.c

示例7: parse_kernel_route

static int
parse_kernel_route(const struct rt_msghdr *rtm, struct kernel_route *route)
{

    void *rta = (void*)rtm + sizeof(struct rt_msghdr);
    struct sockaddr_in6 *sin6;
    char addr[INET6_ADDRSTRLEN];

    memset(route, 0, sizeof(*route));
    route->metric = 0;
    route->ifindex = rtm->rtm_index;

    if(!(rtm->rtm_addrs & RTA_DST))
        return -1;
    sin6 = (struct sockaddr_in6 *)rta;
    if(IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) 
       || IN6_IS_ADDR_MC_LINKLOCAL(&sin6->sin6_addr))
        return -1;
    if((rtm->rtm_flags & RTF_PROTO2) != 0)
        return -1;
    memcpy(&route->prefix, &sin6->sin6_addr, 16);
    rta += ROUNDUP(sizeof(struct sockaddr_in6));
   
    if(!(rtm->rtm_addrs & RTA_GATEWAY))
        return -1;

    sin6 = (struct sockaddr_in6 *)rta;
    if(IN6_IS_ADDR_LINKLOCAL (&sin6->sin6_addr)) {
        route->ifindex = IN6_LINKLOCAL_IFINDEX(sin6->sin6_addr);
        SET_IN6_LINKLOCAL_IFINDEX(sin6->sin6_addr, 0);
    }
    memcpy(&route->gw, &sin6->sin6_addr, 16);
    rta += ROUNDUP(sizeof(struct sockaddr_in6));

    if(!(rtm->rtm_addrs & RTA_NETMASK)) {
        route->plen = 0;
    } else {
        sin6 = (struct sockaddr_in6 *)rta;        
        route->plen = mask2len(&sin6->sin6_addr);
        inet_ntop(AF_INET6, &sin6->sin6_addr, addr, sizeof(addr));
        rta += ROUNDUP(sizeof(struct sockaddr_in6));
    }
    if (rtm->rtm_flags & RTF_HOST)
        route->plen = 128;

    if(ifindex_lo < 0) {
        ifindex_lo = if_nametoindex("lo0");
        if(ifindex_lo <= 0)
            return -1;
    }

    if(route->ifindex == ifindex_lo)
        return -1;

    return 0;

}
开发者ID:neevor,项目名称:babeld,代码行数:57,代码来源:kernel_socket.c

示例8: rr_command_check

/*
 * check validity of a router renumbering command packet
 * return 0 on success, 1 on failure
 */
static int
rr_command_check(int len, struct icmp6_router_renum *rr, struct in6_addr *from,
		 struct in6_addr *dst)
{
	char ntopbuf[INET6_ADDRSTRLEN];

	/* omit rr minimal length check. hope kernel have done it. */
	/* rr_command length check */
	if (len < (sizeof(struct icmp6_router_renum) +
		   sizeof(struct rr_pco_match))) {
		syslog(LOG_ERR,	"<%s> rr_command len %d is too short",
		       __func__, len);
		return 1;
	}

	/* destination check. only for multicast. omit unicast check. */
	if (IN6_IS_ADDR_MULTICAST(dst) && !IN6_IS_ADDR_MC_LINKLOCAL(dst) &&
	    !IN6_IS_ADDR_MC_SITELOCAL(dst)) {
		syslog(LOG_ERR,	"<%s> dst mcast addr %s is illegal",
		       __func__,
		       inet_ntop(AF_INET6, dst, ntopbuf, INET6_ADDRSTRLEN));
		return 1;
	}

	/* seqnum and segnum check */
	if (rro.rro_seqnum > rr->rr_seqnum) {
		syslog(LOG_WARNING,
		       "<%s> rcvd old seqnum %d from %s",
		       __func__, (u_int32_t)ntohl(rr->rr_seqnum),
		       inet_ntop(AF_INET6, from, ntopbuf, INET6_ADDRSTRLEN));
		return 1;
	}
	if (rro.rro_seqnum == rr->rr_seqnum &&
	    (rr->rr_flags & ICMP6_RR_FLAGS_TEST) == 0 &&
	    RR_ISSET_SEGNUM(rro.rro_segnum_bits, rr->rr_segnum)) {
		if ((rr->rr_flags & ICMP6_RR_FLAGS_REQRESULT) != 0)
			syslog(LOG_WARNING,
			       "<%s> rcvd duped segnum %d from %s",
			       __func__, rr->rr_segnum,
			       inet_ntop(AF_INET6, from, ntopbuf,
					 INET6_ADDRSTRLEN));
		return 0;
	}

	/* update seqnum */
	if (rro.rro_seqnum != rr->rr_seqnum) {
		/* then must be "<" */

		/* init rro_segnum_bits */
		memset(rro.rro_segnum_bits, 0,
		       sizeof(rro.rro_segnum_bits));
	}
	rro.rro_seqnum = rr->rr_seqnum;

	return 0;
}
开发者ID:Leon555,项目名称:Mac-src-essentials,代码行数:60,代码来源:rrenum.c

示例9: inet6name

char *
inet6name(struct in6_addr *in6p)
{
	char *cp;
	static char line[NI_MAXHOST];
	struct hostent *hp;
	static char domain[MAXHOSTNAMELEN];
	static int first = 1;
	char hbuf[NI_MAXHOST];
	struct sockaddr_in6 sin6;
	const int niflag = NI_NUMERICHOST;

	if (first && !nflag) {
		first = 0;
		if (gethostname(domain, sizeof(domain)) == 0 &&
		    (cp = strchr(domain, '.')))
			(void) strlcpy(domain, cp + 1, sizeof domain);
		else
			domain[0] = '\0';
	}
	cp = 0;
	if (!nflag && !IN6_IS_ADDR_UNSPECIFIED(in6p)) {
		hp = gethostbyaddr((char *)in6p, sizeof(*in6p), AF_INET6);
		if (hp) {
			if ((cp = strchr(hp->h_name, '.')) &&
			    !strcmp(cp + 1, domain))
				*cp = 0;
			cp = hp->h_name;
		}
	}
	if (IN6_IS_ADDR_UNSPECIFIED(in6p))
		strlcpy(line, "*", sizeof(line));
	else if (cp)
		strlcpy(line, cp, sizeof(line));
	else {
		memset(&sin6, 0, sizeof(sin6));
		sin6.sin6_len = sizeof(sin6);
		sin6.sin6_family = AF_INET6;
		sin6.sin6_addr = *in6p;
#ifdef __KAME__
		if (IN6_IS_ADDR_LINKLOCAL(in6p) ||
		    IN6_IS_ADDR_MC_LINKLOCAL(in6p)) {
			sin6.sin6_scope_id =
			    ntohs(*(u_int16_t *)&in6p->s6_addr[2]);
			sin6.sin6_addr.s6_addr[2] = 0;
			sin6.sin6_addr.s6_addr[3] = 0;
		}
#endif
		if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len,
		    hbuf, sizeof(hbuf), NULL, 0, niflag) != 0)
			strlcpy(hbuf, "?", sizeof hbuf);
		strlcpy(line, hbuf, sizeof(line));
	}
	return (line);
}
开发者ID:MarginC,项目名称:kame,代码行数:55,代码来源:inet6.c

示例10: switch

bool
BNetworkAddress::IsMulticastLinkLocal() const
{
	switch (fAddress.ss_family) {
		case AF_INET6:
			return IN6_IS_ADDR_MC_LINKLOCAL(
				&((sockaddr_in6&)fAddress).sin6_addr);

		default:
			return false;
	}
}
开发者ID:looncraz,项目名称:haiku,代码行数:12,代码来源:NetworkAddress.cpp

示例11: svx_inetaddr_from_ipport

int svx_inetaddr_from_ipport(svx_inetaddr_t *self, const char *ip, uint16_t port)
{
    int   r = 0;
    char *ifname = NULL;
    char  ipv6[INET6_ADDRSTRLEN + 1 + IF_NAMESIZE + 1];

    if(NULL == self || NULL == ip) SVX_LOG_ERRNO_RETURN_ERR(SVX_ERRNO_INVAL, "self:%p, ip:%p\n", self, ip);
    
    memset(self, 0, sizeof(svx_inetaddr_t));

    if(!strchr(ip, ':'))
    {
        /* IPv4 */
        self->storage.addr4.sin_family = AF_INET;
        self->storage.addr4.sin_port = htons(port);
        if(1 != (r = inet_pton(AF_INET, ip, &(self->storage.addr4.sin_addr))))
            SVX_LOG_ERRNO_RETURN_ERR((0 == r ? SVX_ERRNO_INVAL : errno), "ip:%s\n", ip);
    }
    else
    {
        /* IPv6 */
        self->storage.addr6.sin6_family = AF_INET6;
        self->storage.addr6.sin6_port = htons(port);
        self->storage.addr6.sin6_flowinfo = 0; /* ignored, always 0 */
        self->storage.addr6.sin6_scope_id = 0; /* only used for link-local IPv6 address */

        strncpy(ipv6, ip, sizeof(ipv6));
        if(NULL != (ifname = strchr(ipv6, '%')))
        {
            *ifname = '\0';
            ifname++;
        }
        
        if(1 != (r = inet_pton(AF_INET6, ipv6, &(self->storage.addr6.sin6_addr))))
            SVX_LOG_ERRNO_RETURN_ERR((0 == r ? SVX_ERRNO_INVAL : errno), "ip:%s\n", ipv6);

        /* set scope id for link-local IPv6 address */
        /* man ipv6(7): Linux supports it only for link-local addresses, 
           in that case sin6_scope_id contains the interface index */
        if(IN6_IS_ADDR_LINKLOCAL(&(self->storage.addr6.sin6_addr)) || 
           IN6_IS_ADDR_MC_LINKLOCAL(&(self->storage.addr6.sin6_addr)))
        {
            if(NULL == ifname || '\0' == *ifname)
                SVX_LOG_ERRNO_RETURN_ERR(SVX_ERRNO_FORMAT, "IPv6 link-local address without interface: %s\n", ip);
            if(0 == (self->storage.addr6.sin6_scope_id = if_nametoindex(ifname)))
                SVX_LOG_ERRNO_RETURN_ERR(errno, "ifname:%s\n", ifname);
        }
    }

    return 0;
}
开发者ID:JamesLinus,项目名称:libsvx,代码行数:51,代码来源:svx_inetaddr.c

示例12: inet6_uvif2scopeid

int
inet6_uvif2scopeid(struct sockaddr_in6 *sa, struct uvif *v)
{
	if (IN6_IS_ADDR_MULTICAST(&sa->sin6_addr)) {
		if (IN6_IS_ADDR_MC_LINKLOCAL(&sa->sin6_addr))
			return(v->uv_ifindex);
	}
	else {
		if (IN6_IS_ADDR_LINKLOCAL(&sa->sin6_addr))
			return(v->uv_ifindex);
	}

	return(0);
}
开发者ID:Balaji-Parasuram,项目名称:mcast-tools,代码行数:14,代码来源:inet6.c

示例13: asr_print_addr

/*
 * Print the textual representation (as given by inet_ntop(3)) of the address
 * set in "sa".
 *
 * Return the total length of the string it tried to create or 0 if an error
 * occured, in which case errno is set.  On success, the constructed string
 * is guaranteed to be NUL-terminated.  Overflow must be detected by checking
 * the returned size against buflen.
 *
 */
static size_t
asr_print_addr(const struct sockaddr *sa, char *buf, size_t buflen)
{
	unsigned int ifidx;
	char tmp[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")];
	char scope[IF_NAMESIZE + 1], *ifname;
	const void *addr;
	size_t s;

	switch(sa->sa_family) {
	case AF_INET:
		addr = &SA_IN(sa)->sin_addr;
		break;
	case AF_INET6:
		addr = &SA_IN6(sa)->sin6_addr;
		break;
	default:
		errno = EINVAL;
		return (0);
	}

	if (inet_ntop(sa->sa_family, addr, tmp, sizeof(tmp)) == NULL)
		return (0); /* errno set */

	s = strlcpy(buf, tmp, buflen);

	if (sa->sa_family == AF_INET6 && SA_IN6(sa)->sin6_scope_id) {

		scope[0] = SCOPE_DELIMITER;
		scope[1] = '\0';

		ifidx = SA_IN6(sa)->sin6_scope_id;
		ifname = NULL;

		if (IN6_IS_ADDR_LINKLOCAL(&(SA_IN6(sa)->sin6_addr)) ||
		    IN6_IS_ADDR_MC_LINKLOCAL(&(SA_IN6(sa)->sin6_addr)) ||
		    IN6_IS_ADDR_MC_INTFACELOCAL(&(SA_IN6(sa)->sin6_addr)))
			ifname = if_indextoname(ifidx, scope + 1);

		if (ifname == NULL)
			(void)snprintf(scope + 1, sizeof(scope) - 1, "%u", ifidx);

		if (s < buflen)
			(void)strlcat(buf, scope, buflen);

		s += strlen(scope);
	}

	return (s);
}
开发者ID:ajinkya93,项目名称:OpenBSD,代码行数:60,代码来源:getnameinfo.c

示例14: ifa_make_sockaddr_mask

static struct sockaddr *
ifa_make_sockaddr_mask (sa_family_t family,
			struct sockaddr *sa, uint32_t prefixlen)
{
  int i;
  char *p = NULL, c;
  uint32_t max_prefixlen = 0;

  if (sa == NULL)
    return NULL;
  switch (family)
    {
    case AF_INET:
      memset (&((struct sockaddr_in *) sa)->sin_addr, 0,
	      sizeof (((struct sockaddr_in *) sa)->sin_addr));
      p = (char *) &((struct sockaddr_in *) sa)->sin_addr;
      max_prefixlen = 32;
      break;
    case AF_INET6:
      memset (&((struct sockaddr_in6 *) sa)->sin6_addr, 0,
	      sizeof (((struct sockaddr_in6 *) sa)->sin6_addr));
      p = (char *) &((struct sockaddr_in6 *) sa)->sin6_addr;
#if 0				/* XXX: fill scope-id? */
      if (IN6_IS_ADDR_LINKLOCAL (p) || IN6_IS_ADDR_MC_LINKLOCAL (p))
	{
	  ((struct sockaddr_in6 *) sa)->sin6_scope_id = scopeid;
	}
#endif
      max_prefixlen = 128;
      break;
    default:
      return NULL;
    }
  sa->sa_family = family;
#ifdef HAVE_SOCKADDR_SA_LEN
  sa->sa_len = ifa_sa_len (family, len);
#endif
  if (p)
    {
      if (prefixlen > max_prefixlen)
	prefixlen = max_prefixlen;
      for (i = 0; i < (prefixlen / 8); i++)
	*p++ = 0xff;
      c = 0xff;
      c <<= (8 - (prefixlen % 8));
      *p = c;
    }
  return sa;
}
开发者ID:antonywcl,项目名称:AR-5315u_PLD,代码行数:49,代码来源:ifaddrs.c

示例15: add_scope

static void
add_scope(struct sockaddr *sa, int ifindex)
{
  struct sockaddr_in6 *sa6;

  if (sa->sa_family != AF_INET6)
    return;
  sa6 = (struct sockaddr_in6 *)sa;
  if (!IN6_IS_ADDR_LINKLOCAL(&sa6->sin6_addr) &&
      !IN6_IS_ADDR_MC_LINKLOCAL(&sa6->sin6_addr))
    return;
  if (*(u_int16_t *)&sa6->sin6_addr.s6_addr[2] != 0)
    return;
  *(u_int16_t *)&sa6->sin6_addr.s6_addr[2] = htons(ifindex);
}
开发者ID:Gwenio,项目名称:DragonFlyBSD,代码行数:15,代码来源:route.c


注:本文中的IN6_IS_ADDR_MC_LINKLOCAL函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。