Added a function simple_udp_sendto_port() for sending a UDP packet to a specified port.

This commit is contained in:
Adam Dunkels 2012-11-26 19:48:27 +01:00
parent 5c5545ba7d
commit f561bfc205
2 changed files with 32 additions and 0 deletions

View file

@ -113,6 +113,34 @@ simple_udp_sendto(struct simple_udp_connection *c,
return 0;
}
/*---------------------------------------------------------------------------*/
/**
* \brief Send a UDP packet to a specified IP address and UDP port
* \param c A pointer to a struct simple_udp_connection
* \param data A pointer to the data to be sent
* \param datalen The length of the data
* \param to The IP address of the receiver
* \param port The UDP port of the receiver, in host byte order
*
* This function sends a UDP packet to a specified IP
* address and UDP port. The packet will be sent with the
* UDP ports that were specified when the connection wa
* registered with simple_udp_register().
*
* \sa simple_udp_sendto()
*/
int
simple_udp_sendto_port(struct simple_udp_connection *c,
const void *data, uint16_t datalen,
const uip_ipaddr_t *to,
uint16_t port)
{
if(c->udp_conn != NULL) {
uip_udp_packet_sendto(c->udp_conn, data, datalen,
to, UIP_HTONS(port));
}
return 0;
}
/*---------------------------------------------------------------------------*/
/**
* \brief Register a UDP connection
* \param c A pointer to a struct simple_udp_connection

View file

@ -86,6 +86,10 @@ int simple_udp_sendto(struct simple_udp_connection *c,
const void *data, uint16_t datalen,
const uip_ipaddr_t *to);
int simple_udp_sendto_port(struct simple_udp_connection *c,
const void *data, uint16_t datalen,
const uip_ipaddr_t *to, uint16_t to_port);
void simple_udp_init(void);
#endif /* SIMPLE_UDP_H */