What would be the disadvantages/risks of using AF_UNSPEC?

Posted by Kiril Kirov on Stack Overflow See other posts from Stack Overflow or by Kiril Kirov
Published on 2011-11-16T09:49:30Z Indexed on 2011/11/16 9:50 UTC
Read the original article Hit count: 341

Filed under:
|
|
|
|

From Beej's Guide to Network programming

You can force it to use IPv4 or IPv6 in the ai_family field, or leave it as AF_UNSPEC to use whatever. This is cool because your code can be IP version-agnostic.

As the title says - what would be the disadvantages (or risks, if any) of always using AF_UNSPEC, instead of specifying IPv4 or IPv6?

Or it's only for one reason - if the version is specified, this will guarantee that this and only this version is supported?


A little background - I think about adding support for IPv6 in client-server (C++) applications and both versions should be supported. So I wondered if it's fine to use AF_UNSPEC or it's better to "recognize" the address from the string and use AF_INET6 or AF_INET, depending on the address.

© Stack Overflow or respective owner

Related posts about c++

Related posts about c