Added some defensive programming

This commit is contained in:
Adam Dunkels 2011-08-31 20:53:48 +02:00
parent 2b245cf850
commit 81e098d2da

View File

@ -46,23 +46,25 @@ extern u16_t uip_slen;
#include <string.h>
/*---------------------------------------------------------------------------*/
void
uip_udp_packet_send(struct uip_udp_conn *c, const void *data, int len)
{
#if UIP_UDP
if(data != NULL) {
uip_udp_conn = c;
uip_slen = len;
memcpy(&uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN], data, len > UIP_BUFSIZE? UIP_BUFSIZE: len);
memcpy(&uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN], data,
len > UIP_BUFSIZE? UIP_BUFSIZE: len);
uip_process(UIP_UDP_SEND_CONN);
#if UIP_CONF_IPV6 //math
#if UIP_CONF_IPV6
tcpip_ipv6_output();
#else
if(uip_len > 0) {
tcpip_output();
}
#endif
}
uip_slen = 0;
#endif /* UIP_UDP */
}
@ -74,6 +76,7 @@ uip_udp_packet_sendto(struct uip_udp_conn *c, const void *data, int len,
uip_ipaddr_t curaddr;
uint16_t curport;
if(toaddr != NULL) {
/* Save current IP addr/port. */
uip_ipaddr_copy(&curaddr, &c->ripaddr);
curport = c->rport;
@ -87,5 +90,6 @@ uip_udp_packet_sendto(struct uip_udp_conn *c, const void *data, int len,
/* Restore old IP addr/port */
uip_ipaddr_copy(&c->ripaddr, &curaddr);
c->rport = curport;
}
}
/*---------------------------------------------------------------------------*/