Professional Documents
Culture Documents
Session 5959
Greg Granger
grgran@sas.com
host.mvs server.unx
<child>
stdout
Primary
exec cmd
Socket
rexeccmd (ls -l)
stdin
rexec
stderr (pipe)
Secondary
Socket rexecd
<parent>
inetd
rexeccmd
Primary
rexec
Socket rexecd
getservbyname() Coding
getservbyname() returns NULL for failure or a pointer to this structure for success:
struct servent {
char *s_name; /* official name */
char **s_aliases; /* array of aliases */
int s_port; /* well-known port */
char *s_proto; }; /* protocol to use (udp/tcp) */
On UNIX the data comes from the “/etc/services” file formatted like the following:
gethostbyname() Coding
Gethostbyname() returns NULL for failure or a pointer to this structure for success:
Struct hostent {
char *h_name; /* Official name */
char **h_aliases; /* array of aliases */
int h_addrtype; /* AF_INET for TCP/IP */
int h_length; /* sizeof(struct in_addr) for TCP/IP */
char **h_addr_list; /* points to array of struct in_addr */
#define h_addr h_addr_list[0]}; /* Primary IP address */
he = gethostbyname(host);
ia = (struct in_addr *)(he->h_addr);
printf("IP address: %s\n",inet_ntoa(*ia));
0 struct in_addr
154.166.17.231
struct sockaddr_in {
short sin_family; /* AF_INET */
u_short sin_port; /* TCP or UDP port */
struct in_addr sin_addr; /* IP address */
char sin_zero[8]; }; /* varies */
inetd
rexeccmd fork()
Primary
rexec
Socket
exec()
Server creation program (inetd) issues a fork() and exec() call to start
rexecd. The socket descriptor is attached to stdin, stdout and stderr
of rexecd.
inetd
rexeccmd close()
Primary
rexec
Socket
rexeccmd
Primary stdin/stdout/stderr
rexec rexecd
Socket
rexeccmd Primary
Socket
stdin/stdout
rexec rexecd
stderr
Secondary
rexec.c lines [83 - 140] Socket
rexeccmd Primary
Socket
stdin/stdout
rexec rexecd
stderr
Secondary
rexec.c lines [141 - 150] Socket
Server confirms
host.mvs server.unx
rexeccmd Primary
Socket
stdin/stdout
rexec rexecd
stderr
stdin rexecd
Primary
child
rexeccmd Socket
stdout
stderr
(pipe)
stderr
rexecd
parent
rexeccmd lines [61-118] Secondary
Socket
stdin command
Primary
child
rexeccmd Socket
stdout
stderr
(pipe)
stderr
rexecd
parent
rexeccmd lines [61-118] Secondary
Socket
Summary
U Reviewed various socket API function calls
U REXEC / REXECD dialog
U Useable TCP/IP Socket Application
U Questions ?
Bibliography
U Internetworking with TCP/IP: Volumes I, II & III, Douglas
Comer, Prentice Hall, 1991 (ISBN Vol I: 0134685059, Vol
III: 0138487146)
U The Whole Internet User’s Guide & Catalog by Ed Kroll;
O’Reilly & Associates
U UNIX Network Programming by W. Richard Stevens;
Prentice Hall, 1990 (ISBN 0139498761)
U Socket API Programmer’s Reference
U UNIX “man” pages
U TCP/IP Illustrated: Volumes 1 & 2, W. Richard Stevens (v2
with Gary R. Wright); Addison-Wesley Publishing Company,
1994