|
|
With the support routines, an Internet application
program should rarely have to deal directly with addresses.
This allows services to be developed as much as
possible in a network independent fashion.
It is clear, however, that purging all
network dependencies is very difficult.
So long as the user is
required to supply network addresses when naming services and
sockets, there will always be some network dependency in a program,
as shown in
``Sample client code showing network dependency''.
For example, the normal code included in client programs, such as the remote login program, is of this form:
Sample client code showing network dependency
#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 sin; 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 *)&sin, sizeof (sin)); bcopy(hp->h_addr, (char *)&sin.sin_addr, hp->h_length); sin.sin_family = hp->h_addrtype; sin.sin_port = sp->s_port; s = socket(AF_INET, SOCK_STREAM, 0); if (s < 0) { perror("rlogin: socket"); exit(3); } /* ... */ if (connect(s, (char *)&sin, sizeof (sin)) < 0) { perror("rlogin: connect"); exit(5); } /* ... */ }To make the remote login program independent of the Internet protocols and addressing scheme, within the limitations of the current organization, it would be necessary to add a layer of routines which mask the network-dependent aspects from the mainstream login code.