0

In Open vSwitch 2.4.0 implementation, we do have the following:

#ifdef __CHECKER__
#define OVS_BITWISE __attribute__((bitwise))
#define OVS_FORCE __attribute__((force))
#else
#define OVS_BITWISE
#define OVS_FORCE
#endif

/* The ovs_be<N> types indicate that an object is in big-endian, not
 * native-endian, byte order.  They are otherwise equivalent to uint<N>_t. */

typedef uint16_t OVS_BITWISE ovs_be16;
typedef struct {
    ovs_be16 hi, lo;
} ovs_16aligned_be32;

I have the following variables:

ovs_16aligned_be32 srcIP;
ovs_be16 srcPort ;

How can I convert srcIP into a xxx.yyy.zzz.ttt and the srcPort into a little-endian uint16_t ?

Wheatley
  • 153
  • 1
  • 12

2 Answers2

1

there are already the functions:

htonl()
htons()
ntohl()
ntohs()

Which are prototyped in

#include <arpa/inet.h>

If I understand your question correctly, these functions will do what you want.

user3629249
  • 16,402
  • 1
  • 16
  • 17
0

Ok, I do not know what is openvswitch but I think this should work:

ovs_16aligned_be32 ovs_16aligned_be32_to_littleEndian(ovs_16aligned_be32 a) {
    ovs_16aligned_be32 b.high = ovs_be16_toLittleEndian(a.low);
    b.low = ovs_be16_toLittleEndian(a.high);
    return b;
}

ovs_be16 ovs_be16_toLittleEndian(ovs_be16 srcPort a) {
   ovs_be16 srcPort b = (a >> 8) & 0x00ff;
   b |= a << 8;

   return b;
}