⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nsplitd.c

📁 xen 3.2.2 源码
💻 C
📖 第 1 页 / 共 2 页
字号:
	    FD_ISSET_rjb(acto, &exfs))	{	exfs_actl:	exfs_acto:	    /* Thats all folks ... */	    break;	}	if (FD_ISSET_rjb(actc, &exfs))	{	exfs_ctl:	    close(actc);	    actc = 32;	    ctlcc = 0;	    continue;	}	/* Deal with reading */	if (FD_ISSET_rjb(acto, &rdfs))	{	    if ((oicc = read(acto, oiptr = oibuf, MAXSIZE)) < 0)		fault("read acto: %d: %s\n", oicc, strerror(errno));	    if (!oicc) goto exfs_acto;	    	    if (!gdbmode)	    {		int t;		assert((locc == 0) && (hocc == 0));		loptr = lobuf;		hoptr = hobuf;				if (lish>=0) {		    for(t=0; t<oicc; t++)			if (oibuf[t] & 0x80)			    hobuf[hocc++] = oibuf[t] & 0x7f;			else			    lobuf[locc++] = oibuf[t];		} else {		    for (t=0; t<oicc; t++)			lobuf[locc++] = oibuf[t];		}		/* If no high connection scratch that */		if (acth == 32)		    hocc=0;	    }	}	if (FD_ISSET_rjb(actl, &rdfs))	{	    if ((licc = read(actl, liptr = libuf, MAXSIZE)) < 0)		fault("read actl: %d: %s\n", licc, strerror(errno));	    if (!licc) goto exfs_actl;	}	if (FD_ISSET_rjb(acth, &rdfs))	{	    int t;	    	    if ((hicc = read(acth, hiptr = hibuf, MAXSIZE)) < 0)		fault("read acth: %d: %s\n", hicc, strerror(errno));	    if (!hicc) goto exfs_acth;	    for(t=0; t<hicc; t++)		hibuf[t] |= 0x80;	}	if (FD_ISSET_rjb(actg, &rdfs))	{	    if ((gicc = read(actg, giptr = gibuf, MAXSIZE)) < 0)		fault("read actg: %d: %s\n", gicc, strerror(errno));	    if (debug) write(1, giptr, gicc);		/* XXX */	    if (!gicc) goto exfs_actg;	}	if (FD_ISSET_rjb(actc, &rdfs))	{	    if ((ctlcc = read(actc, ctlbuf, MAXSIZE)) < 0)		fault("read actc: %d: %s\n", ctlcc, strerror(errno));	    if (debug) write(1, ctlbuf, gicc);	    if (!ctlcc) goto exfs_ctl;	    if (ctlbuf[0] == 'r') /* reset command */	    {		syslog(LOG_INFO, "reset command read, exiting");		if (debug) write(1, "reseting\n", sizeof("reseting\n"));		break;	    }	}		/* Deal with writing */	if (FD_ISSET_rjb(actg, &wrfs))	{	    /* We must be in gdb mode so send oi buffer data */	    assert(gdbmode);	    if (debug) write(2, oiptr, oicc);		/* XXX */	    if ((rc = write(actg, oiptr, oicc)) <= 0)		fault("write actg: %d: %s\n", rc, strerror(errno));	    oiptr += rc;	    oicc  -= rc;	}	if (FD_ISSET_rjb(actl, &wrfs))	{	    if ((rc = write(actl, loptr, locc)) <= 0)		fault("write actl: %d: %s\n", rc, strerror(errno));	    loptr += rc;	    locc  -= rc;	}	if (FD_ISSET_rjb(acth, &wrfs))	{	    if ((rc = write(acth, hoptr, hocc)) <= 0)		fault("write acth: %d: %s\n", rc, strerror(errno));	    hoptr += rc;	    hocc  -= rc;	}	if (FD_ISSET_rjb(acto, &wrfs))	{	    /* If in gdb mode send gdb input, otherwise send low data	       preferentially */	    if (gdbmode)	    {		assert(gicc);		if ((rc = write(acto, giptr, gicc)) <= 0)		    fault("write acto: %d: %s\n", rc, strerror(errno));		giptr += rc;		gicc  -= rc;	    }	    else	    {		if (licc)		{		    if ((rc = write(acto, liptr, licc)) <= 0)			fault("write acto: %d: %s\n", rc, strerror(errno));		    liptr += rc;		    licc  -= rc;		}		else		{		    assert(hicc);		    if ((rc = write(acto, hiptr, hicc)) <= 0)			fault("write acto: %d: %s\n", rc, strerror(errno));		    hiptr += rc;		    hicc  -= rc;		}	    }	}		/* Deals with new connections */	if ((acth == 32) && lish>=0 && (FD_ISSET_rjb(lish, &rdfs)))	{	    fromlen = sizeof(from);	    if ((acth = accept(lish, &from, &fromlen)) < 0)	    {		syslog(LOG_WARNING, "accept: %m");		acth = 32;	    }	    else	    {		noblock(acth);		hicc = hocc = 0;		syslog(LOG_INFO, "highbit client peer is %s:%u\n",		       inet_ntoa(from.sin_addr), ntohs(from.sin_port));	    }	}		if ((actg == 32) && (FD_ISSET_rjb(lisg, &rdfs)))	{	    fromlen = sizeof(from);	    if ((actg = accept(lisg, &from, &fromlen)) < 0)	    {		syslog(LOG_WARNING, "accept: %m");		actg = 32;	    }	    else	    {		noblock(actg);		gicc = 0;		gdbmode = TRUE;		syslog(LOG_INFO, "gdb client peer is %s:%u\n",		       inet_ntoa(from.sin_addr), ntohs(from.sin_port));	    }	}	if ((actc == 32) && (FD_ISSET_rjb(lisc, &rdfs)))	{	    fromlen = sizeof(from);	    if ((actc = accept(lisc, &from, &fromlen)) < 0)	    {		syslog(LOG_WARNING, "accept (ctl): %m");		actc = 32;	    }	    else	    {		noblock(actc);		syslog(LOG_INFO, "ctl client peer is %s:%u\n",		       inet_ntoa(from.sin_addr), ntohs(from.sin_port));	    }	}	    	/* Back to top of loop */    }        /* We are bailing because one of the primary connections has gone     * away. We close these all explicitly here because that way the     * timeout on reusing the port numbers is smnaller. */        close(acth);    close(actg);    /* XXX AND: why are we closing all these "character counts" ?? */    close(gicc);    close(oicc);    close(licc);    close(locc);    close(hicc);    close(hocc);}/* * ------------------------------------------------------------ */int main(int argc, char **argv){    /* In general, suffix "l" is low channel, "h" is high channel, "g"     * is gdb channel, "c" is control channel and "o" is output channel.     */    struct sockaddr_in		from;    int				infd = 0, outfd;    unsigned short		portl, porth, portg, portc, porto;    int				on = 1, c;    char			*outname, *outservice;    int				fromlen;    int				lish, lisg, lisc;#if 0    FILE			*newerr;#endif /* 0 */        prog_name = argv[0];    if (isatty(infd))	usage();    /* Here, then not just a simple idiot. */    signal(SIGPIPE, SIG_IGN);    openlog(prog_name, LOG_PID, LOG_DAEMON);    fromlen = sizeof(from);    if (getsockname(infd, &from, &fromlen) < 0)	fault("getsockname: %s", strerror(errno));    if ((fromlen != sizeof(from)) || (from.sin_family != AF_INET))	fault("not an inet socket (family=%d)\n", from.sin_family);        portl = ntohs(from.sin_port);    porth = portl+1;    portg = porth+1;    portc = portg+1;    fromlen = sizeof(from);    if (getpeername(infd, &from, &fromlen) < 0)	fault("getpeername: %s", strerror(errno));    if ((fromlen != sizeof(from)) || (from.sin_family != AF_INET))	fault("not an inet socket (family=%d)\n", from.sin_family);    syslog(LOG_INFO, "on port %u peer is %s:%u\n", portl,	   inet_ntoa(from.sin_addr), ntohs(from.sin_port));        if (setsockopt(infd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof (on)) < 0)	syslog(LOG_WARNING, "setsockopt (SO_KEEPALIVE): %m");    /* from here on, we map stderr to output on the connection so we can     * report errors to the remote user.     */#if 0    if (!(newerr = fdopen(infd, "w")))	syslog(LOG_WARNING, "fdopen: %m");    else	*stderr = *newerr;#endif	    while((c = getopt(argc, argv, "d8h:g:c:")) != EOF)    {	switch(c)	{	case 'd':	    debug++;	    break;	    	case 'h':	    /* high bit port */	    if (getservice(optarg, &porth) < 0)		fault("getservice failed (high port '%s')\n", optarg);	    break;	    	case 'g':	    /* gdb port */	    if (getservice(optarg, &portg) < 0)		fault("getservice failed (gdb port '%s')\n", optarg);	    break;	case 'c':	    /* control port */	    if (getservice(optarg, &portc) < 0)		fault("getservice failed (control port '%s')\n", optarg);	    break;	case '8':	    /* 8-bit clean; no high port */	    porth=0;	    break;	default:	    fault("bad argument list!\n");	}    }        if (argc != optind + 1)	fault("unparsed arguments (%d!=%d)\n", argc, optind+1);    outname = argv[optind];    if (!(outservice = strchr(outname, ':')))	fault("output arg '%s' doesn't contain ':'\n", outname);    *outservice++ = 0;    if (getservice(outservice, &porto) < 0)	fault("getservice failed (output port '%s')\n", outservice);        /* Time to start the sockets */    if (porth) {	lish  = startlistening(porth);    } else {	lish  = -1;    }    lisg  = startlistening(portg);    lisc  = startlistening(portc);        outfd = connect_host(outname, porto);        doit(infd, outfd, lish, lisg, lisc);    syslog(LOG_INFO, "terminating normally\n");    fclose(stderr);    closelog();    exit(0); }/* End $Id: nsplitd.c,v 2.6 1998/09/17 14:28:37 sde1000 Exp $ */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -