whois service and connect

I am writing my first program with sockets and I am trying to write a client
that uses the whois tcp/ip service.
But after connect (last line), desc=-1 and I get “Error: Connection refused”.
I am using QNX 6.2.1 SE, inetd is running and the service whois in uncommented.
What could be happend?
If I change the line sp= getservbyname(“whois”,“tcp”); to
sp= getservbyname(“ftp”,“tcp”), I get no error.

Thank you

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>

int main(int argc, char *argv[])
int s;
int desc;
int len;
struct sockaddr_in sa;
struct hostent *hp;
struct servent *sp;
char buf[BUFSIZ+1];
char *myname;
char *host;
char *user;

myname= argv[0];	
host= argv[1];  // NAME OF THE HOST (1st argument)	
user= argv[2]; // NAME OF THE USER (2nd argument)	
hp= gethostbyname(host);

strncpy( &sa.sin_addr, (hp->h_addr), hp->h_length);
sa.sin_family= hp->h_addrtype;	
sp= getservbyname("whois","tcp");	
sa.sin_port= sp->s_port;	
s= socket(hp->h_addrtype, SOCK_STREAM, 0);
desc= connect(s, (struct sockaddr *) &sa, sizeof(sa));


Your argv[1] is the HOST. When you test your program, which host did you use to test against? Are you sure the whois service is listening on that target host? You could try to connect to the well-known whois server such as “whois.arin.net”.

I dont know if what I am doing it is right or not. I am using my
own computer or computers from my local network with QNX to test against.

It is just an easy program to start using sockets.

Thank you.

Well, your test program tries to make a connection to the whois port (tcp port 43) on the HOST (specified on the command line argument). “connection refused” is the correct result if you don’t have anything listening on port 43 on the HOST. You can easily verify this by

telnet HOST 43