diff --git a/src/core/inet.c b/src/core/inet.c index 95c984d3..a34ea132 100644 --- a/src/core/inet.c +++ b/src/core/inet.c @@ -241,6 +241,7 @@ lwip_standard_chksum(void *dataptr, int len) /* inet_chksum_pseudo: * * Calculates the pseudo Internet checksum used by TCP and UDP for a pbuf chain. + * IP addresses are expected to be in network byte order. */ u16_t diff --git a/src/core/udp.c b/src/core/udp.c index 5e1ef75b..6193961c 100644 --- a/src/core/udp.c +++ b/src/core/udp.c @@ -249,6 +249,8 @@ end: * @param dst_ip Destination IP address. * @param dst_port Destination UDP port. * + * dst_ip & dst_port are expected to be in the same byte order as in the pcb. + * * If the PCB already has a remote address association, it will * be restored after the data is sent. * @@ -430,6 +432,8 @@ udp_send(struct udp_pcb *pcb, struct pbuf *p) * bind to all local interfaces. * @param port local UDP port to bind with. * + * ipaddr & port are expected to be in the same byte order as in the pcb. + * * @return lwIP error code. * - ERR_OK. Successful. No error occured. * - ERR_USE. The specified ipaddr and port are already bound to by @@ -528,6 +532,8 @@ udp_bind(struct udp_pcb *pcb, struct ip_addr *ipaddr, u16_t port) * * @return lwIP error code * + * ipaddr & port are expected to be in the same byte order as in the pcb. + * * @see udp_disconnect() */ err_t diff --git a/src/include/ipv4/lwip/ip.h b/src/include/ipv4/lwip/ip.h index f5886740..866214d3 100644 --- a/src/include/ipv4/lwip/ip.h +++ b/src/include/ipv4/lwip/ip.h @@ -74,7 +74,9 @@ err_t ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, beginning of a PCB type definition. It is located here so that changes to this common part are made in one location instead of having to change all PCB structs. */ -#define IP_PCB struct ip_addr local_ip; \ +#define IP_PCB \ + /* ip addresses in network byte order */ \ + struct ip_addr local_ip; \ struct ip_addr remote_ip; \ /* Socket options */ \ u16_t so_options; \ diff --git a/src/include/lwip/sockets.h b/src/include/lwip/sockets.h index 9a1b440b..b0523561 100644 --- a/src/include/lwip/sockets.h +++ b/src/include/lwip/sockets.h @@ -42,6 +42,7 @@ extern "C" { #endif +/* members are in network byte order */ struct sockaddr_in { u8_t sin_len; u8_t sin_family; diff --git a/src/include/lwip/tcp.h b/src/include/lwip/tcp.h index 61be588d..24d245b1 100644 --- a/src/include/lwip/tcp.h +++ b/src/include/lwip/tcp.h @@ -170,6 +170,9 @@ void tcp_rexmit_rto (struct tcp_pcb *pcb); #define TCP_MAXIDLE TCP_KEEPCNT_DEFAULT * TCP_KEEPINTVL_DEFAULT /* Maximum KEEPALIVE probe time */ +/* Fields are (of course) in network byte order. + * Some fields are converted to host byte order in tcp_input(). + */ #ifdef PACK_STRUCT_USE_INCLUDES # include "arch/bpstruct.h" #endif @@ -226,6 +229,7 @@ struct tcp_pcb { u8_t prio; void *callback_arg; + /* ports are in host byte order */ u16_t local_port; u16_t remote_port; @@ -238,6 +242,8 @@ struct tcp_pcb { #define TF_GOT_FIN (u8_t)0x20U /* Connection was closed by the remote end. */ #define TF_NODELAY (u8_t)0x40U /* Disable Nagle algorithm */ + /* the rest of the fields are in host byte order + as we have to do some math with them */ /* receiver variables */ u32_t rcv_nxt; /* next seqno expected */ u16_t rcv_wnd; /* receiver window */ diff --git a/src/include/lwip/udp.h b/src/include/lwip/udp.h index 089066e3..90d4d302 100644 --- a/src/include/lwip/udp.h +++ b/src/include/lwip/udp.h @@ -44,6 +44,7 @@ extern "C" { #define UDP_HLEN 8 +/* Fields are (of course) in network byte order. */ struct udp_hdr { PACK_STRUCT_FIELD(u16_t src); PACK_STRUCT_FIELD(u16_t dest); /* src/dest UDP ports */ @@ -64,10 +65,13 @@ struct udp_pcb { struct udp_pcb *next; u8_t flags; + /* ports are in host byte order */ u16_t local_port, remote_port; + /* used for UDP_LITE only */ u16_t chksum_len; + /* addr and port are in same byte order as in the pcb */ void (* recv)(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16_t port); void *recv_arg;