UDPOpenEx Function

Microchip TCP/IP Stack

Microchip TCP/IP Stack Help
UDPOpenEx Function
C
UDP_SOCKET UDPOpenEx(
    DWORD remoteHost, 
    BYTE remoteHostType, 
    UDP_PORT localPort, 
    UDP_PORT remotePort
);
Description

Provides a unified method for opening UDP sockets. This function can open both client and server sockets. For client sockets, it can accept a host name string to query in DNS, an IP address as a string, an IP address in binary form, or a previously resolved NODE_INFO structure containing the remote IP address and associated MAC address. When a host name or IP address only is provided, UDP module will internally perform the necessary DNSResolve and/or ARP resolution steps before reporting that the UDP socket is connected (via a call to UDPISOpen returning TRUE). Server sockets ignore this destination parameter and listen only on the indicated port. Sockets are statically allocated on boot, but can be claimed with this function and freed using UDPClose .

Preconditions

UDPInit should be called.

Parameters
Parameters 
Description 
remoteHost 
Pointer to remote node info (MAC and IP address) for this connection. If this is a server socket (receives the first packet) or the destination is the broadcast address, then this parameter should be NULL. For client sockets only. Provide a pointer to a null-terminated string of the remote host name (ex:"www.microchip.com" or "192.168.1.123"), a literal destination IP address (ex: 0x7B01A8C0 or an IP_ADDR data type), or a pointer to a NODE_INFO structure with the remote IP address and remote node or gateway MAC address specified, If a string is provided.
 
remoteHostType 
Any one of the following flags to identify the meaning of the remoteHost parameter: 
  • UDP_OPEN_SERVER = Open a server socket and ignore the remoteHost parameter. (e.g. - SNMP agent, DHCP server, Announce)
  • UDP_OPEN_IP_ADDRESS = Open a client socket and connect it to a remote IP address. Ex: 0x7B01A8C0 for 192.168.1.123 (DWORD type). Note that the byte ordering is big endian.
  • UDP_OPEN_NODE_INFO = Open a client socket and connect it to a remote IP and MAC addresses pair stored in a NODE_INFO structure.
  • UDP_OPEN_RAM_HOST = Open a client socket and connect it to a remote host who's name is stored as a null terminated string in a RAM array. Ex:"www.microchip.com" or "192.168.0.123"
  • UDP_OPEN_ROM_HOST = Open a client socket and connect it to a remote host who's name is stored as a null terminated string in a literal string or ROM array. Ex: "www.microchip.com" or "192.168.0.123"


 

localPort 
UDP port number to listen on. If 0, stack will dynamically assign a unique port number to use.
 
remotePort 
For client sockets, the remote port number. 
Return Values
Return Values 
Description 
Success 
A UDP socket handle that can be used for subsequent UDP API calls. 
Failure 
INVALID_UDP_SOCKET. This function fails when no more UDP socket handles are available. Increase MAX_UDP_SOCKETS to make more sockets available. 
Remarks

When finished using the UDP socket handle, call the UDPClose() function to free the socket and delete the handle.

Microchip TCP/IP Stack 5.42.08 - June 15, 2013
Copyright © 2012 Microchip Technology, Inc.  All rights reserved.