|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T x
Length: 3265 (0xcc1)
Types: TextFile
Names: »xtrek.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
└─⟦this⟧ »EUUGD18/X/Xtrek/xtrek.c«
static char sccsid[] = "@(#)xtrek.c 1.2";
#include <sys/types.h>
#include <stdio.h>
#include <pwd.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#ifdef SUN40
#include <sys/filio.h>
#else
#define FD_SET(n, s) (((s)->fds_bits[0]) |= (1 << n))
#define FD_CLR(n, s) (((s)->fds_bits[0]) &= ~(1 << n))
#define FD_ZERO(s) bzero((char *)(s), sizeof (*(s)))
#define FD_ISSET(n, s) (((s)->fds_bits[0]) & (1 << n))
#include <sys/ioctl.h>
#endif /* SUN40 */
#include <setjmp.h>
#include <netdb.h>
#include <signal.h>
#include <string.h>
struct sockaddr_in sin;
struct sockaddr_in udp_sin;
struct servent *sp;
jmp_buf sdied;
done()
{
fprintf(stderr, "broken pipe\n");
longjmp(sdied);
}
main(ac, av)
register int ac;
register char **av;
{
register struct hostent *host = (struct hostent *) NULL;
struct passwd *pwent;
int s;
char *h, *p;
char hostname[80]; /* The xtrek-server-machine */
char *display;
struct servent *sp;
extern struct servent *getservbyname();
extern char *getenv();
p = strrchr(av[0], '/');
if (p == (char *) NULL)
p = av[0];
if (ac != 2)
usage(p);
pwent = getpwuid(getuid());
if (pwent == (struct passwd *) NULL) {
printf("Who are you?\n");
exit(2);
}
display = getenv("DISPLAY");
if (display == (char *) NULL) {
printf("Your DISPLAY environment variable is not set.\n");
exit(3);
}
h = av[1];
sin.sin_addr.s_addr = inet_addr(h);
if (sin.sin_addr.s_addr != -1) {
sin.sin_family = AF_INET;
(void) strcpy(hostname, h);
} else {
host = gethostbyname(h);
if (host) {
sin.sin_family = host->h_addrtype;
bcopy(host->h_addr, (caddr_t) &sin.sin_addr,
host->h_length);
strcpy(hostname, host->h_name, strlen(host->h_name));
} else {
printf("%s: unknown host\n", h);
exit(1);
}
}
sin.sin_port = 5701;
signal(SIGPIPE, done);
#if defined(sun) && !defined(SUN40)
/* Do something to get inetd to start up in.xtrekd */
sp = getservbyname("xtrek", "udp");
if (sp == (struct servent *) NULL) {
goto normal;
}
udp_sin = sin;
udp_sin.sin_port = sp->s_port;
s = socket(AF_INET, SOCK_DGRAM, 0);
if (s < 0) {
fprintf(stderr, "Can't open xtrek datagram socket\n");
perror("socket");
exit(1);
}
if (connect(s, (struct sockaddr *) &udp_sin, sizeof (udp_sin)) < 0) {
perror("connect udp");
(void) close(s);
exit(1);
}
send(s, "WAKEUP!\015\012", 9, 0);
close(s);
normal:
sleep(3); /* give the daemon a chance to start */
#endif
s = socket(AF_INET, SOCK_STREAM, 0);
if (s < 0) {
perror("socket");
exit(1);
}
if (connect(s, (struct sockaddr *) &sin, sizeof (sin)) < 0) {
perror("connect");
(void) close(s);
exit(1);
}
if (setjmp(sdied) == 0)
startup(s, display, pwent->pw_name);
exit(0);
}
startup(s, d, l)
register int s;
register char *d, *l;
{
char buf[80];
int n = 1;
sprintf(buf, "Display: %s Login: %s", d, l);
write(s, buf, strlen(buf));
write(s, "\015\012", 2);
fflush(stdout);
while ((n = read(s, buf, sizeof buf)) >= 0) {
if (n <= 0) {
write(s, "DONE\n", 5); /* Does this cause SIGPIPE? */
/* No, I think it causes read() above to return -1 */
sleep(1);
} else
write(fileno(stdout), buf, n);
}
return 1;
}
usage(p)
register char *p;
{
printf("Usage: %s xtrek-server-machine\n", p);
exit(1);
}