18b52a31eSHanoh Haim/*
28b52a31eSHanoh HaimCopyright (c) 2015-2015 Cisco Systems, Inc.
38b52a31eSHanoh Haim
48b52a31eSHanoh HaimLicensed under the Apache License, Version 2.0 (the "License");
58b52a31eSHanoh Haimyou may not use this file except in compliance with the License.
68b52a31eSHanoh HaimYou may obtain a copy of the License at
78b52a31eSHanoh Haim
88b52a31eSHanoh Haim    http://www.apache.org/licenses/LICENSE-2.0
98b52a31eSHanoh Haim
108b52a31eSHanoh HaimUnless required by applicable law or agreed to in writing, software
118b52a31eSHanoh Haimdistributed under the License is distributed on an "AS IS" BASIS,
128b52a31eSHanoh HaimWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
138b52a31eSHanoh HaimSee the License for the specific language governing permissions and
148b52a31eSHanoh Haimlimitations under the License.
158b52a31eSHanoh Haim*/
168b52a31eSHanoh Haim
178b52a31eSHanoh Haim#ifndef _UDP_HEADER_H_
188b52a31eSHanoh Haim#define _UDP_HEADER_H_
198b52a31eSHanoh Haim
208b52a31eSHanoh Haim#include "PacketHeaderBase.h"
218b52a31eSHanoh Haim#include "IPHeader.h"
228b52a31eSHanoh Haim
234f91be3fSHanoh Haim#define UDP_HEADER_LEN  8
244f91be3fSHanoh Haim
258b52a31eSHanoh Haimclass UDPHeader
268b52a31eSHanoh Haim{
278b52a31eSHanoh Haim
288b52a31eSHanoh Haimpublic:
298b52a31eSHanoh Haim    UDPHeader()
308b52a31eSHanoh Haim	{
318b52a31eSHanoh Haim		setDestPort(0xDEAD);
328b52a31eSHanoh Haim		setSourcePort(0xBEEF);
338b52a31eSHanoh Haim		setChecksum(0);
348b52a31eSHanoh Haim		setLength(0);
358b52a31eSHanoh Haim	}
368b52a31eSHanoh Haim
378b52a31eSHanoh Haim    UDPHeader(uint16_t argSourcePort,
388b52a31eSHanoh Haim              uint16_t argDestinationPort)
398b52a31eSHanoh Haim	{
408b52a31eSHanoh Haim		setDestPort(argDestinationPort);
418b52a31eSHanoh Haim		setSourcePort(argSourcePort);
428b52a31eSHanoh Haim	}
438b52a31eSHanoh Haim
448b52a31eSHanoh Haim
458b52a31eSHanoh Haim    inline  void    setSourcePort(uint16_t data);
468b52a31eSHanoh Haim    inline  uint16_t  getSourcePort();
478b52a31eSHanoh Haim
488b52a31eSHanoh Haim    inline  void    setDestPort(uint16_t data);
498b52a31eSHanoh Haim    inline  uint16_t  getDestPort();
508b52a31eSHanoh Haim
518b52a31eSHanoh Haim    inline  void    setLength(uint16_t data);
528b52a31eSHanoh Haim    inline  uint16_t  getLength();
538b52a31eSHanoh Haim
548b52a31eSHanoh Haim    inline  void    setChecksum(uint16_t data);
558b52a31eSHanoh Haim    inline  uint16_t  getChecksum();
568b52a31eSHanoh Haim
578b52a31eSHanoh Haim	inline void     updateCheckSum(IPHeader  *ipHeader);
588b52a31eSHanoh Haim    inline bool 	isCheckSumOk(IPHeader  *ipHeader);
598b52a31eSHanoh Haim    inline uint16_t   calcCheckSum(IPHeader  *ipHeader);
608b52a31eSHanoh Haim
614f91be3fSHanoh Haim    inline void    setChecksumRaw     (uint16_t data){
624f91be3fSHanoh Haim        myChecksum = data;
634f91be3fSHanoh Haim    }
644f91be3fSHanoh Haim
654f91be3fSHanoh Haim
668b52a31eSHanoh Haim	inline  void	swapSrcDest();
678b52a31eSHanoh Haim
688b52a31eSHanoh Haim////////////////////////////////////////////////////////////////////////////////////////
698b52a31eSHanoh Haim// Common Header Interface
708b52a31eSHanoh Haim////////////////////////////////////////////////////////////////////////////////////////
718b52a31eSHanoh Haim
728b52a31eSHanoh Haimpublic:
738b52a31eSHanoh Haim    inline	uint8_t*  getPointer          (){return (uint8_t*)this;}
748b52a31eSHanoh Haim    inline	uint32_t  getSize             (){return 8;}
758b52a31eSHanoh Haim
768b52a31eSHanoh Haim    inline	uint16_t  getNextProtocol     (){return getDestPort();};
778b52a31eSHanoh Haim    inline	void    setNextProtocol     (uint16_t argNextProtcool){setDestPort(argNextProtcool);};
788b52a31eSHanoh Haim
798b52a31eSHanoh Haim    void    dump                (FILE*  fd);
808b52a31eSHanoh Haim
818b52a31eSHanoh Haim
828b52a31eSHanoh Haimprivate:
838b52a31eSHanoh Haim    uint16_t  mySourcePort;
848b52a31eSHanoh Haim    uint16_t  myDestinationPort;
858b52a31eSHanoh Haim    uint16_t  myLength;
868b52a31eSHanoh Haim    uint16_t  myChecksum;
878b52a31eSHanoh Haim};
888b52a31eSHanoh Haim
898b52a31eSHanoh Haim
908b52a31eSHanoh Haim#include "UdpHeader.inl"
918b52a31eSHanoh Haim
928b52a31eSHanoh Haim#endif
938b52a31eSHanoh Haim