Lines Matching refs:addr
36 static inline uint16_t dn_ntohs(uint16_t addr) in dn_ntohs() argument
42 .word = addr, in dn_ntohs()
48 static inline int do_digit(char *str, uint16_t *addr, uint16_t scale, in do_digit() argument
51 uint16_t tmp = *addr / scale; in do_digit()
60 *addr -= (tmp * scale); in do_digit()
69 uint16_t addr = dn_ntohs(*(uint16_t *)addrbuf); in dnet_ntop() local
70 uint16_t area = addr >> 10; in dnet_ntop()
77 addr &= 0x03ff; in dnet_ntop()
95 if (do_digit(str + pos, &addr, 1000, &pos, len, &started)) in dnet_ntop()
98 if (do_digit(str + pos, &addr, 100, &pos, len, &started)) in dnet_ntop()
101 if (do_digit(str + pos, &addr, 10, &pos, len, &started)) in dnet_ntop()
104 if (do_digit(str + pos, &addr, 1, &pos, len, &started)) in dnet_ntop()
166 struct nl_addr *addr; in nl_addr_alloc() local
168 addr = calloc(1, sizeof(*addr) + maxsize); in nl_addr_alloc()
169 if (!addr) in nl_addr_alloc()
172 addr->a_refcnt = 1; in nl_addr_alloc()
173 addr->a_maxsize = maxsize; in nl_addr_alloc()
175 return addr; in nl_addr_alloc()
187 struct nl_addr *addr; in nl_addr_build() local
189 addr = nl_addr_alloc(size); in nl_addr_build()
190 if (!addr) in nl_addr_build()
193 addr->a_family = family; in nl_addr_build()
194 addr->a_len = size; in nl_addr_build()
195 addr->a_prefixlen = size*8; in nl_addr_build()
198 memcpy(addr->a_addr, buf, size); in nl_addr_build()
200 return addr; in nl_addr_build()
249 struct nl_addr *addr = NULL; /* gcc ain't that smart */ in nl_addr_parse() local
383 addr = nl_addr_alloc(len); in nl_addr_parse()
384 if (!addr) { in nl_addr_parse()
389 nl_addr_set_family(addr, family); in nl_addr_parse()
392 nl_addr_set_binary_addr(addr, buf, len); in nl_addr_parse()
398 nl_addr_destroy(addr); in nl_addr_parse()
402 nl_addr_set_prefixlen(addr, pl); in nl_addr_parse()
404 nl_addr_set_prefixlen(addr, len * 8); in nl_addr_parse()
406 *result = addr; in nl_addr_parse()
420 struct nl_addr *nl_addr_clone(struct nl_addr *addr) in nl_addr_clone() argument
424 new = nl_addr_build(addr->a_family, addr->a_addr, addr->a_len); in nl_addr_clone()
426 new->a_prefixlen = addr->a_prefixlen; in nl_addr_clone()
442 void nl_addr_destroy(struct nl_addr *addr) in nl_addr_destroy() argument
444 if (!addr) in nl_addr_destroy()
447 if (addr->a_refcnt != 1) in nl_addr_destroy()
450 free(addr); in nl_addr_destroy()
460 struct nl_addr *nl_addr_get(struct nl_addr *addr) in nl_addr_get() argument
462 addr->a_refcnt++; in nl_addr_get()
464 return addr; in nl_addr_get()
467 void nl_addr_put(struct nl_addr *addr) in nl_addr_put() argument
469 if (!addr) in nl_addr_put()
472 if (addr->a_refcnt == 1) in nl_addr_put()
473 nl_addr_destroy(addr); in nl_addr_put()
475 addr->a_refcnt--; in nl_addr_put()
483 int nl_addr_shared(struct nl_addr *addr) in nl_addr_shared() argument
485 return addr->a_refcnt > 1; in nl_addr_shared()
549 int nl_addr_iszero(struct nl_addr *addr) in nl_addr_iszero() argument
553 for (i = 0; i < addr->a_len; i++) in nl_addr_iszero()
554 if (addr->a_addr[i]) in nl_addr_iszero()
568 int nl_addr_valid(char *addr, int family) in nl_addr_valid() argument
576 ret = inet_pton(family, addr, buf); in nl_addr_valid()
582 ret = dnet_pton(addr, buf); in nl_addr_valid()
588 if (sscanf(addr, "%*02x:%*02x:%*02x:%*02x:%*02x:%*02x") != 6) in nl_addr_valid()
601 int nl_addr_guess_family(struct nl_addr *addr) in nl_addr_guess_family() argument
603 switch (addr->a_len) { in nl_addr_guess_family()
628 int nl_addr_fill_sockaddr(struct nl_addr *addr, struct sockaddr *sa, in nl_addr_fill_sockaddr() argument
631 switch (addr->a_family) { in nl_addr_fill_sockaddr()
638 sai->sin_family = addr->a_family; in nl_addr_fill_sockaddr()
639 memcpy(&sai->sin_addr, addr->a_addr, 4); in nl_addr_fill_sockaddr()
650 sa6->sin6_family = addr->a_family; in nl_addr_fill_sockaddr()
651 memcpy(&sa6->sin6_addr, addr->a_addr, 16); in nl_addr_fill_sockaddr()
684 int nl_addr_info(struct nl_addr *addr, struct addrinfo **result) in nl_addr_info() argument
690 .ai_family = addr->a_family, in nl_addr_info()
693 nl_addr2str(addr, buf, sizeof(buf)); in nl_addr_info()
728 int nl_addr_resolve(struct nl_addr *addr, char *host, size_t hostlen) in nl_addr_resolve() argument
734 err = nl_addr_fill_sockaddr(addr, (struct sockaddr *) &buf, &salen); in nl_addr_resolve()
753 void nl_addr_set_family(struct nl_addr *addr, int family) in nl_addr_set_family() argument
755 addr->a_family = family; in nl_addr_set_family()
758 int nl_addr_get_family(struct nl_addr *addr) in nl_addr_get_family() argument
760 return addr->a_family; in nl_addr_get_family()
769 int nl_addr_set_binary_addr(struct nl_addr *addr, void *buf, size_t len) in nl_addr_set_binary_addr() argument
771 if (len > addr->a_maxsize) in nl_addr_set_binary_addr()
774 addr->a_len = len; in nl_addr_set_binary_addr()
775 memcpy(addr->a_addr, buf, len); in nl_addr_set_binary_addr()
784 void *nl_addr_get_binary_addr(struct nl_addr *addr) in nl_addr_get_binary_addr() argument
786 return addr->a_addr; in nl_addr_get_binary_addr()
793 unsigned int nl_addr_get_len(struct nl_addr *addr) in nl_addr_get_len() argument
795 return addr->a_len; in nl_addr_get_len()
798 void nl_addr_set_prefixlen(struct nl_addr *addr, int prefixlen) in nl_addr_set_prefixlen() argument
800 addr->a_prefixlen = prefixlen; in nl_addr_set_prefixlen()
807 unsigned int nl_addr_get_prefixlen(struct nl_addr *addr) in nl_addr_get_prefixlen() argument
809 return addr->a_prefixlen; in nl_addr_get_prefixlen()
830 char *nl_addr2str(struct nl_addr *addr, char *buf, size_t size) in nl_addr2str() argument
835 if (!addr || !addr->a_len) { in nl_addr2str()
837 if (addr) in nl_addr2str()
843 switch (addr->a_family) { in nl_addr2str()
845 inet_ntop(AF_INET, addr->a_addr, buf, size); in nl_addr2str()
849 inet_ntop(AF_INET6, addr->a_addr, buf, size); in nl_addr2str()
853 dnet_ntop(addr->a_addr, addr->a_len, buf, size); in nl_addr2str()
859 (unsigned char) addr->a_addr[0]); in nl_addr2str()
860 for (i = 1; i < addr->a_len; i++) { in nl_addr2str()
862 (unsigned char) addr->a_addr[i]); in nl_addr2str()
869 if (addr->a_prefixlen != (8 * addr->a_len)) { in nl_addr2str()
870 snprintf(tmp, sizeof(tmp), "/%u", addr->a_prefixlen); in nl_addr2str()