Difference between revisions of "UDP"

From Embedded Xinu
Jump to navigation Jump to search
(Created page with '== 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 ...')
 
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Sending data over UDP ==
+
== Resources ==
 +
XINU implements UDP as per RFC 768
  
'''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'''
+
== Debugging ==
:Use netLookup to find our local ip address.
+
To enable UDP debugging, uncomment the following line in include/udp.h
:If interface is NULL, then we don't have a valid network interface.  
+
//#define TRACE_UDP    TTY1
This usually happens when a user forgets to run the netup command.
 
  
interface = netLookup((ethertab[0].dev)->num);
+
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.
localhost = &(interface->ip);
+
mips-console router2
 
+
Alternatively TTY1 can be changed to TTY0 resulting in the trace printing on the main console.
'''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.