Description: fix unprivileged (SOCK_DGRAM) ping ignoring all replies
 With an unprivileged ICMP datagram socket, the Linux kernel replaces the
 ICMP echo identifier with the socket's local port. fping 5.1 only reads
 that identifier back when a source address is given with -S, so without -S
 every reply is discarded as foreign and all targets are reported
 unreachable. Always read the identifier back when using SOCK_DGRAM.
 .
 This takes effect whenever fping can't open a raw socket, e.g. when
 /usr/bin/fping's cap_net_raw file capability isn't honoured (containers run
 with no-new-privileges, rootless or user-namespaced runtimes).
Author: David Schweikert <david@schweikert.ch>
Origin: upstream, https://github.com/schweikert/fping/commit/e975a4339b24716fb57bed234b0a1176f2bf3451
Bug: https://github.com/schweikert/fping/issues/248
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/fping/+bug/2178378
Applied-Upstream: 5.2
Last-Update: 2026-11-29
---
--- a/src/fping.c
+++ b/src/fping.c
@@ -1104,11 +1104,11 @@
         exit(num_noaddress ? 2 : 1);
     }
 
-    if (src_addr_set && socket4 >= 0) {
+    if (socket4 >= 0 && (src_addr_set || socktype4 == SOCK_DGRAM)) {
         socket_set_src_addr_ipv4(socket4, &src_addr, (socktype4 == SOCK_DGRAM) ? &ident4 : NULL);
     }
 #ifdef IPV6
-    if (src_addr6_set && socket6 >= 0) {
+    if (socket6 >= 0 && (src_addr6_set || socktype6 == SOCK_DGRAM)) {
         socket_set_src_addr_ipv6(socket6, &src_addr6, (socktype6 == SOCK_DGRAM) ? &ident6 : NULL);
     }
 #endif
