Difference between revisions of "UDP"

From Embedded Xinu
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
== About ==
+
== Resources ==
 
XINU implements UDP as per RFC 768
 
XINU implements UDP as per RFC 768
  
== Sending data over UDP ==
 
  
'''Step 1: Allocate a new UDP device.'''
+
== Debugging ==
:Use udpAlloc to get a device number for a udp device. If allocation fails, the device number returned will be SYSERR.
+
To enable UDP debugging, uncomment the following line in include/udp.h
  dev = tcpAlloc())
+
  //#define TRACE_UDP    TTY1
  
'''Step 2: Get the local ip address'''
+
In order to see the trace results you open another console to the second serial port using the router name followed by the number 2.
:Use netLookup to find our local ip address.
+
  mips-console router2
:If interface is NULL, then we don't have a valid network interface.
+
Alternatively TTY1 can be changed to TTY0 resulting in the trace printing on the main console.
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:
 
 
 
#The UDP device number
 
#Our local ip address
 
#The destination's ip address
 
#The local port to use
 
#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.
 
close(dev);
 

Latest revision as of 18:45, 17 June 2011

Resources

XINU implements UDP as per RFC 768


Debugging

To enable UDP debugging, uncomment the following line in include/udp.h

//#define TRACE_UDP     TTY1

In order to see the trace results you open another console to the second serial port using the router name followed by the number 2.

mips-console router2

Alternatively TTY1 can be changed to TTY0 resulting in the trace printing on the main console.