#include <rtl.h>
U8 udp_get_socket (
U8 tos, /* Type Of Service. */
U8 opt, /* Option to calculate or verify the checksum. */
U16 (*listener)( /* Function to call when TCPnet receives a data packet. */
U8 socket, /* Socket handle of the local machine. */
U8* remip, /* Pointer to IP address of remote machine. */
U16 port, /* Port number of remote machine. */
U8* buf, /* Pointer to buffer containing the received data. */
U16 len )); /* Number of bytes in the received data packet. */
Description
The udp_get_socket function allocates a free UDP socket.
The function initializes all the state variables of the UDP socket to
the default state.
The argument tos specifies the IP Type Of Service. The most
common value for tos is 0. The argument opt specifies
the checksum option as shown in the table.
Option Value
Description
UDP_OPT_SEND_CS
Calculate the UDP checksum for the packets to be sent.
UDP_OPT_CHK_CS
Check the UDP checksum on the received packets.
You can also set opt to UDP_OPT_SEND_CS|UDP_OPT_CHK_CS to
enable both options. This is recommended for a more secure UDP
connection. You can also disable both options by setting opt
to 0 for fast system reaction time.
The argument listener is the event listening
function of the UDP socket. TCPnet calls the listener
function whenever a UDP data packet is received. The arguments to the
listener function are:
socket: UDP socket handle of the local machine.
remip: pointer to the IP address of the remote
machine.
port: UDP port number on the remote machine.
buf: pointer to buffer containing the received
data.
len: number of bytes in the received packet.
The udp_get_socket function is in the RL-TCPnet library.
The prototype is defined in rtl.h.
note
You must call the udp_get_socket function before any
other function calls to the UDP socket.
Ethernet packets are also protected by the ethernet CRC.
Packets can be modified when passing through routers, proxy
servers, gateways, etc.
You must define the listener function to use with
the UDP socket.
Return Value
The udp_get_socket function returns a handle to the
allocated UDP socket. If a socket cannot be allocated, the function
returns 0.
#include <rtl.h>
U8 udp_soc;
U16 udp_callback (U8 socket, U8 *remip, U16 remport, U8 *buf, U16 len) {
/* This function is called when UDP data is received */
/* Process received data from 'buf' */
..
return (0);
}
void main (void) {
init ();
/* Initialize the TcpNet */
init_TcpNet ();
udp_soc = udp_get_socket (0, UDP_OPT_SEND_CS | UDP_OPT_CHK_CS, udp_callback);
if (udp_soc != 0) {
/* Open UDP port 1000 for communication */
udp_open (udp_soc, 1000);
}
while (1);
/* Run main TcpNet 'thread' */
main_TcpNet ();
..
}
}
Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers of your data.