在 Open vSwitch 2.4.0 实现中,我们确实有以下内容:
#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 ;
如何将 srcIP
转换为 xxx.yyy.zzz.ttt
并将 srcPort
转换为小尾数 uint16_t
?
最佳答案
已有的功能:
htonl()
htons()
ntohl()
ntohs()
原型(prototype)是在
#include <arpa/inet.h>
如果我正确理解你的问题,这些函数将执行你想要的操作。
关于将 openvswitch 类型转换为小端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33490767/