diff options
Diffstat (limited to 'lib/ipaddr.h')
| -rw-r--r-- | lib/ipaddr.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/ipaddr.h b/lib/ipaddr.h index 98c28008dc..44bde45add 100644 --- a/lib/ipaddr.h +++ b/lib/ipaddr.h @@ -85,4 +85,21 @@ static inline char *ipaddr2str(struct ipaddr *ip, char *buf, int size) } return buf; } + +/* + * Convert IPv4 address to IPv4-mapped IPv6 address which is of the + * form ::FFFF:<IPv4 address> (RFC 4291). This IPv6 address can then + * be used to represent the IPv4 address, wherever only an IPv6 address + * is required. + */ +static inline void ipv4_to_ipv4_mapped_ipv6(struct in6_addr *in6, + struct in_addr in) +{ + u_int32_t addr_type = htonl(0xFFFF); + + memset(in6, 0, sizeof(struct in6_addr)); + memcpy((char *)in6 + 8, &addr_type, sizeof(addr_type)); + memcpy((char *)in6 + 12, &in, sizeof(struct in_addr)); +} + #endif /* __IPADDR_H__ */ |
