本文介绍了添加了IPv4客户端/服务器应用对IPv6的支持 - sin6_flowinfo和sin6_scope_id领域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我关于执行多个应用程序支持IPv6的工作,但我想知道是这些2场。大约有会这样几个问题在这里,所以我不知道我是正确的。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 ,Q3和Q4给我讲起范围ID的想法,我想我明白了。因此,我将不得不增加一个配置参数,使范围-ID配置。 (我决定在这里添加这个,万一有人很关心这个)。不久 - 作用域ID是必要的唯一地确定这是设备,应处理交通 - 因为可能有多个接口,使用相同的IP,但用不同的(界面?)的标识。到目前为止,一切都很好。又是如何的信息流( sin6_flowinfo )这是什么呢?我无法找到任何有趣的东西有关。我阅读 RFC ,但它并没有帮助我。 是否有一些可能的值sin6_flowinfo (如 - 一些值,比如标志,这意味着什么),或者它就像 sin6_scope_id - 可以是任意值,取决于设备上,我试图连接到我应该担心它在所有的,或我我就让它 0 (如的Beej's指南网络编程。而是的,我试过了,它的工作原理,但我不知道这是否只能在这种情况下,(如果它依赖于一些网络配置),否则它会一直工作,如果它被设置为 0 ?或者,也许,我应该使配置的,我的意思是 - 增加一个配置选项,让用户自定义其值? 谷歌 -ingsin6_flowinfo给我定义的结构和手册页,没有谈到这个领域非常有用。任何有趣的来源? (可以理解one..not 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的流标签规范 ,的IETF草案:流标签作为传输层杜撰 , 和的实用指南:// en.wikipedia.org/wiki/IPv6_packet> 维基百科 。结果现场没有过时(或者我找不到这样的来源,证实了这一点),但它看起来像 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().伪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);这将需要大约 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 是过时的(据我所知),因此设置为0您造成的 结构addrinfo中的的 ai_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领域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-05 15:57