• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 832
  • Last Modified:

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!
0
F-J-K
Asked:
F-J-K
  • 3
  • 2
1 Solution
 
bbaoIT ConsultantCommented:
> 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
 
F-J-KAuthor Commented:
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
 
F-J-KAuthor Commented:
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
 
bbaoIT ConsultantCommented:
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
 
F-J-KAuthor Commented:
wooo, good. I will check it out. Many thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now