mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-21 13:51:26 +02:00
MINOR: tools: Add a function to convert buffer to an ipv6 address
The inet_pton function needs an input string with a final \0. This function copies the input string to a temporary buffer, adds the final \0 and converts to address.
This commit is contained in:
parent
9c1d67ecbd
commit
d559dd8390
@ -527,6 +527,7 @@ int word_match(const char *sample, int slen, const char *word, int wlen);
|
||||
* or the number of chars read in case of success.
|
||||
*/
|
||||
int buf2ip(const char *buf, size_t len, struct in_addr *dst);
|
||||
int buf2ip6(const char *buf, size_t len, struct in6_addr *dst);
|
||||
|
||||
/* To be used to quote config arg positions. Returns the string at <ptr>
|
||||
* surrounded by simple quotes if <ptr> is valid and non-empty, or "end of line"
|
||||
|
@ -1625,6 +1625,27 @@ int buf2ip(const char *buf, size_t len, struct in_addr *dst)
|
||||
return addr - cp;
|
||||
}
|
||||
|
||||
/* This function converts the string in <buf> of the len <len> to
|
||||
* struct in6_addr <dst> which must be allocated by the caller.
|
||||
* This function returns 1 in success case, otherwise zero.
|
||||
*/
|
||||
#define MAX_IP6_LEN 45
|
||||
int buf2ip6(const char *buf, size_t len, struct in6_addr *dst)
|
||||
{
|
||||
char null_term_ip6[MAX_IP6_LEN + 1];
|
||||
|
||||
if (len > MAX_IP6_LEN)
|
||||
return 0;
|
||||
|
||||
memcpy(null_term_ip6, buf, len);
|
||||
null_term_ip6[len] = '\0';
|
||||
|
||||
if (!inet_pton(AF_INET6, null_term_ip6, dst))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* To be used to quote config arg positions. Returns the short string at <ptr>
|
||||
* surrounded by simple quotes if <ptr> is valid and non-empty, or "end of line"
|
||||
* if ptr is NULL or empty. The string is locally allocated.
|
||||
|
Loading…
x
Reference in New Issue
Block a user