将 openvswitch 类型转换为小端

标签 c endianness openvswitch

在 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/

相关文章:

单击 DataTemplate - WP8 中的按钮

c - 在 printf 函数中使用 "%d"+ 常量

清除终端程序 Linux C/C++ 的输出

php - 如何在 PHP 中获取字节序类型?

python - 使用 pyparsing 从 ovs 转储流中提取数据

c - sprintf 中关于返回 '%' 字符的歧义

c++ - 如何确定 NifTi 文件的字节顺序?

memory - 字节序取决于处理器还是内存?

Kubernetes覆盖网络比较

sdn - Openflow交换机中同一个流有多个转发规则怎么办?