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

📄 ipxcp.c

📁 自己精简过的PPPD代码。在嵌入中应用可以更好的发挥。比原先的小了很多
💻 C
📖 第 1 页 / 共 3 页
字号:
		PUTLONG (wo->our_network, p);		orc = CONFNAK;/* * We don't have one. Reject the value. */	    } else		orc = CONFREJ;	    break;/* * The node number is required */	case IPX_NODE_NUMBER:	    /* if we wont negotiate the node number or the length is wrong	       then reject the option */	    if ( cilen != CILEN_NODEN ) {		orc = CONFREJ;		break;	    }	    copy_node (p, ho->his_node);	    ho->neg_node = 1;/* * If the remote does not have a number and we do then NAK it with the value * which we have for it. (We never have a default value of zero.) */	    if (zero_node (ho->his_node)) {		orc = CONFNAK;		copy_node (wo->his_node, p);		INCPTR (sizeof (wo->his_node), p);		break;	    }/* * If you have given me the expected network node number then I'll accept * it now. */	    if (compare_node (wo->his_node, ho->his_node)) {		orc = CONFACK;		ho->neg_node = 1;		INCPTR (sizeof (wo->his_node), p);		break;	    }/* * If his node number is the same as ours then ask him to try the next * value. */	    if (compare_node (ho->his_node, go->our_node)) {		inc_node (ho->his_node);		orc = CONFNAK;		copy_node (ho->his_node, p);		INCPTR (sizeof (wo->his_node), p);		break;	    }/* * If we don't accept a new value then NAK it. */	    if (! ao->accept_remote) {		copy_node (wo->his_node, p);		INCPTR (sizeof (wo->his_node), p);		orc = CONFNAK;		break;	    }	    orc = CONFACK;	    ho->neg_node = 1;	    INCPTR (sizeof (wo->his_node), p);	    break;/* * Compression is not desired at this time. It is always rejected. */	case IPX_COMPRESSION_PROTOCOL:	    orc = CONFREJ;	    break;/* * The routing protocol is a bitmask of various types. Any combination * of the values RIP_SAP and NLSP are permissible. 'IPX_NONE' for no * routing protocol must be specified only once. */	case IPX_ROUTER_PROTOCOL:	    if ( !ao->neg_router || cilen < CILEN_PROTOCOL ) {		orc = CONFREJ;		break;			    }	    GETSHORT (cishort, p);	    if (wo->neg_router == 0) {	        wo->neg_router = 1;		wo->router     = BIT(IPX_NONE);	    }	    if ((cishort == IPX_NONE && ho->router != 0) ||		(ho->router & BIT(IPX_NONE))) {		orc = CONFREJ;		break;	    }	    cishort = BIT(cishort);	    if (ho->router & cishort) {		orc = CONFREJ;		break;	    }	    ho->router	  |= cishort;	    ho->neg_router = 1;	    /* Finally do not allow a router protocol which we do not	       support. */	    if ((cishort & (ao->router | BIT(IPX_NONE))) == 0) {	        int protocol;		if (cishort == BIT(NLSP) &&		    (ao->router & BIT(RIP_SAP)) &&		    !wo->tried_rip) {		    protocol      = RIP_SAP;		    wo->tried_rip = 1;		} else		    protocol = IPX_NONE;		DECPTR (sizeof (u_int16_t), p);		PUTSHORT (protocol, p);		orc = CONFNAK;	    }	    break;/* * The router name is advisorary. Just accept it if it is not too large. */	case IPX_ROUTER_NAME:	    if (cilen >= CILEN_NAME) {		int name_size = cilen - CILEN_NAME;		if (name_size > sizeof (ho->name))		    name_size = sizeof (ho->name) - 1;		memset (ho->name, 0, sizeof (ho->name));		memcpy (ho->name, p, name_size);		ho->name [name_size] = '\0';		ho->neg_name = 1;		orc = CONFACK;		break;	    }	    orc = CONFREJ;	    break;/* * This is advisorary. */	case IPX_COMPLETE:	    if (cilen != CILEN_COMPLETE)		orc = CONFREJ;	    else {		ho->neg_complete = 1;		orc = CONFACK;	    }	    break;/* * All other entries are not known at this time. */	default:	    orc = CONFREJ;	    break;	}endswitch:	if (orc == CONFACK &&		/* Good CI */	    rc != CONFACK)		/*  but prior CI wasnt? */	    continue;			/* Don't send this one */	if (orc == CONFNAK) {		/* Nak this CI? */	    if (reject_if_disagree)	/* Getting fed up with sending NAKs? */		orc = CONFREJ;		/* Get tough if so */	    if (rc == CONFREJ)		/* Rejecting prior CI? */		continue;		/* Don't send this one */	    if (rc == CONFACK) {	/* Ack'd all prior CIs? */		rc  = CONFNAK;		/* Not anymore... */		ucp = inp;		/* Backup */	    }	}	if (orc == CONFREJ &&		/* Reject this CI */	    rc != CONFREJ) {		/*  but no prior ones? */	    rc = CONFREJ;	    ucp = inp;			/* Backup */	}	/* Need to move CI? */	if (ucp != cip)	    BCOPY(cip, ucp, cilen);	/* Move it */	/* Update output pointer */	INCPTR(cilen, ucp);    }    /*     * If we aren't rejecting this packet, and we want to negotiate     * their address, and they didn't send their address, then we     * send a NAK with a IPX_NODE_NUMBER option appended. We assume the     * input buffer is long enough that we can append the extra     * option safely.     */    if (rc != CONFREJ && !ho->neg_node &&	wo->req_nn && !reject_if_disagree) {	if (rc == CONFACK) {	    rc = CONFNAK;	    wo->req_nn = 0;		/* don't ask again */	    ucp = inp;			/* reset pointer */	}	if (zero_node (wo->his_node))	    inc_node (wo->his_node);	PUTCHAR (IPX_NODE_NUMBER, ucp);	PUTCHAR (CILEN_NODEN, ucp);	copy_node (wo->his_node, ucp);	INCPTR (sizeof (wo->his_node), ucp);    }    *len = ucp - inp;			/* Compute output length */    IPXCPDEBUG(("ipxcp: returning Configure-%s", CODENAME(rc)));    return (rc);			/* Return final code */}/* * ipxcp_up - IPXCP has come UP. * * Configure the IP network interface appropriately and bring it up. */static voidipxcp_up(f)    fsm *f;{    int unit = f->unit;    IPXCPDEBUG(("ipxcp: up"));    /* The default router protocol is RIP/SAP. */    if (ho->router == 0)        ho->router = BIT(RIP_SAP);    if (go->router == 0)        go->router = BIT(RIP_SAP);    /* Fetch the network number */    if (!ho->neg_nn)	ho->his_network = wo->his_network;    if (!ho->neg_node)	copy_node (wo->his_node, ho->his_node);    if (!wo->neg_node && !go->neg_node)	copy_node (wo->our_node, go->our_node);    if (zero_node (go->our_node)) {        static char errmsg[] = "Could not determine local IPX node address";	if (debug)	    error(errmsg);	ipxcp_close(f->unit, errmsg);	return;    }    go->network = go->our_network;    if (ho->his_network != 0 && ho->his_network > go->network)	go->network = ho->his_network;    if (go->network == 0) {        static char errmsg[] = "Can not determine network number";	if (debug)	    error(errmsg);	ipxcp_close (unit, errmsg);	return;    }    /* bring the interface up */    if (!sifup(unit)) {	if (debug)	    warn("sifup failed (IPX)");	ipxcp_close(unit, "Interface configuration failed");	return;    }    ipxcp_is_up = 1;    /* set the network number for IPX */    if (!sipxfaddr(unit, go->network, go->our_node)) {	if (debug)	    warn("sipxfaddr failed");	ipxcp_close(unit, "Interface configuration failed");	return;    }    np_up(f->unit, PPP_IPX);    /*     * Execute the ipx-up script, like this:     *	/etc/ppp/ipx-up interface tty speed local-IPX remote-IPX     */    ipxcp_script (f, _PATH_IPXUP);}/* * ipxcp_down - IPXCP has gone DOWN. * * Take the IP network interface down, clear its addresses * and delete routes through it. */static voidipxcp_down(f)    fsm *f;{    IPXCPDEBUG(("ipxcp: down"));    if (!ipxcp_is_up)	return;    ipxcp_is_up = 0;    np_down(f->unit, PPP_IPX);    cipxfaddr(f->unit);    sifnpmode(f->unit, PPP_IPX, NPMODE_DROP);    sifdown(f->unit);    ipxcp_script (f, _PATH_IPXDOWN);}/* * ipxcp_finished - possibly shut down the lower layers. */static voidipxcp_finished(f)    fsm *f;{    np_finished(f->unit, PPP_IPX);}/* * ipxcp_script - Execute a script with arguments * interface-name tty-name speed local-IPX remote-IPX networks. */static voidipxcp_script(f, script)    fsm *f;    char *script;{    char strspeed[32],	 strlocal[32],	   strremote[32];    char strnetwork[32], strpid[32];    char *argv[14],	 strproto_lcl[32], strproto_rmt[32];    slprintf(strpid, sizeof(strpid), "%d", getpid());    slprintf(strspeed, sizeof(strspeed),"%d", baud_rate);    strproto_lcl[0] = '\0';    if (go->neg_router && ((go->router & BIT(IPX_NONE)) == 0)) {	if (go->router & BIT(RIP_SAP))	    strlcpy (strproto_lcl, "RIP ", sizeof(strproto_lcl));	if (go->router & BIT(NLSP))	    strlcat (strproto_lcl, "NLSP ", sizeof(strproto_lcl));    }    if (strproto_lcl[0] == '\0')	strlcpy (strproto_lcl, "NONE ", sizeof(strproto_lcl));    strproto_lcl[strlen (strproto_lcl)-1] = '\0';    strproto_rmt[0] = '\0';    if (ho->neg_router && ((ho->router & BIT(IPX_NONE)) == 0)) {	if (ho->router & BIT(RIP_SAP))	    strlcpy (strproto_rmt, "RIP ", sizeof(strproto_rmt));	if (ho->router & BIT(NLSP))	    strlcat (strproto_rmt, "NLSP ", sizeof(strproto_rmt));    }    if (strproto_rmt[0] == '\0')	strlcpy (strproto_rmt, "NONE ", sizeof(strproto_rmt));    strproto_rmt[strlen (strproto_rmt)-1] = '\0';    strlcpy (strnetwork, ipx_ntoa (go->network), sizeof(strnetwork));    slprintf (strlocal, sizeof(strlocal), "%0.6B", go->our_node);    slprintf (strremote, sizeof(strremote), "%0.6B", ho->his_node);    argv[0]  = script;    argv[1]  = ifname;    argv[2]  = devnam;    argv[3]  = strspeed;    argv[4]  = strnetwork;    argv[5]  = strlocal;    argv[6]  = strremote;    argv[7]  = strproto_lcl;    argv[8]  = strproto_rmt;    argv[9]  = go->name;    argv[10] = ho->name;    argv[11] = ipparam;    argv[12] = strpid;    argv[13] = NULL;    run_program(script, argv, 0, NULL, NULL, 0);}/* * ipxcp_printpkt - print the contents of an IPXCP packet. */static char *ipxcp_codenames[] = {    "ConfReq", "ConfAck", "ConfNak", "ConfRej",    "TermReq", "TermAck", "CodeRej"};static intipxcp_printpkt(p, plen, printer, arg)    u_char *p;    int plen;    void (*printer) __P((void *, char *, ...));    void *arg;{    int code, id, len, olen;    u_char *pstart, *optend;    u_short cishort;    u_int32_t cilong;    if (plen < HEADERLEN)	return 0;    pstart = p;    GETCHAR(code, p);    GETCHAR(id, p);    GETSHORT(len, p);    if (len < HEADERLEN || len > plen)	return 0;    if (code >= 1 && code <= sizeof(ipxcp_codenames) / sizeof(char *))	printer(arg, " %s", ipxcp_codenames[code-1]);    else	printer(arg, " code=0x%x", code);    printer(arg, " id=0x%x", id);    len -= HEADERLEN;    switch (code) {    case CONFREQ:    case CONFACK:    case CONFNAK:    case CONFREJ:	/* print option list */	while (len >= 2) {	    GETCHAR(code, p);	    GETCHAR(olen, p);	    p -= 2;	    if (olen < CILEN_VOID || olen > len) {		break;	    }	    printer(arg, " <");	    len -= olen;	    optend = p + olen;	    switch (code) {	    case IPX_NETWORK_NUMBER:		if (olen == CILEN_NETN) {		    p += 2;		    GETLONG(cilong, p);		    printer (arg, "network %s", ipx_ntoa (cilong));		}		break;	    case IPX_NODE_NUMBER:		if (olen == CILEN_NODEN) {		    p += 2;		    printer (arg, "node ");		    while (p < optend) {			GETCHAR(code, p);			printer(arg, "%.2x", (int) (unsigned int) (unsigned char) code);		    }		}		break;	    case IPX_COMPRESSION_PROTOCOL:		if (olen == CILEN_COMPRESS) {		    p += 2;		    GETSHORT (cishort, p);		    printer (arg, "compression %d", (int) cishort);		}		break;	    case IPX_ROUTER_PROTOCOL:		if (olen == CILEN_PROTOCOL) {		    p += 2;		    GETSHORT (cishort, p);		    printer (arg, "router proto %d", (int) cishort);		}		break;	    case IPX_ROUTER_NAME:		if (olen >= CILEN_NAME) {		    p += 2;		    printer (arg, "router name \"");		    while (p < optend) {			GETCHAR(code, p);			if (code >= 0x20 && code <= 0x7E)			    printer (arg, "%c", (int) (unsigned int) (unsigned char) code);			else			    printer (arg, " \\%.2x", (int) (unsigned int) (unsigned char) code);		    }		    printer (arg, "\"");		}		break;	    case IPX_COMPLETE:		if (olen == CILEN_COMPLETE) {		    p += 2;		    printer (arg, "complete");		}		break;	    default:		break;	    }	    while (p < optend) {		GETCHAR(code, p);		printer(arg, " %.2x", (int) (unsigned int) (unsigned char) code);	    }	    printer(arg, ">");	}	break;    case TERMACK:    case TERMREQ:	if (len > 0 && *p >= ' ' && *p < 0x7f) {	    printer(arg, " ");	    print_string(p, len, printer, arg);	    p += len;	    len = 0;	}	break;    }    /* print the rest of the bytes in the packet */    for (; len > 0; --len) {	GETCHAR(code, p);	printer(arg, " %.2x", (int) (unsigned int) (unsigned char) code);    }    return p - pstart;}#endif /* ifdef IPX_CHANGE */

⌨️ 快捷键说明

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