在 IPv4 客户端/服务器应用程序中添加对 IPv6 的支持 - sin6_flowinfo 和 sin6_scope_id 字段?

发布于 2024-12-17 17:21:29 字数 2230 浏览 1 评论 0原文

我致力于为多个应用程序实现 IPv6 支持,但我想知道这 2 个字段的用途。这里关于这个的问题很少,所以我不确定我是否正确。

  • 关于作用域 ID ( sin6_scope_id ) - 嗯,第一季度 , 第二季度 , 第三季度第四季度 让我了解了范围 ID,我想我明白了。因此,我必须再添加一个配置参数,以使作用域 ID 可配置。 (我决定在这里添加这个,以防有人对此感兴趣)。很快 - 范围 ID 是唯一确定哪个设备应该处理流量所必需的 - 因为可能有多个接口,具有相同的 IP,但具有不同的(接口?)ID。到目前为止,一切都很好。
  • 但是“流信息”(sin6_flowinfo)怎么样?
    • 它的用途是什么?我找不到任何有趣的事情。我阅读了 RFC 但它对我没有任何帮助。
    • sin6_flowinfo 是否有一些可能的值(例如 - 多个值,例如标志,它们表示某种含义),或者类似于 sin6_scope_id - 可能是任何值,具体取决于在我尝试连接的设备上?
    • 我是否应该担心它,或者我只是将其保留0(如Beej 网络编程指南是的,我尝试过,它有效,但我不确定它是否仅适用于这个案例(如果它取决于某些网络配置),或者如果设置为0,它总是有效?
    • 或者,也许我应该使其可配置,我的意思是 - 添加一个配置选项并让用户定义它的值?
    • google-ing“sin6_flowinfo”为我提供了结构定义和手册页,该字段没有任何用处。有什么有趣的来源吗? (可以理解……不是 RFC :D )

编辑:嗯,在@glglgl的回答和提示之后,sin6_flowinfo可能已经过时了,我发现了一些有趣的来源:RFC:IPv6 流标签规范 , IETF 草案:流标签作为传输-层随机数solaris 实用指南<强>维基百科
该字段并未过时(或者我找不到这样的来源,这证实了这一点),但它看起来像 0 因为值足够好。

I work on implementing IPv6 support for several applications, but I wondered what are these 2 fields for. There are so few questions about this here so I'm not sure I got it right.

  • About scope ID ( sin6_scope_id ) - well, Q1 , Q2 , Q3 and Q4 gave me idea about the scope ID and I think I get it. So, I'll have to add one more config parameter, to make the scope-id configurable. (I decided to add this here, in case that someone is interested in this). Shortly - scope ID is necessary to uniquely determine which is the device, that should handle the traffic - because there may be several interfaces, with the same IP, but with different (interface?) ID. So far, so good.
  • But how about the "flow information" ( sin6_flowinfo )
    • What is it for? I couldn't find anything interesting about that. I read the RFC but it didn't help me at all.
    • Are there some possible values for sin6_flowinfo (like - several values, like flags, which mean something), or it's like the sin6_scope_id - may be any value, depending on the device, I'm trying to connect to?
    • Should I worry about it at all, or I my just leave it 0 (as in Beej's Guide to Network Programming . And yes, I tried that, it works, but I'm not sure if it works only in this case (if it depends on some network configuration), or it will always work, if it's set to 0?
    • Or, maybe, I should make it configurable, I mean - add one more config option and let the user defines it's value?
    • google-ing "sin6_flowinfo" gives me struct definitions and man pages, nothing useful about this field. Any interesting source? (understandable one..not RFC :D )

EDIT: Well, after @glglgl 's answer and after the hint, that sin6_flowinfo may be obsolete, I found some interesting sources: RFC: IPv6 Flow Label Specification , IETF draft: Flow Label as Transport-Layer Nonce , Practical guide for solaris and wikipedia .
The field is not obsolete (or I couldn't find such source, that confirms this), but it looks like 0 as value is good enough.

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

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

发布评论

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

评论(1

白首有我共你 2024-12-24 17:21:29

最好的方法是使用 getaddrinfo()< /a>.

伪代码:

struct addrinfo *restrict hints = { .ai_family = AF_UNSPEC, .ai_socktype = SOCK_STREAM };
struct addrinfo * res, r;
if (0 == getaddrinfo("foo.bar.baz", "http", &hints, &res)) {
    for (r=res; r; r=r->ai_next) {
        sock = socket(r->ai_family, r->ai_socktype, r->ai_protocol);
        connect(sock, r->ai_addr, r->ai_addrlen);
        if error: continue
        break
    }
}
freeaddrinfo(res);

这将消除您对 sin6_scope_id 的担忧;通常为 0,除非您有像 fe80::1234:56ff:fe78:9abc%eth2 这样的链接本地地址。此 eth2 被转换为正确的作用域 ID。

sin6_flowinfo 已过时(据我所知),因此在生成的 struct addrinfoai_addr

The best way to go is to use getaddrinfo().

Pseudo code:

struct addrinfo *restrict hints = { .ai_family = AF_UNSPEC, .ai_socktype = SOCK_STREAM };
struct addrinfo * res, r;
if (0 == getaddrinfo("foo.bar.baz", "http", &hints, &res)) {
    for (r=res; r; r=r->ai_next) {
        sock = socket(r->ai_family, r->ai_socktype, r->ai_protocol);
        connect(sock, r->ai_addr, r->ai_addrlen);
        if error: continue
        break
    }
}
freeaddrinfo(res);

This will take the worry about sin6_scope_id from you; which is normally 0, except if you have link-local addresses like fe80::1234:56ff:fe78:9abc%eth2. This eth2 is converted to the correct scope ID.

sin6_flowinfo is obsolete (AFAIK) and thus set to 0 in your resulting struct addrinfo's ai_addr.

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