From a9cbdc141bfe21692e8259ba9f2cc7b576210263 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Wed, 7 Oct 2009 17:58:30 +0000 Subject: [PATCH] patch #6888: Patch for UDP Netbufs to support dest-addr and dest-port --- CHANGELOG | 4 ++++ src/api/api_msg.c | 9 +++++++++ src/api/netbuf.c | 5 +++++ src/include/lwip/netbuf.h | 9 +++++++++ src/include/lwip/opt.h | 7 +++++++ 5 files changed, 34 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 97f689c3..88146057 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -19,6 +19,10 @@ HISTORY ++ New features: + 2009-10-07 Simon Goldschmidt/Fabian Koch + * api_msg.c, netbuf.c/.h, opt.h: patch #6888: Patch for UDP Netbufs to + support dest-addr and dest-port (optional: LWIP_NETBUF_RECVINFO) + 2009-08-26 Simon Goldschmidt/Simon Kallweit * slipif.c/.h: bug #26397: SLIP polling support diff --git a/src/api/api_msg.c b/src/api/api_msg.c index ab4a9beb..a37ab115 100644 --- a/src/api/api_msg.c +++ b/src/api/api_msg.c @@ -168,6 +168,15 @@ recv_udp(void *arg, struct udp_pcb *pcb, struct pbuf *p, buf->ptr = p; buf->addr = addr; buf->port = port; +#if LWIP_NETBUF_RECVINFO + { + const struct ip_hdr* iphdr = ip_current_header(); + /* get the UDP header - always in the first pbuf, ensured by udp_input */ + const struct udp_hdr* udphdr = (void*)(((char*)iphdr) + IPH_LEN(iphdr)); + buf->toaddr = (struct ip_addr*)&iphdr->dest; + buf->toport = udphdr->dest; + } +#endif /* LWIP_NETBUF_RECVINFO */ } if (sys_mbox_trypost(conn->recvmbox, buf) != ERR_OK) { diff --git a/src/api/netbuf.c b/src/api/netbuf.c index af44eefc..57efc4f9 100644 --- a/src/api/netbuf.c +++ b/src/api/netbuf.c @@ -62,6 +62,11 @@ netbuf *netbuf_new(void) buf->p = NULL; buf->ptr = NULL; buf->addr = NULL; + buf->port = 0; +#if LWIP_NETBUF_RECVINFO + buf->toaddr = NULL; + buf->toport = 0; +#endif /* LWIP_NETBUF_RECVINFO */ return buf; } else { return NULL; diff --git a/src/include/lwip/netbuf.h b/src/include/lwip/netbuf.h index 6d84dd07..0dfb367a 100644 --- a/src/include/lwip/netbuf.h +++ b/src/include/lwip/netbuf.h @@ -34,6 +34,7 @@ #include "lwip/opt.h" #include "lwip/pbuf.h" +#include "lwip/ip_addr.h" #ifdef __cplusplus extern "C" { @@ -43,6 +44,10 @@ struct netbuf { struct pbuf *p, *ptr; struct ip_addr *addr; u16_t port; +#if LWIP_NETBUF_RECVINFO + struct ip_addr *toaddr; + u16_t toport; +#endif /* LWIP_NETBUF_RECVINFO */ }; /* Network buffer functions: */ @@ -69,6 +74,10 @@ void netbuf_first (struct netbuf *buf); #define netbuf_len(buf) ((buf)->p->tot_len) #define netbuf_fromaddr(buf) ((buf)->addr) #define netbuf_fromport(buf) ((buf)->port) +#if LWIP_NETBUF_RECVINFO +#define netbuf_destaddr(buf) ((buf)->toaddr) +#define netbuf_destport(buf) ((buf)->toport) +#endif /* LWIP_NETBUF_RECVINFO */ #ifdef __cplusplus } diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index 1723b35a..da7fc56b 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -728,6 +728,13 @@ #define UDP_TTL (IP_DEFAULT_TTL) #endif +/** + * LWIP_NETBUF_RECVINFO==1: append destination addr and port to every netbuf. + */ +#ifndef LWIP_NETBUF_RECVINFO +#define LWIP_NETBUF_RECVINFO 0 +#endif + /* --------------------------------- ---------- TCP options ----------