3      Copyright (C) Dean Camera, 2010. 
   5   dean [at] fourwalledcubicle [dot] com 
   6       www.fourwalledcubicle.com 
  10   Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com) 
  12   Permission to use, copy, modify, distribute, and sell this  
  13   software and its documentation for any purpose is hereby granted 
  14   without fee, provided that the above copyright notice appear in  
  15   all copies and that both that the copyright notice and this 
  16   permission notice and warranty disclaimer appear in supporting  
  17   documentation, and that the name of the author not be used in  
  18   advertising or publicity pertaining to distribution of the  
  19   software without specific, written prior permission. 
  21   The author disclaim all warranties with regard to this 
  22   software, including all implied warranties of merchantability 
  23   and fitness.  In no event shall the author be liable for any 
  24   special, indirect or consequential damages or any damages 
  25   whatsoever resulting from loss of use, data or profits, whether 
  26   in an action of contract, negligence or other tortious action, 
  27   arising out of or in connection with the use or performance of 
  33  *  User Datagram Protocol (UDP) packet handling routines. This protocol handles high throughput, low 
  34  *  reliability packets which are typically used to encapsulate streaming data. 
  37 #define  INCLUDE_FROM_UDP_C 
  40 /** Processes a UDP packet inside an Ethernet frame, and writes the appropriate response 
  41  *  to the output Ethernet frame if a sub-protocol handler has created a response packet. 
  43  *  \param[in] IPHeaderInStart     Pointer to the start of the incoming packet's IP header 
  44  *  \param[in] UDPHeaderInStart    Pointer to the start of the incoming packet's UDP header 
  45  *  \param[out] UDPHeaderOutStart  Pointer to the start of the outgoing packet's UDP header 
  47  *  \return The number of bytes written to the out Ethernet frame if any, NO_RESPONSE otherwise 
  49 int16_t UDP_ProcessUDPPacket(void* IPHeaderInStart
, void* UDPHeaderInStart
, void* UDPHeaderOutStart
) 
  51         UDP_Header_t
* UDPHeaderIN  
= (UDP_Header_t
*)UDPHeaderInStart
; 
  52         UDP_Header_t
* UDPHeaderOUT 
= (UDP_Header_t
*)UDPHeaderOutStart
; 
  54         int16_t RetSize 
= NO_RESPONSE
; 
  56         DecodeUDPHeader(UDPHeaderInStart
); 
  58         switch (SwapEndian_16(UDPHeaderIN
->DestinationPort
)) 
  60                 case UDP_PORT_DHCP_REQUEST
: 
  61                         RetSize 
= DHCP_ProcessDHCPPacket(IPHeaderInStart
, 
  62                                                          &((uint8_t*)UDPHeaderInStart
)[sizeof(UDP_Header_t
)], 
  63                                                      &((uint8_t*)UDPHeaderOutStart
)[sizeof(UDP_Header_t
)]); 
  67         /* Check to see if the protocol processing routine has filled out a response */ 
  70                 /* Fill out the response UDP packet header */ 
  71                 UDPHeaderOUT
->SourcePort      
= UDPHeaderIN
->DestinationPort
; 
  72                 UDPHeaderOUT
->DestinationPort 
= UDPHeaderIN
->SourcePort
; 
  73                 UDPHeaderOUT
->Checksum        
= 0; 
  74                 UDPHeaderOUT
->Length          
= SwapEndian_16(sizeof(UDP_Header_t
) + RetSize
); 
  76                 /* Return the size of the response so far */ 
  77                 return (sizeof(UDP_Header_t
) + RetSize
);