debug options survived to mgmt close (and new mgmt open).
[vde.git] / vde / slirpvde / misc.c
bloba471964982431adb06ec745ee853adb8c006a0bf
1 /*
2 * Copyright (c) 1995 Danny Gasparovski.
3 *
4 * Please read the file COPYRIGHT for the
5 * terms and conditions of the copyright.
6 */
8 #define WANT_SYS_IOCTL_H
9 #include <config.h>
10 #include <slirp.h>
12 u_int curtime, time_fasttimo, last_slowtimo, detach_time;
13 u_int detach_wait = 600000; /* 10 minutes */
15 #if 0
16 int x_port = -1;
17 int x_display = 0;
18 int x_screen = 0;
20 int
21 show_x(buff, inso)
22 char *buff;
23 struct socket *inso;
25 if (x_port < 0) {
26 lprint("X Redir: X not being redirected.\r\n");
27 } else {
28 lprint("X Redir: In sh/bash/zsh/etc. type: DISPLAY=%s:%d.%d; export DISPLAY\r\n",
29 inet_ntoa(our_addr), x_port, x_screen);
30 lprint("X Redir: In csh/tcsh/etc. type: setenv DISPLAY %s:%d.%d\r\n",
31 inet_ntoa(our_addr), x_port, x_screen);
32 if (x_display)
33 lprint("X Redir: Redirecting to display %d\r\n", x_display);
36 return CFG_OK;
41 * XXX Allow more than one X redirection?
43 void
44 redir_x(inaddr, start_port, display, screen)
45 u_int32_t inaddr;
46 int start_port;
47 int display;
48 int screen;
50 int i;
52 if (x_port >= 0) {
53 lprint("X Redir: X already being redirected.\r\n");
54 show_x(0, 0);
55 } else {
56 for (i = 6001 + (start_port-1); i <= 6100; i++) {
57 if (solisten(htons(i), inaddr, htons(6000 + display), 0)) {
58 /* Success */
59 x_port = i - 6000;
60 x_display = display;
61 x_screen = screen;
62 show_x(0, 0);
63 return;
66 lprint("X Redir: Error: Couldn't redirect a port for X. Weird.\r\n");
69 #endif
71 #ifndef HAVE_INET_ATON
72 int
73 inet_aton(cp, ia)
74 const char *cp;
75 struct in_addr *ia;
77 u_int32_t addr = inet_addr(cp);
78 if (addr == 0xffffffff)
79 return 0;
80 ia->s_addr = addr;
81 return 1;
83 #endif
86 * Get our IP address and put it in our_addr
88 void
89 getouraddr()
91 char buff[256];
92 struct hostent *he;
94 if (gethostname(buff,256) < 0)
95 return;
97 if ((he = gethostbyname(buff)) == NULL)
98 return;
100 our_addr = *(struct in_addr *)he->h_addr;
103 #if SIZEOF_CHAR_P == 8
105 struct quehead_32 {
106 u_int32_t qh_link;
107 u_int32_t qh_rlink;
110 inline void
111 insque_32(a, b)
112 void *a;
113 void *b;
115 register struct quehead_32 *element = (struct quehead_32 *) a;
116 register struct quehead_32 *head = (struct quehead_32 *) b;
117 element->qh_link = head->qh_link;
118 head->qh_link = (u_int32_t)element;
119 element->qh_rlink = (u_int32_t)head;
120 ((struct quehead_32 *)(element->qh_link))->qh_rlink
121 = (u_int32_t)element;
124 inline void
125 remque_32(void *a)
127 register struct quehead_32 *element = (struct quehead_32 *) a;
128 ((struct quehead_32 *)(element->qh_link))->qh_rlink = element->qh_rlink;
129 ((struct quehead_32 *)(element->qh_rlink))->qh_link = element->qh_link;
130 element->qh_rlink = 0;
133 #endif /* SIZEOF_CHAR_P == 8 */
135 struct quehead {
136 struct quehead *qh_link;
137 struct quehead *qh_rlink;
140 inline void
141 insque(a, b)
142 void *a, *b;
144 register struct quehead *element = (struct quehead *) a;
145 register struct quehead *head = (struct quehead *) b;
146 element->qh_link = head->qh_link;
147 head->qh_link = (struct quehead *)element;
148 element->qh_rlink = (struct quehead *)head;
149 ((struct quehead *)(element->qh_link))->qh_rlink
150 = (struct quehead *)element;
153 inline void
154 remque(a)
155 void *a;
157 register struct quehead *element = (struct quehead *) a;
158 ((struct quehead *)(element->qh_link))->qh_rlink = element->qh_rlink;
159 ((struct quehead *)(element->qh_rlink))->qh_link = element->qh_link;
160 element->qh_rlink = NULL;
161 /* element->qh_link = NULL; TCP FIN1 crashes if you do this. Why ? */
164 /* #endif */
168 add_exec(ex_ptr, do_pty, exec, addr, port)
169 struct ex_list **ex_ptr;
170 int do_pty;
171 char *exec;
172 int addr;
173 int port;
175 struct ex_list *tmp_ptr;
177 /* First, check if the port is "bound" */
178 for (tmp_ptr = *ex_ptr; tmp_ptr; tmp_ptr = tmp_ptr->ex_next) {
179 if (port == tmp_ptr->ex_fport && addr == tmp_ptr->ex_addr)
180 return -1;
183 tmp_ptr = *ex_ptr;
184 *ex_ptr = (struct ex_list *)malloc(sizeof(struct ex_list));
185 (*ex_ptr)->ex_fport = port;
186 (*ex_ptr)->ex_addr = addr;
187 (*ex_ptr)->ex_pty = do_pty;
188 (*ex_ptr)->ex_exec = strdup(exec);
189 (*ex_ptr)->ex_next = tmp_ptr;
190 return 0;
193 #ifndef HAVE_STRERROR
196 * For systems with no strerror
199 extern int sys_nerr;
200 extern char *sys_errlist[];
202 char *
203 strerror(error)
204 int error;
206 if (error < sys_nerr)
207 return sys_errlist[error];
208 else
209 return "Unknown error.";
212 #endif
215 #if 0
217 openpty(amaster, aslave)
218 int *amaster, *aslave;
220 register int master, slave;
222 #ifdef HAVE_GRANTPT
223 char *ptr;
225 if ((master = open("/dev/ptmx", O_RDWR)) < 0 ||
226 grantpt(master) < 0 ||
227 unlockpt(master) < 0 ||
228 (ptr = ptsname(master)) == NULL) {
229 close(master);
230 return -1;
233 if ((slave = open(ptr, O_RDWR)) < 0 ||
234 ioctl(slave, I_PUSH, "ptem") < 0 ||
235 ioctl(slave, I_PUSH, "ldterm") < 0 ||
236 ioctl(slave, I_PUSH, "ttcompat") < 0) {
237 close(master);
238 close(slave);
239 return -1;
242 *amaster = master;
243 *aslave = slave;
244 return 0;
246 #else
248 static char line[] = "/dev/ptyXX";
249 register const char *cp1, *cp2;
251 for (cp1 = "pqrsPQRS"; *cp1; cp1++) {
252 line[8] = *cp1;
253 for (cp2 = "0123456789abcdefghijklmnopqrstuv"; *cp2; cp2++) {
254 line[9] = *cp2;
255 if ((master = open(line, O_RDWR, 0)) == -1) {
256 if (errno == ENOENT)
257 return (-1); /* out of ptys */
258 } else {
259 line[5] = 't';
260 /* These will fail */
261 (void) chown(line, getuid(), 0);
262 (void) chmod(line, S_IRUSR|S_IWUSR|S_IWGRP);
263 #ifdef HAVE_REVOKE
264 (void) revoke(line);
265 #endif
266 if ((slave = open(line, O_RDWR, 0)) != -1) {
267 *amaster = master;
268 *aslave = slave;
269 return 0;
271 (void) close(master);
272 line[5] = 'p';
276 errno = ENOENT; /* out of ptys */
277 return (-1);
278 #endif
282 * XXX This is ugly
283 * We create and bind a socket, then fork off to another
284 * process, which connects to this socket, after which we
285 * exec the wanted program. If something (strange) happens,
286 * the accept() call could block us forever.
288 * do_pty = 0 Fork/exec inetd style
289 * do_pty = 1 Fork/exec using slirp.telnetd
290 * do_ptr = 2 Fork/exec using pty
293 fork_exec(so, ex, do_pty)
294 struct socket *so;
295 char *ex;
296 int do_pty;
298 int s;
299 struct sockaddr_in addr;
300 int addrlen = sizeof(addr);
301 int opt;
302 int master;
303 char *argv[256];
304 char buff[256];
305 /* don't want to clobber the original */
306 char *bptr;
307 char *curarg;
308 int c, i;
310 DEBUG_CALL("fork_exec");
311 DEBUG_ARG("so = %lx", (long)so);
312 DEBUG_ARG("ex = %lx", (long)ex);
313 DEBUG_ARG("do_pty = %lx", (long)do_pty);
315 if (do_pty == 2) {
316 if (openpty(&master, &s) == -1) {
317 lprint("Error: openpty failed: %s\n", strerror(errno));
318 return 0;
320 } else {
321 addr.sin_family = AF_INET;
322 addr.sin_port = 0;
323 addr.sin_addr.s_addr = INADDR_ANY;
325 if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0 ||
326 bind(s, (struct sockaddr *)&addr, addrlen) < 0 ||
327 listen(s, 1) < 0) {
328 lprint("Error: inet socket: %s\n", strerror(errno));
329 close(s);
331 return 0;
335 switch(fork()) {
336 case -1:
337 lprint("Error: fork failed: %s\n", strerror(errno));
338 close(s);
339 if (do_pty == 2)
340 close(master);
341 return 0;
343 case 0:
344 /* Set the DISPLAY */
345 if (do_pty == 2) {
346 (void) close(master);
347 #ifdef TIOCSCTTY /* XXXXX */
348 (void) setsid();
349 ioctl(s, TIOCSCTTY, (char *)NULL);
350 #endif
351 } else {
352 getsockname(s, (struct sockaddr *)&addr, &addrlen);
353 close(s);
355 * Connect to the socket
356 * XXX If any of these fail, we're in trouble!
358 s = socket(AF_INET, SOCK_STREAM, 0);
359 addr.sin_addr = loopback_addr;
360 connect(s, (struct sockaddr *)&addr, addrlen);
363 if (x_port >= 0) {
364 #ifdef HAVE_SETENV
365 sprintf(buff, "%s:%d.%d", inet_ntoa(our_addr), x_port, x_screen);
366 setenv("DISPLAY", buff, 1);
367 #else
368 sprintf(buff, "DISPLAY=%s:%d.%d", inet_ntoa(our_addr), x_port, x_screen);
369 putenv(buff);
370 #endif
373 dup2(s, 0);
374 dup2(s, 1);
375 dup2(s, 2);
376 for (s = 3; s <= 255; s++)
377 close(s);
379 i = 0;
380 bptr = strdup(ex); /* No need to free() this */
381 if (do_pty == 1) {
382 /* Setup "slirp.telnetd -x" */
383 argv[i++] = "slirp.telnetd";
384 argv[i++] = "-x";
385 argv[i++] = bptr;
386 } else
387 do {
388 /* Change the string into argv[] */
389 curarg = bptr;
390 while (*bptr != ' ' && *bptr != (char)0)
391 bptr++;
392 c = *bptr;
393 *bptr++ = (char)0;
394 argv[i++] = strdup(curarg);
395 } while (c);
397 argv[i] = 0;
398 execvp(argv[0], argv);
400 /* Ooops, failed, let's tell the user why */
402 char buff[256];
404 sprintf(buff, "Error: execvp of %s failed: %s\n",
405 argv[0], strerror(errno));
406 write(2, buff, strlen(buff)+1);
408 close(0); close(1); close(2); /* XXX */
409 exit(1);
411 default:
412 if (do_pty == 2) {
413 close(s);
414 so->s = master;
415 } else {
417 * XXX this could block us...
418 * XXX Should set a timer here, and if accept() doesn't
419 * return after X seconds, declare it a failure
420 * The only reason this will block forever is if socket()
421 * of connect() fail in the child process
423 so->s = accept(s, (struct sockaddr *)&addr, &addrlen);
424 close(s);
425 opt = 1;
426 setsockopt(so->s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(int));
427 opt = 1;
428 setsockopt(so->s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(int));
430 fd_nonblock(so->s);
432 /* Append the telnet options now */
433 if (so->so_m != 0 && do_pty == 1) {
434 sbappend(so, so->so_m);
435 so->so_m = 0;
438 return 1;
441 #endif
443 #ifndef HAVE_STRDUP
444 char *
445 strdup(str)
446 const char *str;
448 char *bptr;
450 bptr = (char *)malloc(strlen(str)+1);
451 strcpy(bptr, str);
453 return bptr;
455 #endif
457 #if 0
458 void
459 snooze_hup(num)
460 int num;
462 int s, ret;
463 #ifndef NO_UNIX_SOCKETS
464 struct sockaddr_un sock_un;
465 #endif
466 struct sockaddr_in sock_in;
467 char buff[256];
469 ret = -1;
470 if (slirp_socket_passwd) {
471 s = socket(AF_INET, SOCK_STREAM, 0);
472 if (s < 0)
473 slirp_exit(1);
474 sock_in.sin_family = AF_INET;
475 sock_in.sin_addr.s_addr = slirp_socket_addr;
476 sock_in.sin_port = htons(slirp_socket_port);
477 if (connect(s, (struct sockaddr *)&sock_in, sizeof(sock_in)) != 0)
478 slirp_exit(1); /* just exit...*/
479 sprintf(buff, "kill %s:%d", slirp_socket_passwd, slirp_socket_unit);
480 write(s, buff, strlen(buff)+1);
482 #ifndef NO_UNIX_SOCKETS
483 else {
484 s = socket(AF_UNIX, SOCK_STREAM, 0);
485 if (s < 0)
486 slirp_exit(1);
487 sock_un.sun_family = AF_UNIX;
488 strcpy(sock_un.sun_path, socket_path);
489 if (connect(s, (struct sockaddr *)&sock_un,
490 sizeof(sock_un.sun_family) + sizeof(sock_un.sun_path)) != 0)
491 slirp_exit(1);
492 sprintf(buff, "kill none:%d", slirp_socket_unit);
493 write(s, buff, strlen(buff)+1);
495 #endif
496 slirp_exit(0);
500 void
501 snooze()
503 sigset_t s;
504 int i;
506 /* Don't need our data anymore */
507 /* XXX This makes SunOS barf */
508 /* brk(0); */
510 /* Close all fd's */
511 for (i = 255; i >= 0; i--)
512 close(i);
514 signal(SIGQUIT, slirp_exit);
515 signal(SIGHUP, snooze_hup);
516 sigemptyset(&s);
518 /* Wait for any signal */
519 sigsuspend(&s);
521 /* Just in case ... */
522 exit(255);
525 void
526 relay(s)
527 int s;
529 char buf[8192];
530 int n;
531 fd_set readfds;
532 struct ttys *ttyp;
534 /* Don't need our data anymore */
535 /* XXX This makes SunOS barf */
536 /* brk(0); */
538 signal(SIGQUIT, slirp_exit);
539 signal(SIGHUP, slirp_exit);
540 signal(SIGINT, slirp_exit);
541 signal(SIGTERM, slirp_exit);
543 /* Fudge to get term_raw and term_restore to work */
544 if (NULL == (ttyp = tty_attach (0, slirp_tty))) {
545 lprint ("Error: tty_attach failed in misc.c:relay()\r\n");
546 slirp_exit (1);
548 ttyp->fd = 0;
549 ttyp->flags |= TTY_CTTY;
550 term_raw(ttyp);
552 while (1) {
553 FD_ZERO(&readfds);
555 FD_SET(0, &readfds);
556 FD_SET(s, &readfds);
558 n = select(s+1, &readfds, (fd_set *)0, (fd_set *)0, (struct timeval *)0);
560 if (n <= 0)
561 slirp_exit(0);
563 if (FD_ISSET(0, &readfds)) {
564 n = read(0, buf, 8192);
565 if (n <= 0)
566 slirp_exit(0);
567 n = writen(s, buf, n);
568 if (n <= 0)
569 slirp_exit(0);
572 if (FD_ISSET(s, &readfds)) {
573 n = read(s, buf, 8192);
574 if (n <= 0)
575 slirp_exit(0);
576 n = writen(0, buf, n);
577 if (n <= 0)
578 slirp_exit(0);
582 /* Just in case.... */
583 exit(1);
585 #endif
587 int (*lprint_print) _P((void *, const char *, va_list));
588 char *lprint_ptr, *lprint_ptr2, **lprint_arg;
590 void
591 #ifdef __STDC__
592 lprint(const char *format, ...)
593 #else
594 lprint(va_alist) va_dcl
595 #endif
597 va_list args;
599 #ifdef __STDC__
600 va_start(args, format);
601 #else
602 char *format;
603 va_start(args);
604 format = va_arg(args, char *);
605 #endif
606 #if 0
607 /* If we're printing to an sbuf, make sure there's enough room */
608 /* XXX +100? */
609 if (lprint_sb) {
610 if ((lprint_ptr - lprint_sb->sb_wptr) >=
611 (lprint_sb->sb_datalen - (strlen(format) + 100))) {
612 int deltaw = lprint_sb->sb_wptr - lprint_sb->sb_data;
613 int deltar = lprint_sb->sb_rptr - lprint_sb->sb_data;
614 int deltap = lprint_ptr - lprint_sb->sb_data;
616 lprint_sb->sb_data = (char *)realloc(lprint_sb->sb_data,
617 lprint_sb->sb_datalen + TCP_SNDSPACE);
619 /* Adjust all values */
620 lprint_sb->sb_wptr = lprint_sb->sb_data + deltaw;
621 lprint_sb->sb_rptr = lprint_sb->sb_data + deltar;
622 lprint_ptr = lprint_sb->sb_data + deltap;
624 lprint_sb->sb_datalen += TCP_SNDSPACE;
627 #endif
628 if (lprint_print)
629 lprint_ptr += (*lprint_print)(*lprint_arg, format, args);
631 /* Check if they want output to be logged to file as well */
632 if (lfd) {
634 * Remove \r's
635 * otherwise you'll get ^M all over the file
637 int len = strlen(format);
638 char *bptr1, *bptr2;
640 bptr1 = bptr2 = strdup(format);
642 while (len--) {
643 if (*bptr1 == '\r')
644 memcpy(bptr1, bptr1+1, len+1);
645 else
646 bptr1++;
648 vfprintf(lfd, bptr2, args);
649 free(bptr2);
651 va_end(args);
654 void
655 add_emu(buff)
656 char *buff;
658 u_int lport, fport;
659 u_int8_t tos = 0, emu = 0;
660 char buff1[256], buff2[256], buff4[128];
661 char *buff3 = buff4;
662 struct emu_t *emup;
663 struct socket *so;
665 if (sscanf(buff, "%256s %256s", buff2, buff1) != 2) {
666 lprint("Error: Bad arguments\r\n");
667 return;
670 if (sscanf(buff1, "%d:%d", &lport, &fport) != 2) {
671 lport = 0;
672 if (sscanf(buff1, "%d", &fport) != 1) {
673 lprint("Error: Bad first argument\r\n");
674 return;
678 if (sscanf(buff2, "%128[^:]:%128s", buff1, buff3) != 2) {
679 buff3 = 0;
680 if (sscanf(buff2, "%256s", buff1) != 1) {
681 lprint("Error: Bad second argument\r\n");
682 return;
686 if (buff3) {
687 if (strcmp(buff3, "lowdelay") == 0)
688 tos = IPTOS_LOWDELAY;
689 else if (strcmp(buff3, "throughput") == 0)
690 tos = IPTOS_THROUGHPUT;
691 else {
692 lprint("Error: Expecting \"lowdelay\"/\"throughput\"\r\n");
693 return;
697 if (strcmp(buff1, "ftp") == 0)
698 emu = EMU_FTP;
699 else if (strcmp(buff1, "irc") == 0)
700 emu = EMU_IRC;
701 else if (strcmp(buff1, "none") == 0)
702 emu = EMU_NONE; /* ie: no emulation */
703 else {
704 lprint("Error: Unknown service\r\n");
705 return;
708 /* First, check that it isn't already emulated */
709 for (emup = tcpemu; emup; emup = emup->next) {
710 if (emup->lport == lport && emup->fport == fport) {
711 lprint("Error: port already emulated\r\n");
712 return;
716 /* link it */
717 emup = (struct emu_t *)malloc(sizeof (struct emu_t));
718 emup->lport = (u_int16_t)lport;
719 emup->fport = (u_int16_t)fport;
720 emup->tos = tos;
721 emup->emu = emu;
722 emup->next = tcpemu;
723 tcpemu = emup;
725 /* And finally, mark all current sessions, if any, as being emulated */
726 for (so = tcb.so_next; so != &tcb; so = so->so_next) {
727 if ((lport && lport == ntohs(so->so_lport)) ||
728 (fport && fport == ntohs(so->so_fport))) {
729 if (emu)
730 so->so_emu = emu;
731 if (tos)
732 so->so_iptos = tos;
736 lprint("Adding emulation for %s to port %d/%d\r\n", buff1, emup->lport, emup->fport);
739 #ifdef BAD_SPRINTF
741 #undef vsprintf
742 #undef sprintf
745 * Some BSD-derived systems have a sprintf which returns char *
749 vsprintf_len(string, format, args)
750 char *string;
751 const char *format;
752 va_list args;
754 vsprintf(string, format, args);
755 return strlen(string);
759 #ifdef __STDC__
760 sprintf_len(char *string, const char *format, ...)
761 #else
762 sprintf_len(va_alist) va_dcl
763 #endif
765 va_list args;
766 #ifdef __STDC__
767 va_start(args, format);
768 #else
769 char *string;
770 char *format;
771 va_start(args);
772 string = va_arg(args, char *);
773 format = va_arg(args, char *);
774 #endif
775 vsprintf(string, format, args);
776 return strlen(string);
779 #endif
781 void
782 u_sleep(usec)
783 int usec;
785 struct timeval t;
786 fd_set fdset;
788 FD_ZERO(&fdset);
790 t.tv_sec = 0;
791 t.tv_usec = usec * 1000;
793 select(0, &fdset, &fdset, &fdset, &t);
797 * Set fd blocking and non-blocking
800 void
801 fd_nonblock(fd)
802 int fd;
804 #ifdef FIONBIO
805 int opt = 1;
807 ioctl(fd, FIONBIO, &opt);
808 #else
809 int opt;
811 opt = fcntl(fd, F_GETFL, 0);
812 opt |= O_NONBLOCK;
813 fcntl(fd, F_SETFL, opt);
814 #endif
817 void
818 fd_block(fd)
819 int fd;
821 #ifdef FIONBIO
822 int opt = 0;
824 ioctl(fd, FIONBIO, &opt);
825 #else
826 int opt;
828 opt = fcntl(fd, F_GETFL, 0);
829 opt &= ~O_NONBLOCK;
830 fcntl(fd, F_SETFL, opt);
831 #endif
835 #if 0
837 * invoke RSH
840 rsh_exec(so,ns, user, host, args)
841 struct socket *so;
842 struct socket *ns;
843 char *user;
844 char *host;
845 char *args;
847 int fd[2];
848 int fd0[2];
849 int s;
850 char buff[256];
852 DEBUG_CALL("rsh_exec");
853 DEBUG_ARG("so = %lx", (long)so);
855 if (pipe(fd)<0) {
856 lprint("Error: pipe failed: %s\n", strerror(errno));
857 return 0;
859 /* #ifdef HAVE_SOCKETPAIR */
860 #if 1
861 if (socketpair(PF_UNIX,SOCK_STREAM,0, fd0) == -1) {
862 close(fd[0]);
863 close(fd[1]);
864 lprint("Error: openpty failed: %s\n", strerror(errno));
865 return 0;
867 #else
868 if (openpty(&fd0[0], &fd0[1]) == -1) {
869 close(fd[0]);
870 close(fd[1]);
871 lprint("Error: openpty failed: %s\n", strerror(errno));
872 return 0;
874 #endif
876 switch(fork()) {
877 case -1:
878 lprint("Error: fork failed: %s\n", strerror(errno));
879 close(fd[0]);
880 close(fd[1]);
881 close(fd0[0]);
882 close(fd0[1]);
883 return 0;
885 case 0:
886 close(fd[0]);
887 close(fd0[0]);
889 /* Set the DISPLAY */
890 if (x_port >= 0) {
891 #ifdef HAVE_SETENV
892 sprintf(buff, "%s:%d.%d", inet_ntoa(our_addr), x_port, x_screen);
893 setenv("DISPLAY", buff, 1);
894 #else
895 sprintf(buff, "DISPLAY=%s:%d.%d", inet_ntoa(our_addr), x_port, x_screen);
896 putenv(buff);
897 #endif
900 dup2(fd0[1], 0);
901 dup2(fd0[1], 1);
902 dup2(fd[1], 2);
903 for (s = 3; s <= 255; s++)
904 close(s);
906 execlp("rsh","rsh","-l", user, host, args, NULL);
908 /* Ooops, failed, let's tell the user why */
910 sprintf(buff, "Error: execlp of %s failed: %s\n",
911 "rsh", strerror(errno));
912 write(2, buff, strlen(buff)+1);
913 close(0); close(1); close(2); /* XXX */
914 exit(1);
916 default:
917 close(fd[1]);
918 close(fd0[1]);
919 ns->s=fd[0];
920 so->s=fd0[0];
922 return 1;
925 #endif