Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages   Examples  

UDP API functions


Detailed Description

These are the functions that applications need to use in order to send/receive data using UDP as well as to work with UDP sockets so as to achieve such a communication.

Functions

INT8 udp_getsocket (UINT8, INT32(*)(INT8, UINT8, UINT32, UINT16, UINT16, UINT16), UINT8)
 Allocate a free socket in UDP socket pool.

INT8 udp_releasesocket (INT8)
 Release a given socket.

INT8 udp_open (INT8, UINT16)
 Open a given UDP socket for communication.

INT8 udp_close (INT8)
 Close given socket for communication.

INT16 udp_send (INT8, UINT32, UINT16, UINT8 *, UINT16, UINT16)
 Send data to remote host using given UDP socket.


Function Documentation

INT8 udp_getsocket UINT8    tos,
INT32(*    listener)(INT8, UINT8, UINT32, UINT16, UINT16, UINT16),
UINT8    opts
 

Author:
Date:
26.07.2002
Parameters:
tos  type of service for socket. For now nothing implemented so 0.
listener  pointer to callback function that will be invoked by the TCP/IP stack to inform socket application of UDP_DATA_ARRIVAL event (for now only this, in future maybe others!)
opts  Options for checksum generation & inspection. Can be one of the following:
Returns:
  • -1 - Error
  • >=0 - Handle to reserved socket
Invoke this function to try to obtain a free socket from UDP socket pool. Function returns a handle to the free socket that is later used for accessing the allocated socket.
Examples:
udp_demo.c.

Definition at line 175 of file udp.c.

References ucb::locport, ucb::opts, ucb::state, ucb::tos, UDP_OPT_CHECK_CS, UDP_OPT_SEND_CS, UDP_STATE_CLOSED, and UDP_STATE_FREE.

Referenced by bootpc_init(), dhcpc_init(), dns_init(), and tftps_init().

INT8 udp_releasesocket INT8    sochandle
 

Author:
Date:
26.07.2002
Parameters:
sochandle  handle of UDP socket to be released
Returns:
  • -1 - error
  • >=0 - OK (returns handle to release socket)
This function releases UDP socket. This means that the socket entry is marked as free and all of the ucb fields are initialized to default values.

Definition at line 244 of file udp.c.

References ucb::locport, ucb::opts, ucb::state, ucb::tos, UDP_OPT_CHECK_CS, UDP_OPT_SEND_CS, and UDP_STATE_FREE.

INT8 udp_open INT8    sochandle,
UINT16    locport
 

Author:
Date:
26.07.2002
Parameters:
sochandle  handle to socket to be opened
locport  local port number
Returns:
  • -1 - Error
  • >=0 - Handle to opened socket
This function binds local port to given UDP socket and opens the socket (virtually) in order to enable communication.
Examples:
udp_demo.c.

Definition at line 291 of file udp.c.

References ucb::locport, ucb::state, udp_getfreeport(), and UDP_STATE_OPENED.

Referenced by bootpc_init(), dhcpc_init(), dns_init(), and tftps_init().

INT8 udp_close INT8    sochandle
 

Author:
Date:
26.07.2002
Parameters:
sochandle  handle to socket to be closed
Returns:
  • -1 - Error
  • >=0 - handle to closed socket
Closes a given socket in order to disable further communication over it.

Definition at line 340 of file udp.c.

References ucb::state, and UDP_STATE_CLOSED.

INT16 udp_send INT8    sochandle,
UINT32    remip,
UINT16    remport,
UINT8 *    buf,
UINT16    blen,
UINT16    dlen
 

Author:
Date:
26.07.2002
Parameters:
sochandle  handle to UDP socket to use
remip  remote IP address to which data should be sent
remport  remote port number to which data should be sent
buf  pointer to data buffer (start of user data)
blen  buffer length in bytes (without space reserved at the beginning of buffer for headers)
dlen  length of user data to be sent (in bytes)
Returns:
  • -1 - Error (general error, e.g. parameters)
  • -2 - ARP or lower layer not ready, try again later
  • -3 - Socket closed or invalid local port
  • >0 - OK (number represents number of bytes actually sent)
Warning:
  • buf parameter is a pointer to data to be sent in user buffer. But note that there MUST be sufficient free buffer space before that data for UDP header (of UDP_HLEN size).
Use this function to send data over an already opened UDP socket.
Examples:
udp_demo.c.

Definition at line 395 of file udp.c.

References ip_checksum(), ip_checksum_buf(), IP_UDP, ucb::locport, ucb::opts, process_ip_out(), ucb::state, ucb::tos, UDP_HLEN, UDP_OPT_SEND_CS, and UDP_STATE_OPENED.

Referenced by bootpc_run(), dhcpc_send_message(), and get_host_by_name().


Generated on Sun Aug 3 20:33:01 2003 for OpenTCP by doxygen1.2.18