Brian Hutchinson wrote:
> 
> I have a simple socket program.  I've compiled it with gcc on
> Debian 1.1 (kernel 2.0.29) and Red Had (Biltmore 2.0.30) and I keep
> getting Network is unreachable.
> 
> Running gdb reveals the connect call is not working.
> After stepping over the connect, errno = 101.  "Network is unreachable" is
> displayed by perror and the program exits.
> 
> This is a small program that runs fine under SunOS 4.1.3.  The only thing
> I had to do to the program was change the include paths from sys/ to linux/.
> 
> My Linux box IP 140.117.43.69
> Netmask         255.255.224.0
> Network         140.117.32.0
> Broadcast       140.117.63.225
> 
> Can anyone give me a clue as to what the problem might be.  I don't know what
> to look for at the moment.  The only thing I can think of is the above IPs
> are not correct.  I can ping and telnet to the target which has the server 
> this
> socket program is to connect to.  I look in the arp table and it has a 
> complete
> entry.  Would arp be able to figure out everything if the above IPs we not 
> right?
> 
> Thanks in advance for any advice.

When you set up your sockaddr_in do you make sure to use htonl() to
convert the IP address to network byte order? I bet you don't! Your
program would work on a Sun because Sparc uses big-endian numbers
(which are therefore *already* in network byte order) while Intel x86
uses little-endian numbers which must be re-ordered using htonl().

-- 
Jens B. Jorgensen
[EMAIL PROTECTED]


--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
[EMAIL PROTECTED] . 
Trouble?  e-mail to [EMAIL PROTECTED] .

Reply via email to