User`s guide

KwikNet Low Level Services
K
A
DAK
125
Receiving UDP Datagrams
If you expect to receive a UDP datagram from a foreign host, your open request must
provide a pointer to an application callback function which KwikNet can call upon receipt
of such a UDP datagram. The callback function is prototyped as follows:
int user_udprecv(struct knx_udpmsg *msgp, void *userp);
Parameter userp is an application pointer provided by you in your request to open the
channel on which this UDP datagram was received. It is a copy of the parameter found at
msgp->xudpm_user.
Parameter
msgp is a pointer to a KwikNet UDP message descriptor. Structure knx_udpmsg
is defined in KwikNet header file KN_API.H as follows:
struct knx_udpmsg {
struct in_addr xudpm_src; /* IP address of source */
struct in_addr xudpm_dest; /* IP address of destination */
int xudpm_fport; /* Foreign port (source) */
int xudpm_lport; /* Local port (destination) */
char *xudpm_datap; /* Pointer to UDP data */
int xudpm_length; /* Length of UDP data */
int xudpm_rsv1; /* Reserved for alignment */
void *xudpm_user; /* User parameter */
unsigned long xudpm_channel; /* UDP channel ID */
struct knx_lmnode xudpm_node; /* List node (for use by user) */
void *xudpm_handle; /* Reserved for KwikNet use */
};
The UDP message structure describes the received UDP datagram. Fields xudpm_src,
xudpm_dest, xudpm_fport, and xudpm_lport are extracted from the received packet and
presented to your application in an easy to use form. The source and destination IPv4
addresses are presented in net endian form in field s_addr of structure in_addr. The
foreign and local ports are provided as integers in host endian form.
The data within the UDP datagram is located at the memory address specified by field
xudpm_datap. The length of the data region is specified by field xudpm_length.
Your UDP callback function must return
0 if it accepts the UDP message descriptor. In
this case, once your application has finished processing the UDP datagram, it must call
KwikNet procedure kn_udpfree() to release the UDP message descriptor and free the
associated data storage for reuse by
KwikNet.
Your UDP callback function must return -1 if it cannot accept the message descriptor. In
this case, KwikNet will release the UDP message descriptor and free the associated data
storage. It is important to note that KwikNet will not send an ICMP destination
unreachable message to the originator of the rejected UDP datagram.