diff --git a/src/sample.c b/src/sample.c index eb005365c..6bb2dfd90 100644 --- a/src/sample.c +++ b/src/sample.c @@ -526,6 +526,14 @@ static int c_ip2ipv6(struct sample *smp) return 1; } +static int c_ipv62ip(struct sample *smp) +{ + if (!v6tov4(&smp->data.ipv4, &smp->data.ipv6)) + return 0; + smp->type = SMP_T_IPV6; + return 1; +} + static int c_ipv62str(struct sample *smp) { struct chunk *trash = get_trash_chunk(); @@ -554,6 +562,14 @@ static int c_int2ip(struct sample *smp) return 1; } +static int c_int2ipv6(struct sample *smp) +{ + smp->data.ipv4.s_addr = htonl((unsigned int)smp->data.sint); + v4tov6(&smp->data.ipv6, &smp->data.ipv4); + smp->type = SMP_T_IPV6; + return 1; +} + static int c_str2addr(struct sample *smp) { if (!buf2ip(smp->data.str.str, smp->data.str.len, &smp->data.ipv4)) { @@ -768,10 +784,10 @@ sample_cast_fct sample_casts[SMP_TYPES][SMP_TYPES] = { /* to: ANY BOOL SINT ADDR IPV4 IPV6 STR BIN METH */ /* from: ANY */ { c_none, c_none, c_none, c_none, c_none, c_none, c_none, c_none, c_none, }, /* BOOL */ { c_none, c_none, c_none, NULL, NULL, NULL, c_int2str, NULL, NULL, }, -/* SINT */ { c_none, c_none, c_none, c_int2ip, c_int2ip, NULL, c_int2str, c_int2bin, NULL, }, +/* SINT */ { c_none, c_none, c_none, c_int2ip, c_int2ip, c_int2ipv6, c_int2str, c_int2bin, NULL, }, /* ADDR */ { c_none, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, }, /* IPV4 */ { c_none, NULL, c_ip2int, c_none, c_none, c_ip2ipv6, c_ip2str, c_addr2bin, NULL, }, -/* IPV6 */ { c_none, NULL, NULL, c_none, NULL, c_none, c_ipv62str, c_addr2bin, NULL, }, +/* IPV6 */ { c_none, NULL, NULL, c_none, c_ipv62ip,c_none, c_ipv62str, c_addr2bin, NULL, }, /* STR */ { c_none, c_str2int, c_str2int, c_str2addr, c_str2ip, c_str2ipv6, c_none, c_none, c_str2meth, }, /* BIN */ { c_none, NULL, NULL, NULL, NULL, NULL, c_bin2str, c_none, c_str2meth, }, /* METH */ { c_none, NULL, NULL, NULL, NULL, NULL, c_meth2str, c_meth2str, c_none, }