#ifndef UDP_LAYER_H
#define UDP_LAYER_H

#include <arpa/inet.h>
#if !defined(LINUX)
#include <netdb.h>
#include <netinet/udp.h>
struct iphdr {
    #if __BYTE_ORDER == __LITTLE_ENDIAN
        u_int8_t    ihl:4,
                version:4;
    #elif __BYTE_ORDER == __BIG_ENDIAN
        u_int8_t    version:4,
                ihl:4;
    #else
        #error  "Please fix <asm/byteorder.h>"
    #endif
          u_int8_t   tos;
          u_int16_t  tot_len;
          u_int16_t  id;
          u_int16_t  frag_off;
          u_int8_t   ttl;
          u_int8_t   protocol;
          u_int16_t  check;
          struct  in_addr  saddr;
          struct  in_addr  daddr;
          //The options start here.
};
#else // LINUX
#include <linux/ip.h>
#include <linux/udp.h>
#endif // LINUX

#include "TLayer.hh"
#include "Params.hh"

class UdpLayer : public Layer {
  Params _params;
  struct iphdr* _iphdr;
  struct udphdr* _udphdr;
  struct sockaddr_in _saddr;
  struct sockaddr_in _daddr;

  unsigned short inet_check_sum(const void *buf, size_t hdr_len, const unsigned short p_initial_sum = 0);

public:
  UdpLayer(const std::string & p_type, const std::string & param);
  virtual ~UdpLayer() {}

  virtual void sendData(OCTETSTRING& data, Params& params);
  virtual void receiveData(OCTETSTRING& data, Params& info);
};

#endif
