Description: Add `ipi_spec_dst` field to `struct in_pktinfo`
Forwarded: https://savannah.nongnu.org/patch/index.php?10555
Author: Joan Lledó <jlledom@member.fsf.org>
Last-Update: 2025-12-26

Index: lwip-deb/src/api/sockets.c
===================================================================
--- lwip-deb.orig/src/api/sockets.c	2026-01-04 19:06:46.000000000 +0100
+++ lwip-deb/src/api/sockets.c	2026-01-04 19:16:14.000000000 +0100
@@ -1272,6 +1272,9 @@
           chdr->cmsg_type = IP_PKTINFO;
           chdr->cmsg_len = CMSG_LEN(sizeof(struct in_pktinfo));
           pkti->ipi_ifindex = buf->p->if_idx;
+#if LWIP_SOCKET_HAVE_IPI_SPEC_DST
+          inet_addr_from_ip4addr(&pkti->ipi_spec_dst, ip_2_ip4(netbuf_ifaddr(buf)));
+#endif /* LWIP_SOCKET_HAVE_IPI_SPEC_DST */
           inet_addr_from_ip4addr(&pkti->ipi_addr, ip_2_ip4(netbuf_destaddr(buf)));
           msg->msg_controllen = CMSG_SPACE(sizeof(struct in_pktinfo));
           wrote_msg = 1;
Index: lwip-deb/src/include/lwip/sockets.h
===================================================================
--- lwip-deb.orig/src/include/lwip/sockets.h	2026-01-04 19:06:46.000000000 +0100
+++ lwip-deb/src/include/lwip/sockets.h	2026-01-04 19:14:18.000000000 +0100
@@ -62,6 +62,9 @@
 /* sockaddr and pals include length fields */
 #define LWIP_SOCKET_HAVE_SA_LEN  1
 
+/* in_pktinfo includes routing destination address */
+#define LWIP_SOCKET_HAVE_IPI_SPEC_DST  1
+
 /* If your port already typedef's sa_family_t, define SA_FAMILY_T_DEFINED
    to prevent this code from redefining it. */
 #if !defined(sa_family_t) && !defined(SA_FAMILY_T_DEFINED)
@@ -334,6 +337,7 @@
 #if LWIP_IPV4
 struct in_pktinfo {
   unsigned int   ipi_ifindex;  /* Interface index */
+  struct in_addr ipi_spec_dst; /* Destination (from routing) address */
   struct in_addr ipi_addr;     /* Destination (from header) address */
 };
 #endif /* LWIP_IPV4 */
Index: lwip-deb/src/api/api_msg.c
===================================================================
--- lwip-deb.orig/src/api/api_msg.c	2026-01-04 19:06:46.000000000 +0100
+++ lwip-deb/src/api/api_msg.c	2026-01-04 19:06:46.000000000 +0100
@@ -263,6 +263,7 @@
       /* get the UDP header - always in the first pbuf, ensured by udp_input */
       const struct udp_hdr *udphdr = (const struct udp_hdr *)ip_next_header_ptr();
       buf->flags = NETBUF_FLAG_DESTADDR;
+      ip_addr_set(&buf->ifaddr, netif_ip_addr4(ip_current_netif()));
       ip_addr_set(&buf->toaddr, ip_current_dest_addr());
       buf->toport_chksum = udphdr->dest;
     }
Index: lwip-deb/src/include/lwip/netbuf.h
===================================================================
--- lwip-deb.orig/src/include/lwip/netbuf.h	2026-01-04 19:06:46.000000000 +0100
+++ lwip-deb/src/include/lwip/netbuf.h	2026-01-04 19:06:46.000000000 +0100
@@ -65,6 +65,7 @@
   u8_t flags;
   u16_t toport_chksum;
 #if LWIP_NETBUF_RECVINFO
+  ip_addr_t ifaddr;
   ip_addr_t toaddr;
 #endif /* LWIP_NETBUF_RECVINFO */
 #endif /* LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY */
@@ -96,6 +97,8 @@
 #if LWIP_NETBUF_RECVINFO
 #define netbuf_destaddr(buf)         (&((buf)->toaddr))
 #define netbuf_set_destaddr(buf, destaddr) ip_addr_set(&((buf)->toaddr), destaddr)
+#define netbuf_ifaddr(buf)         (&((buf)->ifaddr))
+#define netbuf_set_ifaddr(buf, ifaddr) ip_addr_set(&((buf)->ifaddr), ifaddr)
 #if LWIP_CHECKSUM_ON_COPY
 #define netbuf_destport(buf)         (((buf)->flags & NETBUF_FLAG_DESTADDR) ? (buf)->toport_chksum : 0)
 #else /* LWIP_CHECKSUM_ON_COPY */
