From Embedded Xinu
Revision as of 18:31, 10 June 2011 by Jcowdy (talk | contribs)
Jump to navigation Jump to search


XINU implements UDP as per RFC 768

Sending data over UDP

Step 1: Allocate a new UDP device.

Use udpAlloc to get a device number for a udp device. If allocation fails, the device number returned will be SYSERR.
dev = tcpAlloc())

Step 2: Get the local ip address

Use netLookup to find our local ip address.
If interface is NULL, then we don't have a valid network interface.

This usually happens when a user forgets to run the netup command.

interface = netLookup((ethertab[0].dev)->num);
localhost = &(interface->ip);

Step3: Open the UDP device

To open the device simply call open( ) with the following arguments:
  1. The UDP device number
  2. Our local ip address
  3. The destination's ip address
  4. The local port to use
  5. The remote port to connect to
open(dev, localIP, dstIP, localPort, remotePort)

Again if open fails, SYSERR is returned.

Step 4: Send the packet

To actually send the data, use write( ) with the device, buffer, and length arguments.
The actual data you want to send will be written to the buffer. The length arg is the length of the buffer.
 write(dev, buf, MSG_MAX_LEN)

As usual, write returns SYSERR if it fails.

Step 5: Close the connection

Once the device is finish being used, be responsible and call close to return the device.