Changeset 14331 in vbox for trunk/src/VBox
- Timestamp:
- Nov 18, 2008 10:09:17 PM (16 years ago)
- Location:
- trunk/src/VBox/Devices/Network/slirp
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/slirp/debug.c
r13984 r14331 288 288 } 289 289 290 #if 0291 void292 slirp_exit(exit_status)293 int exit_status;294 {295 struct ttys *ttyp;296 297 DEBUG_CALL("slirp_exit");298 DEBUG_ARG("exit_status = %d", exit_status);299 300 if (dostats) {301 lprint_print = (int (*) _P((void *, const char *, va_list)))vfprintf;302 if (!dfd)303 debug_init("slirp_stats", 0xf);304 lprint_arg = (char **)&dfd;305 306 ipstats();307 tcpstats();308 udpstats();309 icmpstats();310 mbufstats();311 sockstats();312 allttystats();313 vjstats();314 }315 316 for (ttyp = ttys; ttyp; ttyp = ttyp->next)317 tty_detached(ttyp, 1);318 319 if (slirp_forked) {320 /* Menendez time */321 if (kill(getppid(), SIGQUIT) < 0)322 lprint("Couldn't kill parent process %ld!\n",323 (long) getppid());324 }325 326 /* Restore the terminal if we gotta */327 if(slirp_tty_restore)328 tcsetattr(0,TCSANOW, &slirp_tty_settings); /* NOW DAMMIT! */329 exit(exit_status);330 }331 #endif -
trunk/src/VBox/Devices/Network/slirp/misc.c
r14329 r14331 8 8 #define WANT_SYS_IOCTL_H 9 9 #include <slirp.h> 10 11 12 #if 013 int x_port = -1;14 int x_display = 0;15 int x_screen = 0;16 17 int18 show_x(buff, inso)19 char *buff;20 struct socket *inso;21 {22 if (x_port < 0) {23 lprint("X Redir: X not being redirected.\r\n");24 } else {25 lprint("X Redir: In sh/bash/zsh/etc. type: DISPLAY=%s:%d.%d; export DISPLAY\r\n",26 inet_ntoa(our_addr), x_port, x_screen);27 lprint("X Redir: In csh/tcsh/etc. type: setenv DISPLAY %s:%d.%d\r\n",28 inet_ntoa(our_addr), x_port, x_screen);29 if (x_display)30 lprint("X Redir: Redirecting to display %d\r\n", x_display);31 }32 33 return CFG_OK;34 }35 36 37 /*38 * XXX Allow more than one X redirection?39 */40 void41 redir_x(inaddr, start_port, display, screen)42 u_int32_t inaddr;43 int start_port;44 int display;45 int screen;46 {47 int i;48 49 if (x_port >= 0) {50 lprint("X Redir: X already being redirected.\r\n");51 show_x(0, 0);52 } else {53 for (i = 6001 + (start_port-1); i <= 6100; i++) {54 if (solisten(htons(i), inaddr, htons(6000 + display), 0)) {55 /* Success */56 x_port = i - 6000;57 x_display = display;58 x_screen = screen;59 show_x(0, 0);60 return;61 }62 }63 lprint("X Redir: Error: Couldn't redirect a port for X. Weird.\r\n");64 }65 }66 #endif67 10 68 11 #ifndef HAVE_INET_ATON … … 237 180 #endif 238 181 239 #if 0240 void241 snooze_hup(num)242 int num;243 {244 int s, ret;245 #ifndef NO_UNIX_SOCKETS246 struct sockaddr_un sock_un;247 #endif248 struct sockaddr_in sock_in;249 char buff[256];250 251 ret = -1;252 if (slirp_socket_passwd) {253 s = socket(AF_INET, SOCK_STREAM, 0);254 if (s < 0)255 slirp_exit(1);256 sock_in.sin_family = AF_INET;257 sock_in.sin_addr.s_addr = slirp_socket_addr;258 sock_in.sin_port = htons(slirp_socket_port);259 if (connect(s, (struct sockaddr *)&sock_in, sizeof(sock_in)) != 0)260 slirp_exit(1); /* just exit...*/261 sprintf(buff, "kill %s:%d", slirp_socket_passwd, slirp_socket_unit);262 write(s, buff, strlen(buff)+1);263 }264 #ifndef NO_UNIX_SOCKETS265 else {266 s = socket(AF_UNIX, SOCK_STREAM, 0);267 if (s < 0)268 slirp_exit(1);269 sock_un.sun_family = AF_UNIX;270 strcpy(sock_un.sun_path, socket_path);271 if (connect(s, (struct sockaddr *)&sock_un,272 sizeof(sock_un.sun_family) + sizeof(sock_un.sun_path)) != 0)273 slirp_exit(1);274 sprintf(buff, "kill none:%d", slirp_socket_unit);275 write(s, buff, strlen(buff)+1);276 }277 #endif278 slirp_exit(0);279 }280 281 282 void283 snooze()284 {285 sigset_t s;286 int i;287 288 /* Don't need our data anymore */289 /* XXX This makes SunOS barf */290 /* brk(0); */291 292 /* Close all fd's */293 for (i = 255; i >= 0; i--)294 close(i);295 296 signal(SIGQUIT, slirp_exit);297 signal(SIGHUP, snooze_hup);298 sigemptyset(&s);299 300 /* Wait for any signal */301 sigsuspend(&s);302 303 /* Just in case ... */304 exit(255);305 }306 307 void308 relay(s)309 int s;310 {311 char buf[8192];312 int n;313 fd_set readfds;314 struct ttys *ttyp;315 316 /* Don't need our data anymore */317 /* XXX This makes SunOS barf */318 /* brk(0); */319 320 signal(SIGQUIT, slirp_exit);321 signal(SIGHUP, slirp_exit);322 signal(SIGINT, slirp_exit);323 signal(SIGTERM, slirp_exit);324 325 /* Fudge to get term_raw and term_restore to work */326 if (NULL == (ttyp = tty_attach (0, slirp_tty))) {327 lprint ("Error: tty_attach failed in misc.c:relay()\r\n");328 slirp_exit (1);329 }330 ttyp->fd = 0;331 ttyp->flags |= TTY_CTTY;332 term_raw(ttyp);333 334 while (1) {335 FD_ZERO(&readfds);336 337 FD_SET(0, &readfds);338 FD_SET(s, &readfds);339 340 n = select(s+1, &readfds, (fd_set *)0, (fd_set *)0, (struct timeval *)0);341 342 if (n <= 0)343 slirp_exit(0);344 345 if (FD_ISSET(0, &readfds)) {346 n = read(0, buf, 8192);347 if (n <= 0)348 slirp_exit(0);349 n = writen(s, buf, n);350 if (n <= 0)351 slirp_exit(0);352 }353 354 if (FD_ISSET(s, &readfds)) {355 n = read(s, buf, 8192);356 if (n <= 0)357 slirp_exit(0);358 n = writen(0, buf, n);359 if (n <= 0)360 slirp_exit(0);361 }362 }363 364 /* Just in case.... */365 exit(1);366 }367 #endif368 369 182 #ifdef BAD_SPRINTF 370 183 … … 462 275 } 463 276 464 465 #if 0466 /*467 * invoke RSH468 */469 int470 rsh_exec(so,ns, user, host, args)471 struct socket *so;472 struct socket *ns;473 char *user;474 char *host;475 char *args;476 {477 int fd[2];478 int fd0[2];479 int s;480 char buff[256];481 482 DEBUG_CALL("rsh_exec");483 DEBUG_ARG("so = %lx", (long)so);484 485 if (pipe(fd)<0) {486 lprint("Error: pipe failed: %s\n", strerror(errno));487 return 0;488 }489 /* #ifdef HAVE_SOCKETPAIR */490 #if 1491 if (socketpair(PF_UNIX,SOCK_STREAM,0, fd0) == -1) {492 close(fd[0]);493 close(fd[1]);494 lprint("Error: openpty failed: %s\n", strerror(errno));495 return 0;496 }497 #else498 if (slirp_openpty(&fd0[0], &fd0[1]) == -1) {499 close(fd[0]);500 close(fd[1]);501 lprint("Error: openpty failed: %s\n", strerror(errno));502 return 0;503 }504 #endif505 506 switch(fork()) {507 case -1:508 lprint("Error: fork failed: %s\n", strerror(errno));509 close(fd[0]);510 close(fd[1]);511 close(fd0[0]);512 close(fd0[1]);513 return 0;514 515 case 0:516 close(fd[0]);517 close(fd0[0]);518 519 /* Set the DISPLAY */520 if (x_port >= 0) {521 #ifdef HAVE_SETENV522 sprintf(buff, "%s:%d.%d", inet_ntoa(our_addr), x_port, x_screen);523 setenv("DISPLAY", buff, 1);524 #else525 sprintf(buff, "DISPLAY=%s:%d.%d", inet_ntoa(our_addr), x_port, x_screen);526 putenv(buff);527 #endif528 }529 530 dup2(fd0[1], 0);531 dup2(fd0[1], 1);532 dup2(fd[1], 2);533 for (s = 3; s <= 255; s++)534 close(s);535 536 execlp("rsh","rsh","-l", user, host, args, NULL);537 538 /* Ooops, failed, let's tell the user why */539 540 sprintf(buff, "Error: execlp of %s failed: %s\n",541 "rsh", strerror(errno));542 write(2, buff, strlen(buff)+1);543 close(0); close(1); close(2); /* XXX */544 exit(1);545 546 default:547 close(fd[1]);548 close(fd0[1]);549 ns->s=fd[0];550 so->s=fd0[0];551 552 return 1;553 }554 }555 #endif -
trunk/src/VBox/Devices/Network/slirp/tcp_subr.c
r14329 r14331 675 675 } 676 676 677 #if 0678 case EMU_RLOGIN:679 /*680 * Rlogin emulation681 * First we accumulate all the initial option negotiation,682 * then fork_exec() rlogin according to the options683 */684 {685 int i, i2, n;686 char *ptr;687 char args[100];688 char term[100];689 struct sbuf *so_snd = &so->so_snd;690 struct sbuf *so_rcv = &so->so_rcv;691 692 /* First check if they have a priveladged port, or too much data has arrived */693 if (ntohs(so->so_lport) > 1023 || ntohs(so->so_lport) < 512 ||694 (m->m_len + so_rcv->sb_wptr) > (so_rcv->sb_data + so_rcv->sb_datalen)) {695 memcpy(so_snd->sb_wptr, "Permission denied\n", 18);696 so_snd->sb_wptr += 18;697 so_snd->sb_cc += 18;698 tcp_sockclosed(sototcpcb(so));699 m_free(m);700 return 0;701 }702 703 /* Append the current data */704 memcpy(so_rcv->sb_wptr, m->m_data, m->m_len);705 so_rcv->sb_wptr += m->m_len;706 so_rcv->sb_rptr += m->m_len;707 m_free(m);708 709 /*710 * Check if we have all the initial options,711 * and build argument list to rlogin while we're here712 */713 n = 0;714 ptr = so_rcv->sb_data;715 args[0] = 0;716 term[0] = 0;717 while (ptr < so_rcv->sb_wptr) {718 if (*ptr++ == 0) {719 n++;720 if (n == 2) {721 sprintf(args, "rlogin -l %s %s",722 ptr, inet_ntoa(so->so_faddr));723 } else if (n == 3) {724 i2 = so_rcv->sb_wptr - ptr;725 for (i = 0; i < i2; i++) {726 if (ptr[i] == '/') {727 ptr[i] = 0;728 #ifdef HAVE_SETENV729 sprintf(term, "%s", ptr);730 #else731 sprintf(term, "TERM=%s", ptr);732 #endif733 ptr[i] = '/';734 break;735 }736 }737 }738 }739 }740 741 if (n != 4)742 return 0;743 744 /* We have it, set our term variable and fork_exec() */745 #ifdef HAVE_SETENV746 setenv("TERM", term, 1);747 #else748 putenv(term);749 #endif750 fork_exec(so, args, 2);751 term[0] = 0;752 so->so_emu = 0;753 754 /* And finally, send the client a 0 character */755 so_snd->sb_wptr[0] = 0;756 so_snd->sb_wptr++;757 so_snd->sb_cc++;758 759 return 0;760 }761 762 case EMU_RSH:763 /*764 * rsh emulation765 * First we accumulate all the initial option negotiation,766 * then rsh_exec() rsh according to the options767 */768 {769 int n;770 char *ptr;771 char *user;772 char *args;773 struct sbuf *so_snd = &so->so_snd;774 struct sbuf *so_rcv = &so->so_rcv;775 776 /* First check if they have a priveladged port, or too much data has arrived */777 if (ntohs(so->so_lport) > 1023 || ntohs(so->so_lport) < 512 ||778 (m->m_len + so_rcv->sb_wptr) > (so_rcv->sb_data + so_rcv->sb_datalen)) {779 memcpy(so_snd->sb_wptr, "Permission denied\n", 18);780 so_snd->sb_wptr += 18;781 so_snd->sb_cc += 18;782 tcp_sockclosed(sototcpcb(so));783 m_free(m);784 return 0;785 }786 787 /* Append the current data */788 memcpy(so_rcv->sb_wptr, m->m_data, m->m_len);789 so_rcv->sb_wptr += m->m_len;790 so_rcv->sb_rptr += m->m_len;791 m_free(m);792 793 /*794 * Check if we have all the initial options,795 * and build argument list to rlogin while we're here796 */797 n = 0;798 ptr = so_rcv->sb_data;799 user="";800 args="";801 if (so->extra==NULL) {802 struct socket *ns;803 struct tcpcb* tp;804 int port=atoi(ptr);805 if (port <= 0) return 0;806 if (port > 1023 || port < 512) {807 memcpy(so_snd->sb_wptr, "Permission denied\n", 18);808 so_snd->sb_wptr += 18;809 so_snd->sb_cc += 18;810 tcp_sockclosed(sototcpcb(so));811 return 0;812 }813 if ((ns=socreate()) == NULL)814 return 0;815 if (tcp_attach(ns)<0) {816 free(ns);817 return 0;818 }819 820 ns->so_laddr=so->so_laddr;821 ns->so_lport=htons(port);822 823 (void) tcp_mss(sototcpcb(ns), 0);824 825 ns->so_faddr=so->so_faddr;826 ns->so_fport=htons(IPPORT_RESERVED-1); /* Use a fake port. */827 828 if (ns->so_faddr.s_addr == 0 ||829 ns->so_faddr.s_addr == loopback_addr.s_addr)830 ns->so_faddr = alias_addr;831 832 ns->so_iptos = tcp_tos(ns);833 tp = sototcpcb(ns);834 835 tcp_template(tp);836 837 /* Compute window scaling to request. */838 /* while (tp->request_r_scale < TCP_MAX_WINSHIFT &&839 * (TCP_MAXWIN << tp->request_r_scale) < so->so_rcv.sb_hiwat)840 * tp->request_r_scale++;841 */842 843 /*soisfconnecting(ns);*/844 845 tcpstat.tcps_connattempt++;846 847 tp->t_state = TCPS_SYN_SENT;848 tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT;849 tp->iss = tcp_iss;850 tcp_iss += TCP_ISSINCR/2;851 tcp_sendseqinit(tp);852 tcp_output(tp);853 so->extra=ns;854 }855 while (ptr < so_rcv->sb_wptr) {856 if (*ptr++ == 0) {857 n++;858 if (n == 2) {859 user=ptr;860 } else if (n == 3) {861 args=ptr;862 }863 }864 }865 866 if (n != 4)867 return 0;868 869 rsh_exec(so,so->extra, user, inet_ntoa(so->so_faddr), args);870 so->so_emu = 0;871 so->extra=NULL;872 873 /* And finally, send the client a 0 character */874 so_snd->sb_wptr[0] = 0;875 so_snd->sb_wptr++;876 so_snd->sb_cc++;877 878 return 0;879 }880 881 case EMU_CTL:882 {883 int num;884 struct sbuf *so_snd = &so->so_snd;885 struct sbuf *so_rcv = &so->so_rcv;886 887 /*888 * If there is binary data here, we save it in so->so_m889 */890 if (!so->so_m) {891 int rxlen;892 char *rxdata;893 rxdata=mtod(m, char *);894 for (rxlen=m->m_len; rxlen; rxlen--) {895 if (*rxdata++ & 0x80) {896 so->so_m = m;897 return 0;898 }899 }900 } /* if(so->so_m==NULL) */901 902 /*903 * Append the line904 */905 sbappendsb(so_rcv, m);906 907 /* To avoid going over the edge of the buffer, we reset it */908 if (so_snd->sb_cc == 0)909 so_snd->sb_wptr = so_snd->sb_rptr = so_snd->sb_data;910 911 /*912 * A bit of a hack:913 * If the first packet we get here is 1 byte long, then it914 * was done in telnet character mode, therefore we must echo915 * the characters as they come. Otherwise, we echo nothing,916 * because in linemode, the line is already echoed917 * XXX two or more control connections won't work918 */919 if (do_echo == -1) {920 if (m->m_len == 1) do_echo = 1;921 else do_echo = 0;922 }923 if (do_echo) {924 sbappendsb(so_snd, m);925 m_free(m);926 tcp_output(sototcpcb(so)); /* XXX */927 } else928 m_free(m);929 930 num = 0;931 while (num < so->so_rcv.sb_cc) {932 if (*(so->so_rcv.sb_rptr + num) == '\n' ||933 *(so->so_rcv.sb_rptr + num) == '\r') {934 int n;935 936 *(so_rcv->sb_rptr + num) = 0;937 if (ctl_password && !ctl_password_ok) {938 /* Need a password */939 if (sscanf(so_rcv->sb_rptr, "pass %256s", buff) == 1) {940 if (strcmp(buff, ctl_password) == 0) {941 ctl_password_ok = 1;942 n = sprintf(so_snd->sb_wptr,943 "Password OK.\r\n");944 goto do_prompt;945 }946 }947 n = sprintf(so_snd->sb_wptr,948 "Error: Password required, log on with \"pass PASSWORD\"\r\n");949 goto do_prompt;950 }951 cfg_quitting = 0;952 n = do_config(so_rcv->sb_rptr, so, PRN_SPRINTF);953 if (!cfg_quitting) {954 /* Register the printed data */955 do_prompt:956 so_snd->sb_cc += n;957 so_snd->sb_wptr += n;958 /* Add prompt */959 n = sprintf(so_snd->sb_wptr, "Slirp> ");960 so_snd->sb_cc += n;961 so_snd->sb_wptr += n;962 }963 /* Drop so_rcv data */964 so_rcv->sb_cc = 0;965 so_rcv->sb_wptr = so_rcv->sb_rptr = so_rcv->sb_data;966 tcp_output(sototcpcb(so)); /* Send the reply */967 }968 num++;969 }970 return 0;971 }972 #endif973 677 case EMU_FTP: /* ftp */ 974 678 *(m->m_data+m->m_len) = 0; /* NULL terminate for strstr */
Note:
See TracChangeset
for help on using the changeset viewer.