Link to home
Start Free TrialLog in
Avatar of F-J-K
F-J-KFlag for Canada

asked on

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

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!
ASKER CERTIFIED SOLUTION
Avatar of bbao
bbao
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of F-J-K

ASKER

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
Avatar of F-J-K

ASKER

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 ...

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
Avatar of F-J-K

ASKER

wooo, good. I will check it out. Many thanks