在 IPv4 客户端/服务器应用程序中添加对 IPv6 的支持 - sin6_flowinfo 和 sin6_scope_id 字段? [英] Adding support for IPv6 in IPv4 client/server apps - sin6_flowinfo and sin6_scope_id fields?

查看:13
本文介绍了在 IPv4 客户端/服务器应用程序中添加对 IPv6 的支持 - sin6_flowinfo 和 sin6_scope_id 字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

  • 关于范围 ID (sin6_scope_id) - 好吧,Q1 , Q2 , Q3Q4 让我了解了范围 ID,我想我明白了.因此,我必须再添加一个配置参数,以使 scope-id 可配置.(我决定在这里添加这个,以防有人对此感兴趣).很快 - 范围 ID 是唯一确定应该处理流量的设备所必需的 - 因为可能有多个接口,具有相同的 IP,但具有不同的(接口?)ID.到目前为止,一切顺利.
  • 但是流信息"呢?( sin6_flowinfo )
    • 它有什么用?我找不到任何有趣的东西.我阅读了 RFC,但它对我没有任何帮助.
    • sin6_flowinfo 是否有一些可能的值(比如 - 几个值,比如标志,这意味着什么),或者就像 sin6_scope_id - 可以是任何值,具体取决于在设备上,我正在尝试连接?
    • 我应该完全担心它,还是我就让它0(如 Beej 网络编程指南.是的,我试过了,它有效,但我不确定它是否只适用于这种情况(如果它取决于某些网络配置),或者如果它设置为 0,它将始终有效?
    • 或者,也许,我应该让它可配置,我的意思是 - 添加一个配置选项并让用户定义它的值?
    • google-ing sin6_flowinfo"给我结构定义和手册页,关于这个领域没有任何用处.有什么有趣的来源吗?(可以理解的……不是 RFC :D)
    • 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 )

      编辑:嗯,在@glglgl 的回答和提示之后,sin6_flowinfo 可能已过时,我发现了一些有趣的来源: RFC: IPv6 Flow Label Specification , IETF 草案:作为传输层 Nonce 的流标签 , solaris 实用指南wikipedia .
      该字段没有过时(或者我找不到这样的来源,证实了这一点),但它看起来像 0 因为值足够好.

      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.

      推荐答案

      最好的方法是使用 getaddrinfo().

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

      伪代码:

      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.

      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 已过时(AFAIK),因此在生成的 struct addrinfoai_addr.

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

      这篇关于在 IPv4 客户端/服务器应用程序中添加对 IPv6 的支持 - sin6_flowinfo 和 sin6_scope_id 字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆