Hack Forums
bind() binds server socket with local IPv6/Port....How Can I Make It bind() on IPv4? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Coders Lounge (https://hackforums.net/forumdisplay.php?fid=5)
+---- Thread: bind() binds server socket with local IPv6/Port....How Can I Make It bind() on IPv4? (/showthread.php?tid=34252)



bind() binds server socket with local IPv6/Port....How Can I Make It bind() on IPv4? - ʇsıʎqqoɥ - Nov 8, 2008

I got a weird problem. I coded a server. Works good, but it only binds the port to the local IPv6 .... So when the client enters the target external IP (Usually IPv4)/port. Client will be able to connect to the listening port that is through IPv4 only...

For example, i made my server binds on port 4443 on the local machine...

I check netstat -an, i get

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

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. So for a client to connect on the server port 4443, it (client) must enter IPv6 for the target so 4443 can respond. Otherwise, connection will fail as you see that 4443 is not included among IPv4! I hope you get my point.....Weird problem! ..... On linux, everything works fine, but on Vista things did not go as it should be....

I hope somebody can provide some help...

Hey, if you don't understand what i have written, lemme know. I will try to re-explain it...


- MiNd-FuCk - Nov 9, 2008

(Nov 8, 2008 11:33 PM)f.ben.isaac Wrote:  I got a weird problem. I coded a server. Works good, but it only binds the port to the local IPv6 .... So when the client enters the target external IP (Usually IPv4)/port. Client will be able to connect to the listening port that is through IPv4 only...

For example, i made my server binds on port 4443 on the local machine...

I check netstat -an, i get

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

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. So for a client to connect on the server port 4443, it (client) must enter IPv6 for the target so 4443 can respond. Otherwise, connection will fail as you see that 4443 is not included among IPv4! I hope you get my point.....Weird problem! ..... On linux, everything works fine, but on Vista things did not go as it should be....

I hope somebody can provide some help...

oh come now, thats just gibberish! have some scones :)

*EDIT actuly i get it now... the monkey goes in the blender!


- ʇsıʎqqoɥ - Nov 9, 2008

the question could be dummy, but am i'm too exhausted, so am blank now. Anyhow, i will be looking at it tomorrow...But, if you got the answer and you think its simple, post it, dont just say blah blah & leave...


- ʇsıʎqqoɥ - Nov 9, 2008

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