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

UDP (User Datagram Protocol) layer
[Networking]


Data Structures

struct  udp
 The UDP packet structure. More...


Typedefs

typedef udp udp_t
 The UDP packet structure.


Functions

void to_udp_layer (udp_t *packet, in_addr_t ip_src, in_addr_t ip_dst)
 Process an UDP packet received from the IP layer.
Parameters:
packet  The UDP packet.
ip_src  The IP source address (in network format).
ip_dst  The IP destination address (in network format).



Detailed Description

The UDP (User Datagram Protocol) layer.

Typedef Documentation

typedef struct udp udp_t
 

The UDP packet structure.


Function Documentation

void to_udp_layer udp_t   packet,
in_addr_t    ip_src,
in_addr_t    ip_dst
 

Process an UDP packet received from the IP layer.

Parameters:
packet  The UDP packet.
ip_src  The IP source address (in network format).
ip_dst  The IP destination address (in network format).

Definition at line 73 of file udp.c.

00074 {
00075         int i;
00076         bool chk;
00077         uint16_t len = ntohs(packet->udp_len) - sizeof(udp_t);
00078 
00079         // For UDP packets the checksum is optional; a value of 0 in    //
00080         // the checksum means the checksum is not used. A value of      //
00081         // 0xFFFF means the checksum is used and its value is 0.        //
00082         if ( packet->udp_chk != 0 )
00083         {
00084                 // The checksum is used                                 //
00085                 if ( packet->udp_chk == 0xFFFF )
00086                         packet->udp_chk = 0x0000;
00087 
00088                 // Calculate the checksum                               //
00089                 chk = udp_checksum(
00090                                 packet,
00091                                 ntohs(packet->udp_len),
00092                                 ip_src,
00093                                 ip_dst
00094                                 );
00095                 if ( chk )
00096                 {
00097                         kprintf("\n\rUDP checksum error! %04X", chk);
00098                         return;
00099                 }
00100         }
00101 
00102         // Dump the UDP packet                                          //
00103         kprintf(        "\n\rUDP packet received (%u bytes of data)"
00104                 "\n\rsender  = %u.%u.%u.%u:%u"
00105                 "\n\rreceiver= %u.%u.%u.%u:%u",
00106                 len,
00107 
00108                 IP_A(ntohl(ip_src)), IP_B(ntohl(ip_src)),
00109                 IP_C(ntohl(ip_src)), IP_D(ntohl(ip_src)),
00110                 ntohs(packet->udp_src),
00111 
00112                 IP_A(ntohl(ip_dst)), IP_B(ntohl(ip_dst)),
00113                 IP_C(ntohl(ip_dst)), IP_D(ntohl(ip_dst)),
00114                 ntohs(packet->udp_dst)
00115         );
00116 
00117         kprintf("\n\rData:\n\r");
00118         for(i=0; i<len; i++)
00119                 kputchar( (((uint8_t *)packet)+sizeof(udp_t))[i]  );
00120 }


Generated on Fri Feb 20 15:32:22 2004 for Minirighi by doxygen1.2.18