As pointed out by Jeff, the defect was:
to replace the line

    sa.sin_port = pno;
with
    sa.sin_port = htons(pno);

His explanation of this was:

<quote>
Because multiple byte quantities are needed as part of the TCP/IP
protocol, the protocol designers adopted a single standard for how
multibyte values are sent across the network. TCP/IP mandates that
big-endian byte order be used for transmitting protocol information
and suggests that it be used for application data, as well.

The ordering used for multibyte values sent across the network
is also known as the network byte order. This is the reason why we
need to use htons, to convert the short value pno from host order
to network order.

The reason that your program program works fine in Solaris is
because Solaris ( Sparc CPU, IBM PowerPC, and MC68000 families )
is a big endian architecture.

You will need to use htons ( or htonl ) in little endian platforms
such as Linux, Windows, DEC Alpha,etc.

Actually , The Silicon Graphics MIPS and IBM/Motorola PowerPC  can be
either.
</quote>

rahul



Reply via email to