DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Developing applications over TCP/IP using Internet sockets

Client processes (Internet domain)

While the server side of the remote login service is a passive entity, listening for client connections, the client process is an active entity which initiates a connection when invoked.

As in the server process, the first step taken by the client remote login process is to locate the service definition for a remote login.

   sp = getservbyname("login" "tcp");


   if (sp == NULL) {
           fprintf(stderr, "rlogin: tcp/login: unknown service\n");
           exit(1);
   }
Next the destination host is looked up with a gethostbyname call.
   p = gethostbyname(argv[1]);
   if (hp == NULL) {
           fprintf(stderr, "rlogin: %s: unknown host\n", argv[1]);
           exit(2);
   }

With this accomplished, all that is required is to establish a connection to the server at the requested host and start up the remote login protocol. The address buffer is cleared, then filled in with the Internet address of the foreign host and the port number at which the login process resides.

   memset((char *)&sin, 0, sizeof(sin));
   memcpy (&sin.sin_addr, hp->h_addr, hp->h_length) ;
   sin.sin_family = hp->h_addrtype;
   sin.sin_port = sp->s_port;
A socket is created, and a connection is initiated.
   s = socket(hp->h_addrtype, SOCK_STREAM, 0);
   if (s < 0) {
           perror("rlogin: socket");
           exit(3);
   }
   /* ... */
   if (connect(s, (struct sockaddr *) &sin, sizeof (sin)) < 0) {
           perror("rlogin: connect");
           exit(4);
   }

Next topic: Server processes without connections (Internet domain)
Previous topic: Main body of the loop

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003