10 date 91.01.25.14.49.56; author mh; state Exp;
15 date 91.01.25.14.49.13; author mh; state Exp;
26 @don't include arpa/inet.h on hpux
34 /* ttyw.c - the writer */
39 #include <sys/types.h>
40 #include <sys/socket.h>
41 #include <netinet/in.h>
44 #include <arpa/inet.h>
51 ttyw (command, host, line, user)
63 struct sockaddr_in tty_socket,
66 if (command == NULL) {
71 if ((sp = getservbyname ("ttyserver", "tcp")) == NULL) {
76 (void) gethostname (host = buffer, sizeof buffer);
77 if ((hp = gethostbyname (host))==NULL) {
82 if (line && strncmp (line, "/dev/", strlen ("/dev/")) == 0)
83 line += strlen ("/dev/");
85 privd = *command >= 'A' && *command <= 'Z';/* crude */
89 for (times = 1; times <= 16; times *= 2) {
90 if ((sd = getport (0, privd)) == NOTOK)
93 bzero ((char *) tsock, sizeof *tsock);
94 tsock -> sin_family = hp -> h_addrtype;
95 tsock -> sin_port = sp -> s_port;
96 bcopy (hp -> h_addr, (char *) &tsock -> sin_addr, hp -> h_length);
98 if (connect (sd, (struct sockaddr *) tsock, sizeof *tsock) == NOTOK) {
100 if (errno == ECONNREFUSED || errno == EINTR) {
107 ttym (sd, command, line, user, NULL);
108 if (ttyv (sd) == NOTOK || ttyv (sd) == NOTOK) {
110 errno = EPERM; /* what else??? */
122 static int getport (options, privd)
128 struct sockaddr_in unx_socket,
129 *usock = &unx_socket;
131 if ((sd = socket (AF_INET, SOCK_STREAM, 0)) == NOTOK)
134 if (options & SO_DEBUG)
135 (void) setsockopt (sd, SOL_SOCKET, SO_DEBUG, NULL, 0);
136 (void) setsockopt (sd, SOL_SOCKET, SO_KEEPALIVE, NULL, 0);
141 usock -> sin_family = AF_INET;
142 usock -> sin_addr.s_addr = INADDR_ANY;
144 for (port = IPPORT_RESERVED - 1; port > IPPORT_RESERVED / 2; port--) {
145 usock -> sin_port = htons (port);
147 switch (bind (sd, (struct sockaddr *) usock, sizeof *usock)) {
149 if (errno != EADDRINUSE && errno != EADDRNOTAVAIL)