typedef struct { CTL_NET_PORT_t this_port; CTL_NET_PORT_t other_port; CTL_NET_IPv4_ADDR_t other_ip_addr; void *metadata; } CTL_UDP_INFO_t;
pointer to an instance of CTL_UDP_INFO_t is passed into user code during a UDP receive callback and out of user code when calling ctl_udp_sendto.
Note the use of ‘this’ and ‘other’ semantics rather than ‘src’ and ‘dst’.
In a UDP server, the same CTL_UDP_INFO_t pointer received in the CTL_UDP_RECV_FN_t may be passed unmodified to ctl_udp_sendto as in the following example: The simple semantic change of using "this" and "other" avoids having to do a parameter swap in the callback.
void myUdpReceiveFn(unsigned long *rcvData, unsigned rcvByteCount, const CTL_UDP_INFO_t *info) { // \em{process the rcvData...} // \em{and then call ctl_udp_sendto} ctl_udp_sendto(sendData, sendByteCount, info, 0); }
You can use the metaData member to store endpoint information for any application-specific data set by the MAC-layer driver.
The metaData member is intended to be used by IEEE 1588 (Precision Time Protocol)-compliant MAC layers to provide a packet timestamp (or at least a pointer to a packet timestamp), but the field may be used for any information that needs to be transmitted from the MAC layer to the application layer as part of a UDP datagram.