mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-10-05 22:29:49 +00:00
Improve formatting by fixing wrong indents and lines too long.
This commit is contained in:
parent
9ca9649c1b
commit
047e3455f7
@ -100,7 +100,8 @@ udp_input(struct pbuf *p, struct netif *inp)
|
|||||||
|
|
||||||
if (pbuf_header(p, -((s16_t)(UDP_HLEN + IPH_HL(iphdr) * 4)))) {
|
if (pbuf_header(p, -((s16_t)(UDP_HLEN + IPH_HL(iphdr) * 4)))) {
|
||||||
/* drop short packets */
|
/* drop short packets */
|
||||||
LWIP_DEBUGF(UDP_DEBUG, ("udp_input: short UDP datagram (%"U16_F" bytes) discarded\n", p->tot_len));
|
LWIP_DEBUGF(UDP_DEBUG,
|
||||||
|
("udp_input: short UDP datagram (%"U16_F" bytes) discarded\n", p->tot_len));
|
||||||
UDP_STATS_INC(udp.lenerr);
|
UDP_STATS_INC(udp.lenerr);
|
||||||
UDP_STATS_INC(udp.drop);
|
UDP_STATS_INC(udp.drop);
|
||||||
snmp_inc_udpinerrors();
|
snmp_inc_udpinerrors();
|
||||||
@ -118,7 +119,9 @@ udp_input(struct pbuf *p, struct netif *inp)
|
|||||||
udp_debug_print(udphdr);
|
udp_debug_print(udphdr);
|
||||||
|
|
||||||
/* print the UDP source and destination */
|
/* print the UDP source and destination */
|
||||||
LWIP_DEBUGF(UDP_DEBUG, ("udp (%"U16_F".%"U16_F".%"U16_F".%"U16_F", %"U16_F") <-- (%"U16_F".%"U16_F".%"U16_F".%"U16_F", %"U16_F")\n",
|
LWIP_DEBUGF(UDP_DEBUG,
|
||||||
|
("udp (%"U16_F".%"U16_F".%"U16_F".%"U16_F", %"U16_F") <-- "
|
||||||
|
"(%"U16_F".%"U16_F".%"U16_F".%"U16_F", %"U16_F")\n",
|
||||||
ip4_addr1(&iphdr->dest), ip4_addr2(&iphdr->dest),
|
ip4_addr1(&iphdr->dest), ip4_addr2(&iphdr->dest),
|
||||||
ip4_addr3(&iphdr->dest), ip4_addr4(&iphdr->dest), ntohs(udphdr->dest),
|
ip4_addr3(&iphdr->dest), ip4_addr4(&iphdr->dest), ntohs(udphdr->dest),
|
||||||
ip4_addr1(&iphdr->src), ip4_addr2(&iphdr->src),
|
ip4_addr1(&iphdr->src), ip4_addr2(&iphdr->src),
|
||||||
@ -129,7 +132,9 @@ udp_input(struct pbuf *p, struct netif *inp)
|
|||||||
/* Iterate through the UDP pcb list for a matching pcb */
|
/* Iterate through the UDP pcb list for a matching pcb */
|
||||||
for (pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) {
|
for (pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) {
|
||||||
/* print the PCB local and remote address */
|
/* print the PCB local and remote address */
|
||||||
LWIP_DEBUGF(UDP_DEBUG, ("pcb (%"U16_F".%"U16_F".%"U16_F".%"U16_F", %"U16_F") --- (%"U16_F".%"U16_F".%"U16_F".%"U16_F", %"U16_F")\n",
|
LWIP_DEBUGF(UDP_DEBUG,
|
||||||
|
("pcb (%"U16_F".%"U16_F".%"U16_F".%"U16_F", %"U16_F") --- "
|
||||||
|
"(%"U16_F".%"U16_F".%"U16_F".%"U16_F", %"U16_F")\n",
|
||||||
ip4_addr1(&pcb->local_ip), ip4_addr2(&pcb->local_ip),
|
ip4_addr1(&pcb->local_ip), ip4_addr2(&pcb->local_ip),
|
||||||
ip4_addr3(&pcb->local_ip), ip4_addr4(&pcb->local_ip), pcb->local_port,
|
ip4_addr3(&pcb->local_ip), ip4_addr4(&pcb->local_ip), pcb->local_port,
|
||||||
ip4_addr1(&pcb->remote_ip), ip4_addr2(&pcb->remote_ip),
|
ip4_addr1(&pcb->remote_ip), ip4_addr2(&pcb->remote_ip),
|
||||||
@ -161,8 +166,7 @@ udp_input(struct pbuf *p, struct netif *inp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check checksum if this is a match or if it was directed at us. */
|
/* Check checksum if this is a match or if it was directed at us. */
|
||||||
if (pcb != NULL || ip_addr_cmp(&inp->ip_addr, &iphdr->dest))
|
if (pcb != NULL || ip_addr_cmp(&inp->ip_addr, &iphdr->dest)) {
|
||||||
{
|
|
||||||
LWIP_DEBUGF(UDP_DEBUG | DBG_TRACE, ("udp_input: calculating checksum\n"));
|
LWIP_DEBUGF(UDP_DEBUG | DBG_TRACE, ("udp_input: calculating checksum\n"));
|
||||||
pbuf_header(p, UDP_HLEN);
|
pbuf_header(p, UDP_HLEN);
|
||||||
#ifdef IPv6
|
#ifdef IPv6
|
||||||
@ -175,7 +179,8 @@ udp_input(struct pbuf *p, struct netif *inp)
|
|||||||
if (inet_chksum_pseudo(p, (struct ip_addr *)&(iphdr->src),
|
if (inet_chksum_pseudo(p, (struct ip_addr *)&(iphdr->src),
|
||||||
(struct ip_addr *)&(iphdr->dest),
|
(struct ip_addr *)&(iphdr->dest),
|
||||||
IP_PROTO_UDPLITE, ntohs(udphdr->len)) != 0) {
|
IP_PROTO_UDPLITE, ntohs(udphdr->len)) != 0) {
|
||||||
LWIP_DEBUGF(UDP_DEBUG | 2, ("udp_input: UDP Lite datagram discarded due to failing checksum\n"));
|
LWIP_DEBUGF(UDP_DEBUG | 2,
|
||||||
|
("udp_input: UDP Lite datagram discarded due to failing checksum\n"));
|
||||||
UDP_STATS_INC(udp.chkerr);
|
UDP_STATS_INC(udp.chkerr);
|
||||||
UDP_STATS_INC(udp.drop);
|
UDP_STATS_INC(udp.drop);
|
||||||
snmp_inc_udpinerrors();
|
snmp_inc_udpinerrors();
|
||||||
@ -189,8 +194,8 @@ udp_input(struct pbuf *p, struct netif *inp)
|
|||||||
if (inet_chksum_pseudo(p, (struct ip_addr *)&(iphdr->src),
|
if (inet_chksum_pseudo(p, (struct ip_addr *)&(iphdr->src),
|
||||||
(struct ip_addr *)&(iphdr->dest),
|
(struct ip_addr *)&(iphdr->dest),
|
||||||
IP_PROTO_UDP, p->tot_len) != 0) {
|
IP_PROTO_UDP, p->tot_len) != 0) {
|
||||||
LWIP_DEBUGF(UDP_DEBUG | 2, ("udp_input: UDP datagram discarded due to failing checksum\n"));
|
LWIP_DEBUGF(UDP_DEBUG | 2,
|
||||||
|
("udp_input: UDP datagram discarded due to failing checksum\n"));
|
||||||
UDP_STATS_INC(udp.chkerr);
|
UDP_STATS_INC(udp.chkerr);
|
||||||
UDP_STATS_INC(udp.drop);
|
UDP_STATS_INC(udp.drop);
|
||||||
snmp_inc_udpinerrors();
|
snmp_inc_udpinerrors();
|
||||||
@ -205,9 +210,7 @@ udp_input(struct pbuf *p, struct netif *inp)
|
|||||||
snmp_inc_udpindatagrams();
|
snmp_inc_udpindatagrams();
|
||||||
/* callback */
|
/* callback */
|
||||||
if (pcb->recv != NULL)
|
if (pcb->recv != NULL)
|
||||||
{
|
|
||||||
pcb->recv(pcb->recv_arg, pcb, p, &(iphdr->src), src);
|
pcb->recv(pcb->recv_arg, pcb, p, &(iphdr->src), src);
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
LWIP_DEBUGF(UDP_DEBUG | DBG_TRACE, ("udp_input: not for us.\n"));
|
LWIP_DEBUGF(UDP_DEBUG | DBG_TRACE, ("udp_input: not for us.\n"));
|
||||||
|
|
||||||
@ -229,8 +232,7 @@ udp_input(struct pbuf *p, struct netif *inp)
|
|||||||
} else {
|
} else {
|
||||||
pbuf_free(p);
|
pbuf_free(p);
|
||||||
}
|
}
|
||||||
end:
|
end:
|
||||||
|
|
||||||
PERF_STOP("udp_input");
|
PERF_STOP("udp_input");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -327,15 +329,16 @@ udp_send(struct udp_pcb *pcb, struct pbuf *p)
|
|||||||
}
|
}
|
||||||
/* chain header q in front of given pbuf p */
|
/* chain header q in front of given pbuf p */
|
||||||
pbuf_chain(q, p);
|
pbuf_chain(q, p);
|
||||||
/* { first pbuf q points to header pbuf } */
|
/* first pbuf q points to header pbuf */
|
||||||
LWIP_DEBUGF(UDP_DEBUG, ("udp_send: added header pbuf %p before given pbuf %p\n", (void *)q, (void *)p));
|
LWIP_DEBUGF(UDP_DEBUG,
|
||||||
|
("udp_send: added header pbuf %p before given pbuf %p\n", (void *)q, (void *)p));
|
||||||
/* adding a header within p succeeded */
|
/* adding a header within p succeeded */
|
||||||
} else {
|
} else {
|
||||||
/* first pbuf q equals given pbuf */
|
/* first pbuf q equals given pbuf */
|
||||||
q = p;
|
q = p;
|
||||||
LWIP_DEBUGF(UDP_DEBUG, ("udp_send: added header in given pbuf %p\n", (void *)p));
|
LWIP_DEBUGF(UDP_DEBUG, ("udp_send: added header in given pbuf %p\n", (void *)p));
|
||||||
}
|
}
|
||||||
/* { q now represents the packet to be sent } */
|
/* q now represents the packet to be sent */
|
||||||
udphdr = q->payload;
|
udphdr = q->payload;
|
||||||
udphdr->src = htons(pcb->local_port);
|
udphdr->src = htons(pcb->local_port);
|
||||||
udphdr->dest = htons(pcb->remote_port);
|
udphdr->dest = htons(pcb->remote_port);
|
||||||
@ -363,15 +366,15 @@ udp_send(struct udp_pcb *pcb, struct pbuf *p)
|
|||||||
udphdr->chksum = inet_chksum_pseudo(q, src_ip, &(pcb->remote_ip),
|
udphdr->chksum = inet_chksum_pseudo(q, src_ip, &(pcb->remote_ip),
|
||||||
IP_PROTO_UDP, pcb->chksum_len);
|
IP_PROTO_UDP, pcb->chksum_len);
|
||||||
/* chksum zero must become 0xffff, as zero means 'no checksum' */
|
/* chksum zero must become 0xffff, as zero means 'no checksum' */
|
||||||
if (udphdr->chksum == 0x0000) udphdr->chksum = 0xffff;
|
if (udphdr->chksum == 0x0000)
|
||||||
|
udphdr->chksum = 0xffff;
|
||||||
#else
|
#else
|
||||||
udphdr->chksum = 0x0000;
|
udphdr->chksum = 0x0000;
|
||||||
#endif
|
#endif
|
||||||
/* output to IP */
|
/* output to IP */
|
||||||
LWIP_DEBUGF(UDP_DEBUG, ("udp_send: ip_output_if (,,,,IP_PROTO_UDPLITE,)\n"));
|
LWIP_DEBUGF(UDP_DEBUG, ("udp_send: ip_output_if (,,,,IP_PROTO_UDPLITE,)\n"));
|
||||||
err = ip_output_if (q, src_ip, &pcb->remote_ip, pcb->ttl, pcb->tos, IP_PROTO_UDPLITE, netif);
|
err = ip_output_if(q, src_ip, &pcb->remote_ip, pcb->ttl, pcb->tos, IP_PROTO_UDPLITE, netif);
|
||||||
/* UDP */
|
} else { /* UDP */
|
||||||
} else {
|
|
||||||
LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP packet length %"U16_F"\n", q->tot_len));
|
LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP packet length %"U16_F"\n", q->tot_len));
|
||||||
udphdr->len = htons(q->tot_len);
|
udphdr->len = htons(q->tot_len);
|
||||||
/* calculate checksum */
|
/* calculate checksum */
|
||||||
@ -395,8 +398,9 @@ udp_send(struct udp_pcb *pcb, struct pbuf *p)
|
|||||||
/* did we chain a seperate header pbuf earlier? */
|
/* did we chain a seperate header pbuf earlier? */
|
||||||
if (q != p) {
|
if (q != p) {
|
||||||
/* free the header pbuf */
|
/* free the header pbuf */
|
||||||
pbuf_free(q); q = NULL;
|
pbuf_free(q);
|
||||||
/* { p is still referenced by the caller, and will live on } */
|
q = NULL;
|
||||||
|
/* p is still referenced by the caller, and will live on */
|
||||||
}
|
}
|
||||||
|
|
||||||
UDP_STATS_INC(udp.xmit);
|
UDP_STATS_INC(udp.xmit);
|
||||||
@ -439,26 +443,28 @@ udp_bind(struct udp_pcb *pcb, struct ip_addr *ipaddr, u16_t port)
|
|||||||
rebind = 1;
|
rebind = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this code does not allow upper layer to share a UDP port for
|
/* this code does not allow upper layer to share a UDP port for
|
||||||
listening to broadcast or multicast traffic (See SO_REUSE_ADDR and
|
listening to broadcast or multicast traffic (See SO_REUSE_ADDR and
|
||||||
SO_REUSE_PORT under *BSD). TODO: See where it fits instead, OR
|
SO_REUSE_PORT under *BSD). TODO: See where it fits instead, OR
|
||||||
combine with implementation of UDP PCB flags. Leon Woestenberg. */
|
combine with implementation of UDP PCB flags. Leon Woestenberg. */
|
||||||
#ifdef LWIP_UDP_TODO
|
#ifdef LWIP_UDP_TODO
|
||||||
/* port matches that of PCB in list? */
|
/* port matches that of PCB in list? */
|
||||||
else if ((ipcb->local_port == port) &&
|
else
|
||||||
|
if ((ipcb->local_port == port) &&
|
||||||
/* IP address matches, or one is IP_ADDR_ANY? */
|
/* IP address matches, or one is IP_ADDR_ANY? */
|
||||||
(ip_addr_isany(&(ipcb->local_ip)) ||
|
(ip_addr_isany(&(ipcb->local_ip)) ||
|
||||||
ip_addr_isany(ipaddr) ||
|
ip_addr_isany(ipaddr) ||
|
||||||
ip_addr_cmp(&(ipcb->local_ip), ipaddr))) {
|
ip_addr_cmp(&(ipcb->local_ip), ipaddr))) {
|
||||||
/* other PCB already binds to this local IP and port */
|
/* other PCB already binds to this local IP and port */
|
||||||
LWIP_DEBUGF(UDP_DEBUG, ("udp_bind: local port %"U16_F" already bound by another pcb\n", port));
|
LWIP_DEBUGF(UDP_DEBUG,
|
||||||
|
("udp_bind: local port %"U16_F" already bound by another pcb\n", port));
|
||||||
return ERR_USE;
|
return ERR_USE;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ip_addr_set(&pcb->local_ip, ipaddr);
|
ip_addr_set(&pcb->local_ip, ipaddr);
|
||||||
|
|
||||||
/* no port specified? */
|
/* no port specified? */
|
||||||
if (port == 0) {
|
if (port == 0) {
|
||||||
#ifndef UDP_LOCAL_PORT_RANGE_START
|
#ifndef UDP_LOCAL_PORT_RANGE_START
|
||||||
@ -487,7 +493,8 @@ udp_bind(struct udp_pcb *pcb, struct ip_addr *ipaddr, u16_t port)
|
|||||||
pcb->next = udp_pcbs;
|
pcb->next = udp_pcbs;
|
||||||
udp_pcbs = pcb;
|
udp_pcbs = pcb;
|
||||||
}
|
}
|
||||||
LWIP_DEBUGF(UDP_DEBUG | DBG_TRACE | DBG_STATE, ("udp_bind: bound to %"U16_F".%"U16_F".%"U16_F".%"U16_F", port %"U16_F"\n",
|
LWIP_DEBUGF(UDP_DEBUG | DBG_TRACE | DBG_STATE,
|
||||||
|
("udp_bind: bound to %"U16_F".%"U16_F".%"U16_F".%"U16_F", port %"U16_F"\n",
|
||||||
(u16_t)(ntohl(pcb->local_ip.addr) >> 24 & 0xff),
|
(u16_t)(ntohl(pcb->local_ip.addr) >> 24 & 0xff),
|
||||||
(u16_t)(ntohl(pcb->local_ip.addr) >> 16 & 0xff),
|
(u16_t)(ntohl(pcb->local_ip.addr) >> 16 & 0xff),
|
||||||
(u16_t)(ntohl(pcb->local_ip.addr) >> 8 & 0xff),
|
(u16_t)(ntohl(pcb->local_ip.addr) >> 8 & 0xff),
|
||||||
@ -540,14 +547,15 @@ udp_connect(struct udp_pcb *pcb, struct ip_addr *ipaddr, u16_t port)
|
|||||||
pcb->local_ip.addr = 0;
|
pcb->local_ip.addr = 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
LWIP_DEBUGF(UDP_DEBUG | DBG_TRACE | DBG_STATE, ("udp_connect: connected to %"U16_F".%"U16_F".%"U16_F".%"U16_F",port %"U16_F"\n",
|
LWIP_DEBUGF(UDP_DEBUG | DBG_TRACE | DBG_STATE,
|
||||||
|
("udp_connect: connected to %"U16_F".%"U16_F".%"U16_F".%"U16_F",port %"U16_F"\n",
|
||||||
(u16_t)(ntohl(pcb->remote_ip.addr) >> 24 & 0xff),
|
(u16_t)(ntohl(pcb->remote_ip.addr) >> 24 & 0xff),
|
||||||
(u16_t)(ntohl(pcb->remote_ip.addr) >> 16 & 0xff),
|
(u16_t)(ntohl(pcb->remote_ip.addr) >> 16 & 0xff),
|
||||||
(u16_t)(ntohl(pcb->remote_ip.addr) >> 8 & 0xff),
|
(u16_t)(ntohl(pcb->remote_ip.addr) >> 8 & 0xff),
|
||||||
(u16_t)(ntohl(pcb->remote_ip.addr) & 0xff), pcb->remote_port));
|
(u16_t)(ntohl(pcb->remote_ip.addr) & 0xff), pcb->remote_port));
|
||||||
|
|
||||||
/* Insert UDP PCB into the list of active UDP PCBs. */
|
/* Insert UDP PCB into the list of active UDP PCBs. */
|
||||||
for(ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) {
|
for (ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) {
|
||||||
if (pcb == ipcb) {
|
if (pcb == ipcb) {
|
||||||
/* already on the list, just return */
|
/* already on the list, just return */
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
@ -579,6 +587,7 @@ udp_recv(struct udp_pcb *pcb,
|
|||||||
pcb->recv = recv;
|
pcb->recv = recv;
|
||||||
pcb->recv_arg = recv_arg;
|
pcb->recv_arg = recv_arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove an UDP PCB.
|
* Remove an UDP PCB.
|
||||||
*
|
*
|
||||||
@ -596,7 +605,8 @@ udp_remove(struct udp_pcb *pcb)
|
|||||||
/* make list start at 2nd pcb */
|
/* make list start at 2nd pcb */
|
||||||
udp_pcbs = udp_pcbs->next;
|
udp_pcbs = udp_pcbs->next;
|
||||||
/* pcb not 1st in list */
|
/* pcb not 1st in list */
|
||||||
} else for(pcb2 = udp_pcbs; pcb2 != NULL; pcb2 = pcb2->next) {
|
} else
|
||||||
|
for (pcb2 = udp_pcbs; pcb2 != NULL; pcb2 = pcb2->next) {
|
||||||
/* find pcb in udp_pcbs list */
|
/* find pcb in udp_pcbs list */
|
||||||
if (pcb2->next != NULL && pcb2->next == pcb) {
|
if (pcb2->next != NULL && pcb2->next == pcb) {
|
||||||
/* remove pcb from list */
|
/* remove pcb from list */
|
||||||
@ -605,6 +615,7 @@ udp_remove(struct udp_pcb *pcb)
|
|||||||
}
|
}
|
||||||
memp_free(MEMP_UDP_PCB, pcb);
|
memp_free(MEMP_UDP_PCB, pcb);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a UDP PCB.
|
* Create a UDP PCB.
|
||||||
*
|
*
|
||||||
@ -614,7 +625,8 @@ udp_remove(struct udp_pcb *pcb)
|
|||||||
* @see udp_remove()
|
* @see udp_remove()
|
||||||
*/
|
*/
|
||||||
struct udp_pcb *
|
struct udp_pcb *
|
||||||
udp_new(void) {
|
udp_new(void)
|
||||||
|
{
|
||||||
struct udp_pcb *pcb;
|
struct udp_pcb *pcb;
|
||||||
pcb = memp_malloc(MEMP_UDP_PCB);
|
pcb = memp_malloc(MEMP_UDP_PCB);
|
||||||
/* could allocate UDP PCB? */
|
/* could allocate UDP PCB? */
|
||||||
@ -623,8 +635,6 @@ udp_new(void) {
|
|||||||
memset(pcb, 0, sizeof(struct udp_pcb));
|
memset(pcb, 0, sizeof(struct udp_pcb));
|
||||||
pcb->ttl = UDP_TTL;
|
pcb->ttl = UDP_TTL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return pcb;
|
return pcb;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -644,12 +654,3 @@ udp_debug_print(struct udp_hdr *udphdr)
|
|||||||
#endif /* UDP_DEBUG */
|
#endif /* UDP_DEBUG */
|
||||||
|
|
||||||
#endif /* LWIP_UDP */
|
#endif /* LWIP_UDP */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user