?
Solved

Is IPv4 & IPv6 Completely Independent than Each Other? My PC has The Two Versions! C/C++ Winsock about listen()

Posted on 2008-11-08
5
Medium Priority
?
825 Views
Last Modified: 2013-11-13
My PC has two version of IP's. Here is what my ipconfig represents:

Wireless LAN adapter Wireless Network Connection:

   Connection-specific DNS Suffix  . : *****.com
   Link-local IPv6 Address . . . . . : ****::***:****:***:****%13
   IPv4 Address. . . . . . . . . . . : 192.168.0.101
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.0.1

I created a server that listens on 4432 port. My piece of code grabs the local ip address automatically & bind to the specified port 4432. After that, it waits for connections...

After executing the server, i go to netstat -an. I see the port 4443 is listening.

I do a port scan on 4443 to see if its actually listening or not. The answer is yes and no...

If i scan the port 4443 on this address 127.0.1.1 (IPv4), i get result as 4443 is blocked.
If i scan the port 4443 on this address  ****::***:****:***:**** (IPv6), i get a result as 4443 is open - which is correct ....

So my server is listening on 4443 for the IPv6, but for the IPv4.....Only clients that connects to the server by using server's IPv6/4443 will be able to communicate with the server. If a client trying to connect to the server by using servers' IPv4/4443, its connection will get refused (10061)....

When i did netstat -an i discovered some ports are listening for both IP versions, some are only listening for one IP version e.g.

Proto  Local Address          Foreign Address        State
TCP    0.0.0.0:135            0.0.0.0:0              LISTENING
TCP    0.0.0.0:445            0.0.0.0:0              LISTENING
TCP    0.0.0.0:1025           0.0.0.0:0              LISTENING
 TCP    [::]:135               [::]:0                 LISTENING
 TCP    [::]:445               [::]:0                 LISTENING
 TCP    [::]:1025              [::]:0                 LISTENING
TCP    [::]:4443              [::]:0                 LISTENING

Ok, ports 135, 445, and 1025 will respond to client who connects to it through IPv4 or IPv6.
4443 will only respond to client who connects to it through IPv6.

Questions:

1. How come IPv4 & IPv6 are not related? Both of them are the same, in the same machine! so an open  port is an open port regardless of the IP version, because the port is a port. 4443 its only number, its only one port...How come its blocked on IPv4 and open on IPv6? Machine address is a machine address, no matter on what version clients connect to me, client is connecting to the same place just by using different version of addresses, but its still connecting to the same machine which has same ports, same system, etc....Can you clarify to me please

2. How can i make my port 4443 listens for both IP versions?

I tried to explain everything above to make my question clearer. I'm looking forward to hearing from you!
0
Comment
Question by:F-J-K
  • 3
  • 2
5 Comments
 
LVL 37

Accepted Solution

by:
bbao earned 2000 total points
ID: 22916854
> 1. How come IPv4 & IPv6 are not related?

the two protocols are totally separated, as they use different stack and different addressing system. you may just simply think IPv6 as IPX, another different protocol, though the two protocols are bound to the same network adapter.

> Both of them are the same, in the same machine!

theoretically, not same, just similar.

> so an open port is an open port regardless of the IP version, because the port is a port.

IPv4 and IPv6 do not share their ports, so IPv4:123 and IPv6:123 are different port, though they have the same port number, because, as i explained above, the two ports belong to different protocol stack, one for each.

> 4443 its only number, its only one port...How come its blocked on IPv4 and open on IPv6? Machine address is a machine address, no matter on what version clients connect to me, client is connecting to the same place just by using different version of addresses, but its still connecting to the same machine which has same ports, same system, etc....Can you clarify to me please

as described above, it is by design.

2. How can i make my port 4443 listens for both IP versions?

by default, if the application using port 4443 does support both V4 and V6, it listens on the *two* 4443 ports at the same time, except a firewall or system setting blocks one port of them.

FYI - Comparison of IPv4 and IPv6
http://publib.boulder.ibm.com/infocenter/iseries/v5r4/topic/rzai2/rzai2compipv4ipv6.htm#rzai2compipv4ipv6__compports

hope it helps,
bbao
0
 
LVL 1

Author Closing Comment

by:F-J-K
ID: 31514728
Very clear & straight forward.

One thing, i will have to figure out how to make my application support both V4 & V6! ..... Thanks for explaining the logic
0
 
LVL 1

Author Comment

by:F-J-K
ID: 22918541
I figured it out. I had to change hints.ai_family = AF_UNSPEC; to hints.ai_family = AF_INET;
As AF_UNSPEC, picks the highest numbered family protocol which happens to be IPV6 with Windows. I don't know why in Windows Vista let my application binds the port with IPV6 only. On other hand, linux binds the port with both IP versions. Anyhow, since IPv4 is more common, i just forced the ai_family to be AF_INET - IPv4 ...

0
 
LVL 37

Expert Comment

by:bbao
ID: 22919091
you may check the protocol binding settings on Vista...

Change the order of network protocol bindings (for Vista)
http://windowshelp.microsoft.com/Windows/en-us/help/89554521-7ce7-4d70-aa29-88b8316d50761033.mspx

hope it helps,
bbao
0
 
LVL 1

Author Comment

by:F-J-K
ID: 22919102
wooo, good. I will check it out. Many thanks
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is the first one of a series of articles I’ll be writing to address technical issues that are always referred to as network problems. The network boundaries have changed, therefore having an understanding of how each piece in the network  puzzl…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses
Course of the Month17 days, 4 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question