Technical article 109392

The sample code from the Network Programmer's Guide doesn't compile.

OpenServer 5.0.0OpenServer 5.0.2OpenServer 5.0.4OpenServer 5.0.5

Written · Last revised

Problem

I am trying to run the Sample client program taken from the SCO Development System Network Programmer's Guide and Reference, Chapter 7, Example 7-12.

When I compile the code, I get this error message:

"client.c", line 33: error: prototype mismatch: 4 args passed, 3 expected

Solution

Using your favorite editor, search for the line:

if (connect(s, (struct sockaddr*)&sin, sizeof(sin), 0) == -1) {

The connect function only takes three parameters; however, the
documentation has an extra parameter, which is the '0'.  The zero
can be taken out. The line should then look like this:
if (connect(s, (struct sockaddr*)&sin, sizeof(sin)) == -1) {
NOTE:     There is something else wrong with this code that does not give
          the desired output.  The output always reads:
tom: connect: Connection refused

To correct this, search for the line:

sin.sin_port = PORTNUM;

This line is missing the htons(SLIB) routine, which converts 16 and 32-bit quantities between network byte order and host byte order.

Change it to:
sin.sin_port = htons(PORTNUM);

This problem has been reported to SCO Engineering.

See also

byteorder(SLIB), gethostbyname(SLIB), getservent(SLIB)

From the Xinuos technical article database, record 109392. Reproduced with permission. The original is at www.sco.com/ta/109392, which is reachable but blocked from search engines. Xinuos marks this article against a retired product line. That refers to the product’s lifecycle, not to whether the advice still works — plenty of it still applies to running systems.

Next step

Need this fixed rather than explained?

Tell us the release, what the system runs and what it is doing. We will reply by email with what we would do next.

  • You deal with the people who do the work
  • No obligation, and no upgrade required before we will help
  • We tell you plainly if something is not worth doing

Send an enquiry

We reply by email. If a server is down, say so in the first line. You can also write to help@scoexpert.com.