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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:31:34+00:00 2026-06-09T03:31:34+00:00

I have a UDP Server which has to serve clients on both IPV4 and

  • 0

I have a UDP Server which has to serve clients on both IPV4 and IPV6 address. I have created a single IPV6 socket to serve both the IPV4 and IPV6 clients.

The server stores IPAddress of the client on the very first communication. If it is a IPV4 client it stores as IPV4 Address and if it is a IPV6 client the server stores as IPV6 address. For all future communication it checks the storage whether this client is already known(stored) and then acts accordingly. For comparing the client address with the stored address I do a memcmp based on the family type (AF_INET and AF_INET6).

While communicating with IPV6 client the system is working normally but while communicating with IPV4 client the system behaves as if it never knew the client. While debugging I found that due to IPV6 the Socket Type the IPAddresss of the IPV4 client is received as IPV6 mapped IPV4 Address with family set to IPV6. To Solve this I need to compare between the IPV4 Stored address and the IPV6 mapped address. For this I am using sin_addr.s_addr of IPV4 structure and sin6_addr.in6_u.u6_addr32 of IPV6 structure. Please find the code snippet below.

ipv6_clientdata = (const struct sockaddr_in6 *)&sockStor;
ipv4_storeddata = (const struct sockaddr_in *)&(_stData[index].clientaddr);
if( (ipv6_clientdata->sin6_port == ipv4_storeddata->sin_port) && 
    (ipv6_clientdata->sin6_addr.in6_u.u6_addr32[3] == ipv4_storeddata->sin_addr.s_addr) 
  )
{
    addrfound = true;
}

I would like to know whether this method is the proper solution for comparing IPV6 Mapped IPV4 address with IPV4 address or is there any other better way.

  • 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-06-09T03:31:36+00:00Added an answer on June 9, 2026 at 3:31 am

    As Joachim Pileborg reasoned, you don’t need to care about this when the IPv4 address comes from an earlier packet received on the same socket because you will be comparing one mapped IPv4 address to another. It is only in the case that the IPv4 address was obtained from an external source that you have to care.

    As João Augusto pointed out, you neglected to check that the IPv6 address indeed is an IPv4 mapped address before comparing the last 32 bits. There is a macro IN6_IS_ADDR_V4MAPPED that will help you do this:

    if (
        IN6_IS_ADDR_V4MAPPED(&(ipv6_clientdata->sin6_addr)) &&
        (ipv6_clientdata->sin6_port == ipv4_storeddata->sin_port) &&
        (ipv6_clientdata->sin6_addr.in6_u.u6_addr32[3] == ipv4_storeddata->sin_addr.s_addr)
    ) {
        addrfound = true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a java program which sends a udp packet to a server when
I have an asynchronous UDP server class with a socket bound on IPAddress.Any, and
I have client code which gets a response from the server using UDP and
I have a client-server application, which intercommunicate via WCF. They also both use Castle
I have created an echo server under UDP, and am working on a client
I have a simple UDP client server written in C++ on Ubuntu 9.10 where
I have been investigating about creating a UDP server, at first i though i
I have a written a very simple UDP Server using Netty - it quite
I have a problem with a Sender and a Server UDP. The SenderUDP sends
I have a client and a server communicating with datagrams (UDP) in C. The

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.