2015-11-03 51 views
0

在打開的vSwitch 2.4.0實施,我們有以下幾點:轉換openvswitch類型爲小端

#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; 

我有以下變量:

ovs_16aligned_be32 srcIP; 
ovs_be16 srcPort ; 

我如何轉換srcIPxxx.yyy.zzz.tttsrcPort變成little-endian uint16_t

回答

0

好吧,我不知道什麼是openvswitch,但我認爲這應該工作:

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; 
} 
1

已有的功能:

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

這是在

#include <arpa/inet.h> 
原型

如果我正確理解你的問題,這些功能將做你想做的。