Lines Matching refs:addr
38 static inline uint16_t dn_ntohs(uint16_t addr) in dn_ntohs() argument
44 .word = addr, in dn_ntohs()
50 static inline int do_digit(char *str, uint16_t *addr, uint16_t scale, in do_digit() argument
53 uint16_t tmp = *addr / scale; in do_digit()
62 *addr -= (tmp * scale); in do_digit()
71 uint16_t addr = dn_ntohs(*(uint16_t *)addrbuf); in dnet_ntop() local
72 uint16_t area = addr >> 10; in dnet_ntop()
79 addr &= 0x03ff; in dnet_ntop()
97 if (do_digit(str + pos, &addr, 1000, &pos, len, &started)) in dnet_ntop()
100 if (do_digit(str + pos, &addr, 100, &pos, len, &started)) in dnet_ntop()
103 if (do_digit(str + pos, &addr, 10, &pos, len, &started)) in dnet_ntop()
106 if (do_digit(str + pos, &addr, 1, &pos, len, &started)) in dnet_ntop()
156 static void addr_destroy(struct nl_addr *addr) in addr_destroy() argument
158 if (!addr) in addr_destroy()
161 if (addr->a_refcnt != 1) in addr_destroy()
164 free(addr); in addr_destroy()
187 struct nl_addr *addr; in nl_addr_alloc() local
189 addr = calloc(1, sizeof(*addr) + maxsize); in nl_addr_alloc()
190 if (!addr) in nl_addr_alloc()
193 addr->a_refcnt = 1; in nl_addr_alloc()
194 addr->a_maxsize = maxsize; in nl_addr_alloc()
196 return addr; in nl_addr_alloc()
218 struct nl_addr *addr; in nl_addr_build() local
220 addr = nl_addr_alloc(size); in nl_addr_build()
221 if (!addr) in nl_addr_build()
224 addr->a_family = family; in nl_addr_build()
225 addr->a_len = size; in nl_addr_build()
226 addr->a_prefixlen = size*8; in nl_addr_build()
229 memcpy(addr->a_addr, buf, size); in nl_addr_build()
231 return addr; in nl_addr_build()
295 struct nl_addr *addr = NULL; /* gcc ain't that smart */ in nl_addr_parse() local
428 addr = nl_addr_alloc(len); in nl_addr_parse()
429 if (!addr) { in nl_addr_parse()
434 nl_addr_set_family(addr, family); in nl_addr_parse()
437 nl_addr_set_binary_addr(addr, buf, len); in nl_addr_parse()
443 addr_destroy(addr); in nl_addr_parse()
447 nl_addr_set_prefixlen(addr, pl); in nl_addr_parse()
449 nl_addr_set_prefixlen(addr, len * 8); in nl_addr_parse()
451 *result = addr; in nl_addr_parse()
471 struct nl_addr *nl_addr_clone(struct nl_addr *addr) in nl_addr_clone() argument
475 new = nl_addr_build(addr->a_family, addr->a_addr, addr->a_len); in nl_addr_clone()
477 new->a_prefixlen = addr->a_prefixlen; in nl_addr_clone()
501 struct nl_addr *nl_addr_get(struct nl_addr *addr) in nl_addr_get() argument
503 addr->a_refcnt++; in nl_addr_get()
505 return addr; in nl_addr_get()
517 void nl_addr_put(struct nl_addr *addr) in nl_addr_put() argument
519 if (!addr) in nl_addr_put()
522 if (addr->a_refcnt == 1) in nl_addr_put()
523 addr_destroy(addr); in nl_addr_put()
525 addr->a_refcnt--; in nl_addr_put()
534 int nl_addr_shared(struct nl_addr *addr) in nl_addr_shared() argument
536 return addr->a_refcnt > 1; in nl_addr_shared()
620 int nl_addr_iszero(struct nl_addr *addr) in nl_addr_iszero() argument
624 for (i = 0; i < addr->a_len; i++) in nl_addr_iszero()
625 if (addr->a_addr[i]) in nl_addr_iszero()
639 int nl_addr_valid(char *addr, int family) in nl_addr_valid() argument
647 ret = inet_pton(family, addr, buf); in nl_addr_valid()
653 ret = dnet_pton(addr, buf); in nl_addr_valid()
659 if (sscanf(addr, "%*02x:%*02x:%*02x:%*02x:%*02x:%*02x") != 6) in nl_addr_valid()
673 int nl_addr_guess_family(struct nl_addr *addr) in nl_addr_guess_family() argument
675 switch (addr->a_len) { in nl_addr_guess_family()
700 int nl_addr_fill_sockaddr(struct nl_addr *addr, struct sockaddr *sa, in nl_addr_fill_sockaddr() argument
703 switch (addr->a_family) { in nl_addr_fill_sockaddr()
710 sai->sin_family = addr->a_family; in nl_addr_fill_sockaddr()
711 memcpy(&sai->sin_addr, addr->a_addr, 4); in nl_addr_fill_sockaddr()
722 sa6->sin6_family = addr->a_family; in nl_addr_fill_sockaddr()
723 memcpy(&sa6->sin6_addr, addr->a_addr, 16); in nl_addr_fill_sockaddr()
756 int nl_addr_info(struct nl_addr *addr, struct addrinfo **result) in nl_addr_info() argument
762 .ai_family = addr->a_family, in nl_addr_info()
765 nl_addr2str(addr, buf, sizeof(buf)); in nl_addr_info()
800 int nl_addr_resolve(struct nl_addr *addr, char *host, size_t hostlen) in nl_addr_resolve() argument
806 err = nl_addr_fill_sockaddr(addr, (struct sockaddr *) &buf, &salen); in nl_addr_resolve()
832 void nl_addr_set_family(struct nl_addr *addr, int family) in nl_addr_set_family() argument
834 addr->a_family = family; in nl_addr_set_family()
845 int nl_addr_get_family(struct nl_addr *addr) in nl_addr_get_family() argument
847 return addr->a_family; in nl_addr_get_family()
870 int nl_addr_set_binary_addr(struct nl_addr *addr, void *buf, size_t len) in nl_addr_set_binary_addr() argument
872 if (len > addr->a_maxsize) in nl_addr_set_binary_addr()
875 addr->a_len = len; in nl_addr_set_binary_addr()
876 memset(addr->a_addr, 0, addr->a_maxsize); in nl_addr_set_binary_addr()
879 memcpy(addr->a_addr, buf, len); in nl_addr_set_binary_addr()
893 void *nl_addr_get_binary_addr(struct nl_addr *addr) in nl_addr_get_binary_addr() argument
895 return addr->a_addr; in nl_addr_get_binary_addr()
905 unsigned int nl_addr_get_len(struct nl_addr *addr) in nl_addr_get_len() argument
907 return addr->a_len; in nl_addr_get_len()
917 void nl_addr_set_prefixlen(struct nl_addr *addr, int prefixlen) in nl_addr_set_prefixlen() argument
919 addr->a_prefixlen = prefixlen; in nl_addr_set_prefixlen()
928 unsigned int nl_addr_get_prefixlen(struct nl_addr *addr) in nl_addr_get_prefixlen() argument
930 return addr->a_prefixlen; in nl_addr_get_prefixlen()
951 char *nl_addr2str(struct nl_addr *addr, char *buf, size_t size) in nl_addr2str() argument
956 if (!addr || !addr->a_len) { in nl_addr2str()
958 if (addr) in nl_addr2str()
964 switch (addr->a_family) { in nl_addr2str()
966 inet_ntop(AF_INET, addr->a_addr, buf, size); in nl_addr2str()
970 inet_ntop(AF_INET6, addr->a_addr, buf, size); in nl_addr2str()
974 dnet_ntop(addr->a_addr, addr->a_len, buf, size); in nl_addr2str()
980 (unsigned char) addr->a_addr[0]); in nl_addr2str()
981 for (i = 1; i < addr->a_len; i++) { in nl_addr2str()
983 (unsigned char) addr->a_addr[i]); in nl_addr2str()
990 if (addr->a_prefixlen != (8 * addr->a_len)) { in nl_addr2str()
991 snprintf(tmp, sizeof(tmp), "/%u", addr->a_prefixlen); in nl_addr2str()