PDA

View Full Version : linux boots slow after changing /etc/hosts


philipaby
8th September 2005, 02:31 PM
Hi everyone,
I am a realy newbie into the Linux (actually Unix) environment. I was writing a simple socket program in C where there server program was running on the same machine as the client program. My ip was 192.168.1.103 and when my server socket tried to bind to the ip with the port it wasn't able to. Gave the error "cannot bind to the requested ip address". I then changed the ip in the program to 127.0.0.1 and everything worked fine.

So I went ahead and added a line in the hosts file (which only had the 127.0.0.1 localhost) which said 192.168.1.103 testname. After this the socket program worked fine when I used the 192 ip.

That being said, when i restarted the machine, linux took a lot of time to reboot. As soon as i removed this newly added line from the hosts file, it was booting at it's normal speed.

My computer comes in through a router, I don't know if DHCP has anything to do with this.

Thanks in advance for the help. Really appreciate the fact that I can ask folks who know this stuff about this.

Kind Regards
Aby

mndar
8th September 2005, 02:47 PM
Gave the error "cannot bind to the requested ip address"
I read this somewhere. After creating a socket, set the socket options as follows
setsockopt(sockfd,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(int));
where sockfd is the socket and yes is an integer with value 1
This solved the problem for me.

philipaby
29th September 2005, 07:44 PM

Thanks mndar,
That solved the problem. Really appreciate the help. Sorry for being late in the reply as I was out on vacation.