From: Ian Jackson Date: Tue, 2 Sep 2014 08:04:27 +0000 (+0100) Subject: Provide string_item_to_iaddr X-Git-Tag: base.ipv6-polypath-fixes-2.v1~94 X-Git-Url: https://git.distorted.org.uk/~mdw/secnet/commitdiff_plain/bb8398990f4b904047ddd8543f24c4ae683e1881 Provide string_item_to_iaddr This will be used shortly. Signed-off-by: Ian Jackson --- diff --git a/util.c b/util.c index 426fc69..9c8abb3 100644 --- a/util.c +++ b/util.c @@ -40,6 +40,7 @@ #include "util.h" #include "unaligned.h" #include "magic.h" +#include "ipaddr.h" #define MIN_BUFFER_SIZE 64 #define DEFAULT_BUFFER_SIZE 4096 @@ -478,6 +479,29 @@ extern void slilog_part(struct log_if *lf, int priority, const char *message, .. va_end(ap); } +void string_item_to_iaddr(const item_t *item, uint16_t port, union iaddr *ia, + const char *desc) +{ +#ifndef CONFIG_IPV6 + + ia->sin.sin_family=AF_INET; + ia->sin.sin_addr.s_addr=string_item_to_ipaddr(item,desc); + +#else /* CONFIG_IPV6 => we have adns_text2addr */ + + if (item->type!=t_string) + cfgfatal(item->loc,desc,"expecting a string IP (v4 or v6) address\n"); + socklen_t salen=sizeof(*ia); + int r=adns_text2addr(item->data.string, port, + adns_qf_addrlit_ipv4_quadonly, + &ia->sa, &salen); + assert(r!=ENOSPC); + if (r) cfgfatal(item->loc,desc,"invalid IP (v4 or v6) address: %s\n", + strerror(r)); + +#endif /* CONFIG_IPV6 */ +} + #define IADDR_NBUFS_SHIFT 3 #define IADDR_NBUFS (1 << IADDR_NBUFS_SHIFT) diff --git a/util.h b/util.h index e321814..33b2b2b 100644 --- a/util.h +++ b/util.h @@ -84,6 +84,9 @@ extern int consttime_memeq(const void *s1, const void *s2, size_t n); const char *iaddr_to_string(const union iaddr *ia); int iaddr_socklen(const union iaddr *ia); +void string_item_to_iaddr(const item_t *item, uint16_t port, union iaddr *ia, + const char *desc); + #define MINMAX(ae,be,op) ({ \ typeof((ae)) a=(ae); \ typeof((be)) b=(be); \