[SOLVED] Connecting socket using bogus address -- No problem! But why?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Connecting socket using bogus address -- No problem! But why?
I cannot understand why an attempt to connect to a bogus address using port 22 fails, yet if I change the port to 80 it succeeds. I would expect both cases to fail.
With port 80 in use, I successfully connect and see the printed message of "Success!". If I change the port to 22, then the assert(), when attempting to connect, is triggered.
Can anyone help explain this odd behavior?
Last edited by dwhitney67; 03-04-2013 at 04:55 PM.
But the assert around getaddrinfo() is not triggered? Maybe try printing the host info that is returned by getaddrinfo() then.
ntubski,
Thanks for the pointer.
I printed out the IP address and came up with an address of 199.101.28.20. Using my web browser, I found it to be http://search.dnsassist.verizon.net. This explains why using port 80 I was able to connect.
So apparently my system fails over to that IP address (of my ISP) when I supply any bogus server name and port 80. It would be nice if I could configure my system to avoid such a thing. Any ideas on how to do this?
Last edited by dwhitney67; 03-05-2013 at 04:58 AM.
I'd expect that's probably the default of most ISPs; the pkt goes as far as it can (sort of).
If you want a test addr, stick to localhost range 127.0.0.0/8 or possibly something in your normal lan addr range eg 192.168.0.0/16.
This RFC lists the 'special' ranges; https://tools.ietf.org/html/rfc3330
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.