From f561bfc205fdd746f9d6307b8f86920ece0b9f8d Mon Sep 17 00:00:00 2001 From: Adam Dunkels Date: Mon, 26 Nov 2012 19:48:27 +0100 Subject: [PATCH] Added a function simple_udp_sendto_port() for sending a UDP packet to a specified port. --- core/net/simple-udp.c | 28 ++++++++++++++++++++++++++++ core/net/simple-udp.h | 4 ++++ 2 files changed, 32 insertions(+) diff --git a/core/net/simple-udp.c b/core/net/simple-udp.c index 97a39c89b..61197f452 100644 --- a/core/net/simple-udp.c +++ b/core/net/simple-udp.c @@ -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 diff --git a/core/net/simple-udp.h b/core/net/simple-udp.h index 8579dc497..0198c2f10 100644 --- a/core/net/simple-udp.h +++ b/core/net/simple-udp.h @@ -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 */