struct dns_api_msg *msg = (struct dns_api_msg*)arg;
LWIP_ASSERT("DNS response for wrong host name", strcmp(msg->name, name) == 0);
+ LWIP_UNUSED_ARG(name);
if (ipaddr == NULL) {
/* timeout or memory error */
sa->sin_addr.s_addr = addr.addr;
sa->sin_family = AF_INET;
sa->sin_len = sizeof(struct sockaddr_in);
- sa->sin_port = htons(port_nr);
+ sa->sin_port = htons((u16_t)port_nr);
/* set up addrinfo */
ai->ai_family = AF_INET;
* In that case, newconn->socket is counted down (newconn->socket--),
* so nsock->rcvevent is >= 1 here!
*/
- nsock->rcvevent += -1 - newconn->socket;
+ nsock->rcvevent += (s16_t)(-1 - newconn->socket);
newconn->socket = newsock;
sys_sem_signal(socksem);
return -1;
/* limit the "backlog" parameter to fit in an u8_t */
- if (backlog < 0) {
- backlog = 0;
- }
- if (backlog > 0xff) {
- backlog = 0xff;
- }
+ backlog = LWIP_MIN(LWIP_MAX(backlog, 0), 0xff);
- err = netconn_listen_with_backlog(sock->conn, backlog);
+ err = netconn_listen_with_backlog(sock->conn, (u8_t)backlog);
if (err != ERR_OK) {
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_listen(%d) failed, err=%d\n", s, err));
lwip_setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen)
{
struct lwip_socket *sock = get_socket(s);
- int err = ERR_OK;
+ err_t err = ERR_OK;
struct lwip_setgetsockopt_data data;
if (!sock)
case IPPROTO_UDPLITE:
switch (optname) {
case UDPLITE_SEND_CSCOV:
- if ((*(int*)optval != 0) && (*(int*)optval < 8)) {
+ if ((*(int*)optval != 0) && ((*(int*)optval < 8)) || (*(int*)optval > 0xffff)) {
/* don't allow illegal values! */
sock->conn->pcb.udp->chksum_len_tx = 8;
} else {
- sock->conn->pcb.udp->chksum_len_tx = *(int*)optval;
+ sock->conn->pcb.udp->chksum_len_tx = (u16_t)*(int*)optval;
}
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_UDPLITE, UDPLITE_SEND_CSCOV) -> %d\n",
s, (*(int*)optval)) );
break;
case UDPLITE_RECV_CSCOV:
- if ((*(int*)optval != 0) && (*(int*)optval < 8)) {
+ if ((*(int*)optval != 0) && ((*(int*)optval < 8)) || (*(int*)optval > 0xffff)) {
/* don't allow illegal values! */
sock->conn->pcb.udp->chksum_len_rx = 8;
} else {
- sock->conn->pcb.udp->chksum_len_rx = *(int*)optval;
+ sock->conn->pcb.udp->chksum_len_rx = (u16_t)*(int*)optval;
}
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_UDPLITE, UDPLITE_RECV_CSCOV) -> %d\n",
s, (*(int*)optval)) );
#if LWIP_NETIF_HOSTNAME
p = (const char*)netif->hostname;
if (p != NULL) {
- dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, strlen(p));
+ u8_t namelen = (u8_t)strlen(p);
+ LWIP_ASSERT("DHCP: hostname is too long!", namelen < 255);
+ dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, namelen);
while (*p) {
dhcp_option_byte(dhcp, *p++);
}
#if LWIP_NETIF_HOSTNAME
p = (const char*)netif->hostname;
if (p != NULL) {
- dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, strlen(p));
+ u8_t namelen = (u8_t)strlen(p);
+ LWIP_ASSERT("DHCP: hostname is too long!", namelen < 255);
+ dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, namelen);
while (*p) {
dhcp_option_byte(dhcp, *p++);
}
#if LWIP_NETIF_HOSTNAME
p = (const char*)netif->hostname;
if (p != NULL) {
- dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, strlen(p));
+ u8_t namelen = (u8_t)strlen(p);
+ LWIP_ASSERT("DHCP: hostname is too long!", namelen < 255);
+ dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, namelen);
while (*p) {
dhcp_option_byte(dhcp, *p++);
}
MEMCPY( query, &qry, SIZEOF_DNS_QUERY);
/* resize pbuf to the exact dns query */
- pbuf_realloc(p, (query + SIZEOF_DNS_QUERY) - ((char*)(p->payload)));
+ pbuf_realloc(p, (u16_t)((query + SIZEOF_DNS_QUERY) - ((char*)(p->payload))));
/* connect to the server for faster receiving */
udp_connect(dns_pcb, &dns_servers[numdns], DNS_SERVER_PORT);
static void
dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16_t port)
{
- u8_t i;
+ u16_t i;
char *pHostname;
struct dns_hdr *hdr;
struct dns_answer ans;
struct dns_table_entry *pEntry;
- u8_t nquestions, nanswers;
+ u16_t nquestions, nanswers;
#if (DNS_USES_STATIC_BUF == 0)
u8_t dns_payload[DNS_MSG_SIZE];
#endif /* (DNS_USES_STATIC_BUF == 0) */
sum = SWAP_BYTES_IN_WORD(sum);
}
- return sum;
+ return (u16_t)sum;
}
#endif
sum = SWAP_BYTES_IN_WORD(sum);
}
- return sum;
+ return (u16_t)sum;
}
#endif
static int
ip_reass_free_complete_datagram(struct ip_reassdata *ipr, struct ip_reassdata *prev)
{
- int pbufs_freed = 0;
+ u16_t pbufs_freed = 0;
+ u8_t clen;
struct pbuf *p;
struct ip_reass_helper *iprh;
/* Then, copy the original header into it. */
SMEMCPY(p->payload, &ipr->iphdr, IP_HLEN);
icmp_time_exceeded(p, ICMP_TE_FRAG);
- pbufs_freed += pbuf_clen(p);
+ clen = pbuf_clen(p);
+ LWIP_ASSERT("pbufs_freed + clen <= 0xffff", pbufs_freed + clen <= 0xffff);
+ pbufs_freed += clen;
pbuf_free(p);
}
#endif /* LWIP_ICMP */
pcur = p;
/* get the next pointer before freeing */
p = iprh->next_pbuf;
- pbufs_freed += pbuf_clen(pcur);
- pbuf_free(pcur);
+ clen = pbuf_clen(pcur);
+ LWIP_ASSERT("pbufs_freed + clen <= 0xffff", pbufs_freed + clen <= 0xffff);
+ pbufs_freed += clen;
+ pbuf_free(pcur);
}
/* Then, unchain the struct ip_reassdata from the list and free it. */
ip_reass_dequeue_datagram(ipr, prev);
/* lookup current source address for this dst */
dst_if = ip_route(&td->dip);
dst_ip.addr = ntohl(dst_if->ip_addr.addr);
- trap_msg.sip_raw[0] = dst_ip.addr >> 24;
- trap_msg.sip_raw[1] = dst_ip.addr >> 16;
- trap_msg.sip_raw[2] = dst_ip.addr >> 8;
- trap_msg.sip_raw[3] = dst_ip.addr;
+ trap_msg.sip_raw[0] = (u8_t)(dst_ip.addr >> 24);
+ trap_msg.sip_raw[1] = (u8_t)(dst_ip.addr >> 16);
+ trap_msg.sip_raw[2] = (u8_t)(dst_ip.addr >> 8);
+ trap_msg.sip_raw[3] = (u8_t)dst_ip.addr;
trap_msg.gen_trap = generic_trap;
trap_msg.spc_trap = specific_trap;
if (generic_trap == SNMP_GENTRAP_ENTERPRISESPC)
pcb->rcv_ann_wnd = 0;
} else {
/* keep the right edge of window constant */
- pcb->rcv_ann_wnd = pcb->rcv_ann_right_edge - pcb->rcv_nxt;
+ u32_t new_rcv_ann_wnd = pcb->rcv_ann_right_edge - pcb->rcv_nxt;
+ LWIP_ASSERT("new_rcv_ann_wnd <= 0xffff", new_rcv_ann_wnd <= 0xffff);
+ pcb->rcv_ann_wnd = (u16_t)new_rcv_ann_wnd;
}
return 0;
}
static void tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb);
static struct tcp_hdr *
-tcp_output_set_header(struct tcp_pcb *pcb, struct pbuf *p, int optlen,
+tcp_output_set_header(struct tcp_pcb *pcb, struct pbuf *p, u16_t optlen,
u32_t seqno_be /* already in network byte order */)
{
struct tcp_hdr *tcphdr = p->payload;
struct pbuf* p;
struct ip_hdr* iphdr;
struct tcp_hdr* tcphdr;
- u16_t pbuf_len = sizeof(struct ip_hdr) + sizeof(struct tcp_hdr) + data_len;
+ u16_t pbuf_len = (u16_t)(sizeof(struct ip_hdr) + sizeof(struct tcp_hdr) + data_len);
p = pbuf_alloc(PBUF_RAW, pbuf_len, PBUF_POOL);
EXPECT_RETNULL(p != NULL);
tcphdr->ackno = htonl(ackno);
TCPH_HDRLEN_SET(tcphdr, sizeof(struct tcp_hdr)/4);
TCPH_FLAGS_SET(tcphdr, headerflags);
- tcphdr->wnd = htonl(TCP_WND);
+ tcphdr->wnd = htons(TCP_WND);
/* copy data */
memcpy((char*)tcphdr + sizeof(struct tcp_hdr), data, data_len);