/*
 * Licensed to Open Source Radio Access Network(OS-RAN) Alliance and OAI
 * Software Alliance under one or more contributor license agreements. The
 * initial OpenXG series projects are derided from OAI projects, the files from
 * OAI projects are all in compliance with OAI Public License, Version 1.1.
 * codes and files developed from OpenXG projects and from OS-RAN Alliance
 * are all under OS-RAN licenses; you may not use this file except in compliance
 * with the license.  You may get a copy of the license at:
 *	http://www.openxg.org.cn/?falu_69.html
 * For more information about OpenXG, please contact:
 * contact@openxg.org.cn
 */

/*! \file conversions.hpp
  \brief
  \author Sebastien ROUX, Lionel Gauthier
  \company Eurecom
  \email: lionel.gauthier@eurecom.fr
*/

#ifndef FILE_CONVERSIONS_HPP_SEEN
#define FILE_CONVERSIONS_HPP_SEEN
#include <netinet/in.h>
#include <stdint.h>

#include <string>

/* Used to format an uint32_t containing an ipv4 address */
#define IN_ADDR_FMT "%u.%u.%u.%u"
#define PRI_IN_ADDR(aDDRESS)                            \
  (uint8_t)((aDDRESS.s_addr) & 0x000000ff),             \
      (uint8_t)(((aDDRESS.s_addr) & 0x0000ff00) >> 8),  \
      (uint8_t)(((aDDRESS.s_addr) & 0x00ff0000) >> 16), \
      (uint8_t)(((aDDRESS.s_addr) & 0xff000000) >> 24)

#define IPV4_ADDR_DISPLAY_8(aDDRESS) \
  (aDDRESS)[0], (aDDRESS)[1], (aDDRESS)[2], (aDDRESS)[3]

class conv {
 public:
  static void hexa_to_ascii(uint8_t *from, char *to, size_t length);
  static int ascii_to_hex(uint8_t *dst, const char *h);
  static struct in_addr fromString(const std::string addr4);
  static std::string toString(const struct in_addr &inaddr);
  static std::string toString(const struct in6_addr &in6addr);
  static std::string mccToString(const uint8_t digit1, const uint8_t digit2,
                                 const uint8_t digit3);
  static std::string mncToString(const uint8_t digit1, const uint8_t digit2,
                                 const uint8_t digit3);
  static std::string uint8_to_hex_string(const uint8_t *v, const size_t s);
  static void hex_str_to_uint8(const char *string, uint8_t *des);
};
#endif /* FILE_CONVERSIONS_HPP_SEEN */
