MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / udp_input

Function udp_input

components/net/lwip/lwip-2.1.2/src/core/udp.c:193–443  ·  view source on GitHub ↗

* Process an incoming UDP datagram. * * Given an incoming UDP datagram (as a chain of pbufs) this function * finds a corresponding UDP PCB and hands over the pbuf to the pcbs * recv function. If no pcb is found or the datagram is incorrect, the * pbuf is freed. * * @param p pbuf to be demultiplexed to a UDP PCB (p->payload pointing to the UDP header) * @param inp network interface on which

Source from the content-addressed store, hash-verified

191 *
192 */
193void
194udp_input(struct pbuf *p, struct netif *inp)
195{
196 struct udp_hdr *udphdr;
197 struct udp_pcb *pcb, *prev;
198 struct udp_pcb *uncon_pcb;
199 u16_t src, dest;
200 u8_t broadcast;
201 u8_t for_us = 0;
202
203 LWIP_UNUSED_ARG(inp);
204
205 LWIP_ASSERT_CORE_LOCKED();
206
207 LWIP_ASSERT("udp_input: invalid pbuf", p != NULL);
208 LWIP_ASSERT("udp_input: invalid netif", inp != NULL);
209
210 PERF_START;
211
212 UDP_STATS_INC(udp.recv);
213
214 /* Check minimum length (UDP header) */
215 if (p->len < UDP_HLEN) {
216 /* drop short packets */
217 LWIP_DEBUGF(UDP_DEBUG,
218 ("udp_input: short UDP datagram (%"U16_F" bytes) discarded\n", p->tot_len));
219 UDP_STATS_INC(udp.lenerr);
220 UDP_STATS_INC(udp.drop);
221 MIB2_STATS_INC(mib2.udpinerrors);
222 pbuf_free(p);
223 goto end;
224 }
225
226 udphdr = (struct udp_hdr *)p->payload;
227
228 /* is broadcast packet ? */
229 broadcast = ip_addr_isbroadcast(ip_current_dest_addr(), ip_current_netif());
230
231 LWIP_DEBUGF(UDP_DEBUG, ("udp_input: received datagram of length %"U16_F"\n", p->tot_len));
232
233 /* convert src and dest ports to host byte order */
234 src = lwip_ntohs(udphdr->src);
235 dest = lwip_ntohs(udphdr->dest);
236
237 udp_debug_print(udphdr);
238
239 /* print the UDP source and destination */
240 LWIP_DEBUGF(UDP_DEBUG, ("udp ("));
241 ip_addr_debug_print_val(UDP_DEBUG, *ip_current_dest_addr());
242 LWIP_DEBUGF(UDP_DEBUG, (", %"U16_F") <-- (", lwip_ntohs(udphdr->dest)));
243 ip_addr_debug_print_val(UDP_DEBUG, *ip_current_src_addr());
244 LWIP_DEBUGF(UDP_DEBUG, (", %"U16_F")\n", lwip_ntohs(udphdr->src)));
245
246 pcb = NULL;
247 prev = NULL;
248 uncon_pcb = NULL;
249 /* Iterate through the UDP pcb list for a matching pcb.
250 * 'Perfect match' pcbs (connected to the remote port & ip address) are

Callers 4

ip6.cFile · 0.50
ip4.cFile · 0.50
ip_inputFunction · 0.50
ip.cFile · 0.50

Calls 12

lwip_ntohsFunction · 0.85
ip_addr_isanyFunction · 0.85
ip_addr_cmpFunction · 0.85
pbuf_remove_headerFunction · 0.85
pbuf_cloneFunction · 0.85
pbuf_freeFunction · 0.70
udp_debug_printFunction · 0.70
udp_input_local_matchFunction · 0.70
netif_get_ip6_addr_matchFunction · 0.70
ip_chksum_pseudo_partialFunction · 0.70
ip_chksum_pseudoFunction · 0.70
pbuf_header_forceFunction · 0.70

Tested by

no test coverage detected