主机顺序字节中的 ether_addr_octet

发布于 2024-10-18 04:11:13 字数 193 浏览 7 评论 0原文

我想将 struct ether_addr (ether_addr_octet) 转换为整数主机字节顺序表示。有什么想法吗?

ntohl(eth->ether_addr_octet)

不起作用,因为 ether_addr_octet 是一个字符数组。

问候

I would like convert struct ether_addr (ether_addr_octet) to integer host byte order representation. Any ideas?

ntohl(eth->ether_addr_octet)

not working, because ether_addr_octet is a char array.

Regards

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

巴黎盛开的樱花 2024-10-25 04:11:13

我不确定这的语义是什么。
以太币为 48 位,最大 ntoh* 为 32 位值。
我想你可以创建一个 64 位值解析 char 数组,并调用 ntohl() 两次......

I'm not sure what the semantics of this are going to be.
The ether is 48bit, and the largest ntoh* is for 32bit values.
I suppose you can create a 64bit value parsing the char array, and calling ntohl() twice...

他不在意 2024-10-25 04:11:13

你可以将它转换为 char 然后你可以做你想做的其他事情......

char *ether_ntoa_my(const struct ether_addr *addr){
    static char buf[18];
    sprintf(buf, "%02x%02x:%02x%02x:%02x%02x",
            addr->ether_addr_octet[0], addr->ether_addr_octet[1],
            addr->ether_addr_octet[2], addr->ether_addr_octet[3],
            addr->ether_addr_octet[4], addr->ether_addr_octet[5]);
    return buf;
}

我希望它有帮助

You can convert it to char and then you can do something else you want...

char *ether_ntoa_my(const struct ether_addr *addr){
    static char buf[18];
    sprintf(buf, "%02x%02x:%02x%02x:%02x%02x",
            addr->ether_addr_octet[0], addr->ether_addr_octet[1],
            addr->ether_addr_octet[2], addr->ether_addr_octet[3],
            addr->ether_addr_octet[4], addr->ether_addr_octet[5]);
    return buf;
}

I hope it helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文