从CMSG获取时间戳记可能为null吗?

发布于 2025-02-12 17:21:43 字数 497 浏览 0 评论 0 原文

我看这个代码 https://elixir.bootlin.com/linux/v4.6.7/source/Documentation/networking/timestamping/timestamping.c#L181

This code try to print the timestamp of packet using struct timespec *stamp =(struct timespec *)cmsg_data(cmsg);

如果是UDP数据包。 有什么办法 CMSG_DATA(CMSG)将返回null?

I looking at this code
https://elixir.bootlin.com/linux/v4.6.7/source/Documentation/networking/timestamping/timestamping.c#L181

This code try to print the timestamp of packet using struct timespec *stamp = (struct timespec *)CMSG_DATA(cmsg);

If this is UDP packet.
Is there any way that CMSG_DATA(cmsg) will return NULL?

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

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

发布评论

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

评论(1

ヅ她的身影、若隐若现 2025-02-19 17:21:43

如果您查看您看到

#define CMSG_DATA(cmsg) ((void *)((char *)(cmsg) + CMSG_ALIGN(sizeof(struct cmsghdr))))

这将偏移添加到 cmsg
除非您设法将 cmsg 馈入该宏,否则添加该偏移量后,该宏将评估为 null ,则结果永远无法 null

If you look at the definition of CMSG_DATA you see

#define CMSG_DATA(cmsg) ((void *)((char *)(cmsg) + CMSG_ALIGN(sizeof(struct cmsghdr))))

This adds an offset to cmsg.
Unless you manage to feed a cmsg into that macro that evaluates to NULL after adding that offset, the result can never be come NULL.

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