Lines Matching refs:addr
33 static inline uint16_t dn_ntohs(uint16_t addr) in dn_ntohs() argument
39 .word = addr, in dn_ntohs()
45 static inline int do_digit(char *str, uint16_t *addr, uint16_t scale, in do_digit() argument
48 uint16_t tmp = *addr / scale; in do_digit()
57 *addr -= (tmp * scale); in do_digit()
66 uint16_t addr = dn_ntohs(*(uint16_t *)addrbuf); in dnet_ntop() local
67 uint16_t area = addr >> 10; in dnet_ntop()
74 addr &= 0x03ff; in dnet_ntop()
92 if (do_digit(str + pos, &addr, 1000, &pos, len, &started)) in dnet_ntop()
95 if (do_digit(str + pos, &addr, 100, &pos, len, &started)) in dnet_ntop()
98 if (do_digit(str + pos, &addr, 10, &pos, len, &started)) in dnet_ntop()
101 if (do_digit(str + pos, &addr, 1, &pos, len, &started)) in dnet_ntop()
151 static void addr_destroy(struct nl_addr *addr) in addr_destroy() argument
153 if (!addr) in addr_destroy()
156 if (addr->a_refcnt != 1) in addr_destroy()
159 free(addr); in addr_destroy()
182 struct nl_addr *addr; in nl_addr_alloc() local
184 addr = calloc(1, sizeof(*addr) + maxsize); in nl_addr_alloc()
185 if (!addr) in nl_addr_alloc()
188 addr->a_refcnt = 1; in nl_addr_alloc()
189 addr->a_maxsize = maxsize; in nl_addr_alloc()
191 return addr; in nl_addr_alloc()
213 struct nl_addr *addr; in nl_addr_build() local
215 addr = nl_addr_alloc(size); in nl_addr_build()
216 if (!addr) in nl_addr_build()
219 addr->a_family = family; in nl_addr_build()
220 addr->a_len = size; in nl_addr_build()
223 addr->a_prefixlen = 20; /* MPLS address is a 20-bit label */ in nl_addr_build()
226 addr->a_prefixlen = size*8; in nl_addr_build()
230 memcpy(addr->a_addr, buf, size); in nl_addr_build()
232 return addr; in nl_addr_build()
296 struct nl_addr *addr = NULL; /* gcc ain't that smart */ in nl_addr_parse() local
442 addr = nl_addr_alloc(len); in nl_addr_parse()
443 if (!addr) { in nl_addr_parse()
448 nl_addr_set_family(addr, family); in nl_addr_parse()
451 nl_addr_set_binary_addr(addr, buf, len); in nl_addr_parse()
457 addr_destroy(addr); in nl_addr_parse()
461 nl_addr_set_prefixlen(addr, pl); in nl_addr_parse()
465 nl_addr_set_prefixlen(addr, plen); in nl_addr_parse()
467 *result = addr; in nl_addr_parse()
487 struct nl_addr *nl_addr_clone(const struct nl_addr *addr) in nl_addr_clone() argument
491 new = nl_addr_build(addr->a_family, addr->a_addr, addr->a_len); in nl_addr_clone()
493 new->a_prefixlen = addr->a_prefixlen; in nl_addr_clone()
517 struct nl_addr *nl_addr_get(struct nl_addr *addr) in nl_addr_get() argument
519 addr->a_refcnt++; in nl_addr_get()
521 return addr; in nl_addr_get()
533 void nl_addr_put(struct nl_addr *addr) in nl_addr_put() argument
535 if (!addr) in nl_addr_put()
538 if (addr->a_refcnt == 1) in nl_addr_put()
539 addr_destroy(addr); in nl_addr_put()
541 addr->a_refcnt--; in nl_addr_put()
550 int nl_addr_shared(const struct nl_addr *addr) in nl_addr_shared() argument
552 return addr->a_refcnt > 1; in nl_addr_shared()
644 int nl_addr_iszero(const struct nl_addr *addr) in nl_addr_iszero() argument
648 for (i = 0; i < addr->a_len; i++) in nl_addr_iszero()
649 if (addr->a_addr[i]) in nl_addr_iszero()
663 int nl_addr_valid(const char *addr, int family) in nl_addr_valid() argument
671 ret = inet_pton(family, addr, buf); in nl_addr_valid()
677 ret = mpls_pton(family, addr, buf, sizeof(buf)); in nl_addr_valid()
683 ret = dnet_pton(addr, buf); in nl_addr_valid()
689 if (sscanf(addr, "%*02x:%*02x:%*02x:%*02x:%*02x:%*02x") != 6) in nl_addr_valid()
703 int nl_addr_guess_family(const struct nl_addr *addr) in nl_addr_guess_family() argument
705 switch (addr->a_len) { in nl_addr_guess_family()
730 int nl_addr_fill_sockaddr(const struct nl_addr *addr, struct sockaddr *sa, in nl_addr_fill_sockaddr() argument
733 switch (addr->a_family) { in nl_addr_fill_sockaddr()
740 if (addr->a_len == 4) in nl_addr_fill_sockaddr()
741 memcpy(&sai->sin_addr, addr->a_addr, 4); in nl_addr_fill_sockaddr()
742 else if (addr->a_len != 0) in nl_addr_fill_sockaddr()
747 sai->sin_family = addr->a_family; in nl_addr_fill_sockaddr()
758 if (addr->a_len == 16) in nl_addr_fill_sockaddr()
759 memcpy(&sa6->sin6_addr, addr->a_addr, 16); in nl_addr_fill_sockaddr()
760 else if (addr->a_len != 0) in nl_addr_fill_sockaddr()
765 sa6->sin6_family = addr->a_family; in nl_addr_fill_sockaddr()
798 int nl_addr_info(const struct nl_addr *addr, struct addrinfo **result) in nl_addr_info() argument
804 .ai_family = addr->a_family, in nl_addr_info()
807 nl_addr2str(addr, buf, sizeof(buf)); in nl_addr_info()
842 int nl_addr_resolve(const struct nl_addr *addr, char *host, size_t hostlen) in nl_addr_resolve() argument
848 err = nl_addr_fill_sockaddr(addr, (struct sockaddr *) &buf, &salen); in nl_addr_resolve()
874 void nl_addr_set_family(struct nl_addr *addr, int family) in nl_addr_set_family() argument
876 addr->a_family = family; in nl_addr_set_family()
887 int nl_addr_get_family(const struct nl_addr *addr) in nl_addr_get_family() argument
889 return addr->a_family; in nl_addr_get_family()
912 int nl_addr_set_binary_addr(struct nl_addr *addr, const void *buf, size_t len) in nl_addr_set_binary_addr() argument
914 if (len > addr->a_maxsize) in nl_addr_set_binary_addr()
917 addr->a_len = len; in nl_addr_set_binary_addr()
918 memset(addr->a_addr, 0, addr->a_maxsize); in nl_addr_set_binary_addr()
921 memcpy(addr->a_addr, buf, len); in nl_addr_set_binary_addr()
935 void *nl_addr_get_binary_addr(const struct nl_addr *addr) in nl_addr_get_binary_addr() argument
937 return (void*)addr->a_addr; in nl_addr_get_binary_addr()
947 unsigned int nl_addr_get_len(const struct nl_addr *addr) in nl_addr_get_len() argument
949 return addr->a_len; in nl_addr_get_len()
959 void nl_addr_set_prefixlen(struct nl_addr *addr, int prefixlen) in nl_addr_set_prefixlen() argument
961 addr->a_prefixlen = prefixlen; in nl_addr_set_prefixlen()
970 unsigned int nl_addr_get_prefixlen(const struct nl_addr *addr) in nl_addr_get_prefixlen() argument
972 return addr->a_prefixlen; in nl_addr_get_prefixlen()
993 char *nl_addr2str(const struct nl_addr *addr, char *buf, size_t size) in nl_addr2str() argument
998 if (!addr || !addr->a_len) { in nl_addr2str()
1000 if (addr) in nl_addr2str()
1006 switch (addr->a_family) { in nl_addr2str()
1008 inet_ntop(AF_INET, addr->a_addr, buf, size); in nl_addr2str()
1012 inet_ntop(AF_INET6, addr->a_addr, buf, size); in nl_addr2str()
1016 mpls_ntop(AF_MPLS, addr->a_addr, buf, size); in nl_addr2str()
1020 dnet_ntop(addr->a_addr, addr->a_len, buf, size); in nl_addr2str()
1026 (unsigned char) addr->a_addr[0]); in nl_addr2str()
1027 for (i = 1; i < addr->a_len; i++) { in nl_addr2str()
1029 (unsigned char) addr->a_addr[i]); in nl_addr2str()
1036 if (addr->a_family != AF_MPLS && in nl_addr2str()
1037 addr->a_prefixlen != (8 * addr->a_len)) { in nl_addr2str()
1038 snprintf(tmp, sizeof(tmp), "/%u", addr->a_prefixlen); in nl_addr2str()