Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6839715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:45:08+00:00 2026-05-26T23:45:08+00:00

From Beej’s Guide to Network programming You can force it to use IPv4 or

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:45:09+00:00Added an answer on May 26, 2026 at 11:45 pm

    You have to differentiate between client and server applications.

    On the client, it is easy: just call getaddrinfo() and try each of the answers in sequence until you get a connection.

    On the server, things are a little bit harder:

    • There are systems whose IPv4 and v6 stacks are interconnected, there it is enough to just listen on IPv6. Maybe the socket has to be enabled to listen to both.
    • Other systems, like Windows XP, have separated stacks where this connection is not possible. There you would have to work with several sockets at once. Let me concentrate on those in the following.

    Even on servers, getaddrinfo() can be used. There you use the flag AI_PASSIVE in the hints. Then you get results. On these all you’ll have to listen, perhaps enabling the IPV6_V6ONLY flag.

    accept() should either be done non-blocking or with select() or poll() (not sure if the latter is possible).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As described in Beej's Guide to network Programming , select() monitors a set of
From what I can gather, there are three categories: Never use GET and use
This is from Beej's guide to C The drawback to using calloc() is that
From this article I see I can use msbuild to apply configuration transformations but
From organizer window i can copy document directory data. But in some apps i
From what I have gathered, one can have both editions of Delphi installed. My
From the calculation returns -30. How can I remove the minus, so it just
I was just going through the Networking Guide by Beej and am curious about
I'd like to do some network socket programming in C++ and have found the
From what I've ready you should be able to use the 'value' property of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.