Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

Example of address conversion

&pagelevel(3)&pagelevel

The client program code of the remote login shown below demonstrates the address conversion discussed in the preceding sections.

#include <sys.types.h>
#include <sys.socket.h>
#include <netinet.in.h>
#include <stdio.h>
#include <netdb.h>
 
main(argc, argv)
      int argc;
      char *argv[];
{
      struct sockaddr_in server;
      struct servent *sp;
      struct hostent *hp;
      int s;
      sp = getservbyname("login", "tcp");
      if (sp == NULL) {
              fprintf(stderr, "rlogin: tcp/login: unknown service\n");
              exit(1);
      }
      hp = gethostbyname(argv[1]);
      if (hp == NULL) {
              fprintf(stderr, "rlogin: %s: unknown host\n", argv[1]);
              exit(2);
      }
      memset((char *)&server, 0, sizeof server);
      memcpy((char *)&server.sin_addr, hp->h_addr, hp->h_length);
      server.sin_family = hp->h_addrtype;
      server.sin_port = sp->s_port;
      s = socket(AF_INET, SOCK_STREAM, 0);
      if (s < 0) {
              perror("rlogin: socket");
              exit(3);
      }
 
      /* Connect does the bind for us */
      if (connect(s, &server, sizeof server) < 0) {
              perror("rlogin: connect");
              exit(5);
      }
exit(0);
}