Figure 1. Remote login client code.
     #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);
          }
          bzero((char *)&server, sizeof (server));
          bcopy(hp->h_addr, (char *)&server.sin_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, (char *)&server, sizeof (server)) < 0) {
               perror("rlogin: connect");
               exit(5);
          }
          ...
     }