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 636345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:30:18+00:00 2026-05-13T20:30:18+00:00

I need to add IPv6 support to an existing socket-based application which currently only

  • 0

I need to add IPv6 support to an existing socket-based application which currently only supports IPv4. To embrace the incoming era of IPv6, someone ordered me to add an IPv6 interface for the app and let the outside world to choose either the IPv4 interface or the IPv6 interface when trying to communicate with the app.

My question is: is it true that for the socket handling API level in Linux, there is no difference between handling an IPv4 based socket and IPv6 based socket?

Further more, is it possible to let a socket listen on two IP addresses with same port? If that is true, then to implement the requirement is a trivial work, I guess.

  • 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-13T20:30:18+00:00Added an answer on May 13, 2026 at 8:30 pm

    It is not possible to listen on 2 different IP addresses with 1 TCP socket, however if you listen on all interfaces using the in6addr_any address, that will include all IPv4 addresses as well (though I believe e.g. linux has a kernel option to disable that mapping).

    The (newer version of) socket API is quite transparent as to whether you’re using IPv4 or IPv6, but quite great care must be taken over how an IPv4 application is typically coded.

    e.g. this IPv4 code which accepts a connection and prints out the address of the remote host:

     struct sockaddr_in client_addr;
     socklen_t addr_len = sizeof(client_addr);
     client_data->fd = accept(server_fd,(struct sockaddr*)&client_addr,&addr_len);
     log_printf("New client from %s\n",inet_ntoa(client_addr.sin_addr.s_addr));
    

    Would have to be converted to the following, which handles both IPv4 and IPv6

     struct sockaddr_storage client_addr;
     char numeric_addr[INET6_ADDRSTRLEN];
     socklen_t addr_len = sizeof(client_addr);
     client_data->fd = accept(server_fd,(struct sockaddr*)&client_addr,&addr_len);
     if(client_addr.ss_family == AF_INET)
        log_printf("New client from %s\n",inet_ntop(client_addr.ss_family,((struct sockaddr_in*)&client_addr)->sin_addr.s_addr ,numeric_addr,sizeof numeric_addr));
     else if(client_addr.ss_family == AF_INET6)
        log_printf("New client from %s\n",inet_ntop(client_addr.ss_family,((struct sockaddr_in6*)&client_addr)->sin6_addr ,numeric_addr,sizeof numeric_addr));
    

    Though I believe you could do it even more elegantly and transparent with getaddrinfo()

    Here’s additional notes on IP layer independance:
    http://uw714doc.sco.com/en/SDK_netapi/sockC.PortIPv4appIPv6.html
    http://www.kame.net/newsletter/19980604/

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

Sidebar

Ask A Question

Stats

  • Questions 375k
  • Answers 375k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer A quick google for 8086 instructions timings size turned up… May 14, 2026 at 8:18 pm
  • Editorial Team
    Editorial Team added an answer First of all, you need to put the FindNode method… May 14, 2026 at 8:18 pm
  • Editorial Team
    Editorial Team added an answer Create a new class the inherits from WebClient that stores… May 14, 2026 at 8:18 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.