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

  • Home
  • SEARCH
  • 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 6021729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:45:21+00:00 2026-05-23T03:45:21+00:00

In my program, I am trying to implement support for dual-stack operation (both IPv4

  • 0

In my program, I am trying to implement support for dual-stack operation (both IPv4 and IPv6 sockets).

In the case of IPv4, everything is working fine. But in the IPv6 case, accept() is returning a -1 value (an error).

Can anyone suggest the possible reasons, and how to fix it?

  • 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-23T03:45:22+00:00Added an answer on May 23, 2026 at 3:45 am

    When accept() returns -1, errno will be set to indicate what specific error occurred. Please call perror("accept") for an easy way to see what the error was, and update your question with the results.

    Also, please note that accept() must be called on a socket that has been:

    • Created using the socket() call. (you should pass PF_INET6 for the first argument of your socket to create an IPv6 protocol family socket)
    • Bound, using bind() using a struct sockaddr_in6 parameter as the 2nd parameter (with its sin6_family set to AF_INET6 for IPv6 to indicate you will be binding to an IPv6 address). Remember to zero out the sin6_zero field first. One strategy would be to zero the entire sockaddr structure, which would set the IPv6 address to IN6ADDR_ANY, which means you would just have to set the port and the address family.
    • Listening, by means of calling listen()

    If you are still having trouble, post the code you have so far.

    If I had to guess (since you haven’t posted any code), I think if it works with IPv4 and gets to the point where it can accept() a connection, but IPv6 connection accept() calls return -1, I think it’s likely that you aren’t passing accept() a large enough struct sockaddr for it to work.

    For example, the following code:

    printf("sizeof(struct sockaddr_in) = %ld\n", sizeof(struct sockaddr_in));
    printf("sizeof(struct sockaddr_in6) = %ld\n", sizeof(struct sockaddr_in6));
    

    Prints (on my system):

    sizeof(struct sockaddr_in) = 16
    sizeof(struct sockaddr_in6) = 28
    

    If you are only giving accept() enough room to write out an IPv4 address, it will fail when it accepts an IPv6 connection. Make sure you allocate either a struct sockaddr_in6 or a struct sockaddr_storage, and ensure the size argument is correct.

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

Sidebar

Related Questions

I'm trying to implement a server-client socket program in Java that can support multiple
I am trying to implement a simple chat program in linux using bsd sockets.
I'm trying to implement a TCP connection, everything works fine from the server's side
I'm trying to implement a program that involves an array of stacks. Each stack
I am trying to implement a image recognition program in C++ . I had
I'm trying to implement a WCF Service in my program , howevery I don't
Entry level programmer here trying to implement a COM interface. I am working on
I'm writing a program trying to implement a toy XML processor. Right now the
Am trying to implement a Java program which sends an Apple Push Notification to
I am trying to implement a program that sends the same messages to a

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.