aboutgitcodebugslistschat
path: root/icmp.c
diff options
context:
space:
mode:
Diffstat (limited to 'icmp.c')
-rw-r--r--icmp.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/icmp.c b/icmp.c
index b842fa8..ddf83f8 100644
--- a/icmp.c
+++ b/icmp.c
@@ -170,8 +170,16 @@ int icmp_tap_handler(const struct ctx *c, int af, const void *addr,
iref.icmp.id = id = ntohs(ih->un.echo.id);
if ((s = icmp_id_map[V4][id].sock) <= 0) {
- s = sock_l4(c, AF_INET, IPPROTO_ICMP, NULL, NULL, id,
- iref.u32);
+ const struct in_addr *bind_addr = NULL;
+ const char *bind_if;
+
+ bind_if = *c->ip4.ifname_out ? c->ip4.ifname_out : NULL;
+
+ if (!IN4_IS_ADDR_UNSPECIFIED(&c->ip4.addr_out))
+ bind_addr = &c->ip4.addr_out;
+
+ s = sock_l4(c, AF_INET, IPPROTO_ICMP, bind_addr,
+ bind_if, id, iref.u32);
if (s < 0)
goto fail_sock;
if (s > SOCKET_MAX) {
@@ -216,8 +224,16 @@ int icmp_tap_handler(const struct ctx *c, int af, const void *addr,
iref.icmp.id = id = ntohs(ih->icmp6_identifier);
if ((s = icmp_id_map[V6][id].sock) <= 0) {
- s = sock_l4(c, AF_INET6, IPPROTO_ICMPV6, NULL, NULL, id,
- iref.u32);
+ const struct in6_addr *bind_addr = NULL;
+ const char *bind_if;
+
+ bind_if = *c->ip6.ifname_out ? c->ip6.ifname_out : NULL;
+
+ if (!IN6_IS_ADDR_UNSPECIFIED(&c->ip6.addr_out))
+ bind_addr = &c->ip6.addr_out;
+
+ s = sock_l4(c, AF_INET6, IPPROTO_ICMPV6, bind_addr,
+ bind_if, id, iref.u32);
if (s < 0)
goto fail_sock;
if (s > SOCKET_MAX) {