[En-Nut-Discussion] UdpGetError() is only conditionally defined

Philipp Burch phip at hb9etc.ch
Mon Feb 11 09:16:50 CET 2013

Hi Ole!

On 02/10/2013 05:22 PM, Ole Reinhardt wrote:
> Hi Philipp and Harald,
>> just found this in sys/socket.h:
>> extern int NutUdpSetSocketError(UDPSOCKET * sock, uint32_t remote_addr,
>> uint16_t remote_port, uint16_t error);
>> extern int NutUdpError(UDPSOCKET * sock, uint32_t * addr, uint16_t * port);
>> #endif
>> Why is there an #ifdef with ICMP for these basic functions?
> The reason was quite simple:
> I added ICMP support for UDP quite some time ago because I needed it for
> a project.
> But the UDP error support slightly modifies the behavior of the
> NutUdpSendTo() and NutUdpReceiveFrom(). Both functions will return -1
> without sending/receiving the packet if an error is outstanding, as long
> as NUT_UDP_ICMP_SUPPORT is enabled.

Ok, this indeed may change the behaviour of existing applications. It 
does not, however, restrict the availability of NutUdpError(). In my 
opinion, NutUdpError() and NutUdpSetSocketError() should be available 
unconditionally (and simply retrieve/store the error code), while the 
behaviour of NutUdpSendTo() and NutUdpReceiveFrom() could depend on 
So an application may check which error occured, but the socket would 
function normally unless the macro is set.

> I did not want to break existing code and therefor added conditional
> compilation. This functionality is not enabled in the configurator by
> default. So by default you'll get the standard functionality of
> NutUdpSendTo() and NutUdpReceiveFrom()
>> It is not present in the source, so the functions will always be
>> compiled anyway.
> It is available, but I forgot it at some places.
>> Additionally, the doc still says "Todo: There is no similar call like
>> NutTcpError() available for UDP."
> Ok, that should be changed.
> [...]


More information about the En-Nut-Discussion mailing list