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

📄 options.c

📁 vxworks的tcpip协议栈源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* options.c - handles option processing for PPP *//* Copyright 1995 Wind River Systems, Inc. */#include "copyright_wrs.h"/* * Copyright (c) 1989 Carnegie Mellon University. * All rights reserved. * * Redistribution and use in source and binary forms are permitted * provided that the above copyright notice and this paragraph are * duplicated in all such forms and that any documentation, * advertising materials, and other materials related to such * distribution and use acknowledge that the software was developed * by Carnegie Mellon University.  The name of the * University may not be used to endorse or promote products derived * from this software without specific prior written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. *//*modification history--------------------01m,29nov95,vin  added code to accept hostnames for local_adrs & remote_adrs01l,05jul95,dzb  close fd's in setupapfile() and setchapfile().01k,23jun95,dzb  fixed setipcpfails() to access ipcp, not lcp.                 removed usehostname option.01j,16jun95,dzb  header file consolidation.  removed perror() references.01i,22may95,dzb  Changed pap/chap_require_file to just pap/chap_require.                 Changed to no params for reqpap() and reqchap().01h,05may95,dzb  removed parsing code in setupapfile() (original +ua file).		 fixed getword() for "/n", then EOF exit condition.		 added setpasswd() for setting passwd[].                 re-activated "login" option.01g,16feb95,dab  added stringdup() call for pap_file in setupapfile().01f,13feb95,dab  added call out to setchapfile() in parse_args() (SPR #4072).01e,09feb95,dab  removed "login" option.01d,07feb95,dab  only parse options struct if one is specified.01c,18jan95,dzb  ifdef'ed out usage().01b,16jan95,dab  ifdef'ed out options_from_user(), options_for_tty().01a,21dec94,dab  VxWorks port - first WRS version.	   +dzb  added: path for ppp header files, WRS copyright.*/#include <vxWorks.h>#include <stdlib.h>#include <stdio.h>#include <errno.h>#include <hostLib.h>#include <ioLib.h>#include <inetLib.h>#include <string.h>#include <sys/types.h>#include <sys/stat.h>#include <netinet/in.h>#include <ctype.h>#include "pppLib.h"#ifndef GIDSET_TYPE#define GIDSET_TYPE     int#endif/* * Prototypes */static int setdebug __ARGS((void));static int setkdebug __ARGS((void));static int setpassive __ARGS((void));static int setsilent __ARGS((void));static int noopt __ARGS((void));static int setnovj __ARGS((void));static int setnovjccomp __ARGS((void));static int setvjslots __ARGS((char *));static int nopap __ARGS((void));static int nochap __ARGS((void));static int reqpap __ARGS((void));static int reqchap __ARGS((void));static int setchapfile __ARGS((char *));static int setupapfile __ARGS((char *));static int setspeed __ARGS((int, int));static int noaccomp __ARGS((void));static int noasyncmap __ARGS((void));static int noipaddr __ARGS((void));static int nomagicnumber __ARGS((void));static int setasyncmap __ARGS((char *));static int setescape __ARGS((char *));static int setmru __ARGS((char *));static int setmtu __ARGS((char *));static int nomru __ARGS((void));static int nopcomp __ARGS((void));static int setnetmask __ARGS((char *));static int setname __ARGS((char *));static int setuser __ARGS((char *));static int setpasswd __ARGS((char *));static int setremote __ARGS((char *));static int readfile __ARGS((char *));static int setdefaultroute __ARGS((void));static int setproxyarp __ARGS((void));static int setdologin __ARGS((void));static int setlcptimeout __ARGS((char *));static int setlcpterm __ARGS((char *));static int setlcpconf __ARGS((char *));static int setlcpfails __ARGS((char *));static int setipcptimeout __ARGS((char *));static int setipcpterm __ARGS((char *));static int setipcpconf __ARGS((char *));static int setipcpfails __ARGS((char *));static int setpaptimeout __ARGS((char *));static int setpapreqs __ARGS((char *));static int setchaptimeout __ARGS((char *));static int setchapchal __ARGS((char *));static int setchapintv __ARGS((char *));static int setipcpaccl __ARGS((void));static int setipcpaccr __ARGS((void));static int setlcpechointv __ARGS((char *));static int setlcpechofails __ARGS((char *));static int number_option __ARGS((char *, long *, int));static int readable __ARGS((int fd));/* * Valid arguments. */static struct cmd {    char *cmd_name;    int num_args;    int (*cmd_func)();} cmds[] = {    {"no_all", 0, noopt},	/* Don't request/allow any options */    {"no_acc", 0, noaccomp},	/* Disable Address/Control compress */    {"no_asyncmap", 0, noasyncmap}, /* Disable asyncmap negotiation */    {"debug", 0, setdebug},	/* Enable the daemon debug mode */    {"driver_debug", 1, setkdebug}, /* Enable driver-level debugging */    {"no_ip", 0, noipaddr},	/* Disable IP address negotiation */    {"no_mn", 0, nomagicnumber}, /* Disable magic number negotiation */    {"no_mru", 0, nomru},	/* Disable mru negotiation */    {"passive_mode", 0, setpassive},	/* Set passive mode */    {"no_pc", 0, nopcomp},	/* Disable protocol field compress */    {"no_pap", 0, nopap},	/* Don't allow UPAP authentication with peer */    {"no_chap", 0, nochap},	/* Don't allow CHAP authentication with peer */    {"require_pap", 0, reqpap}, /* Require PAP auth from peer */    {"require_chap", 0, reqchap}, /* Require CHAP auth from peer */    {"no_vj", 0, setnovj},	/* disable VJ compression */    {"no_vjccomp", 0, setnovjccomp}, /* disable VJ connection-ID compression */    {"silent_mode", 0, setsilent},	/* Set silent mode */    {"defaultroute", 0, setdefaultroute}, /* Add default route */    {"proxyarp", 0, setproxyarp}, /* Add proxy ARP entry */    {"login", 0, setdologin}, /* Use system password database for UPAP */    {"ipcp_accept_local", 0, setipcpaccl}, /* Accept peer's address for us */    {"ipcp_accept_remote", 0, setipcpaccr}, /* Accept peer's address for it */    {"asyncmap", 1, setasyncmap}, /* set the desired async map */    {"vj_max_slots", 1, setvjslots}, /* Set maximum VJ header slots */    {"escape_chars", 1, setescape}, /* set chars to escape on transmission */    {"pap_file", 1, setupapfile}, /* Get PAP user and password from file */    {"chap_file", 1, setchapfile}, /* Get CHAP info */    {"mru", 1, setmru},		/* Set MRU value for negotiation */    {"mtu", 1, setmtu},		/* Set our MTU */    {"netmask", 1, setnetmask},	/* Set netmask */    {"local_auth_name", 1, setname}, /* Set local name for authentication */    {"pap_user_name", 1, setuser}, /* Set username for PAP auth with peer */    {"pap_passwd", 1, setpasswd}, /* Set password for PAP auth with peer */    {"remote_auth_name", 1, setremote}, /* Set remote name for authentication */    {"lcp_echo_failure", 1, setlcpechofails}, /* consecutive echo failures */    {"lcp_echo_interval", 1, setlcpechointv}, /* time for lcp echo events */    {"lcp_restart", 1, setlcptimeout}, /* Set timeout for LCP */    {"lcp_max_terminate", 1, setlcpterm}, /* Set max #xmits for term-reqs */    {"lcp_max_configure", 1, setlcpconf}, /* Set max #xmits for conf-reqs */    {"lcp_max_failure", 1, setlcpfails}, /* Set max #conf-naks for LCP */    {"ipcp_restart", 1, setipcptimeout}, /* Set timeout for IPCP */    {"ipcp_max_terminate", 1, setipcpterm}, /* Set max #xmits for term-reqs */    {"ipcp_max_configure", 1, setipcpconf}, /* Set max #xmits for conf-reqs */    {"ipcp_max_failure", 1, setipcpfails}, /* Set max #conf-naks for IPCP */    {"pap_restart", 1, setpaptimeout}, /* Set timeout for UPAP */    {"pap_max_authreq", 1, setpapreqs}, /* Set max #xmits for auth-reqs */    {"chap_restart", 1, setchaptimeout}, /* Set timeout for CHAP */    {"chap_max_challenge", 1, setchapchal}, /* Set max #xmits for challenge */    {"chap_interval", 1, setchapintv}, /* Set interval for rechallenge */    {NULL, 0, NULL}};#ifdef	notyet#ifndef IMPLEMENTATION#define IMPLEMENTATION ""#endifstatic char *usage_string = "\pppd version %s patch level %d%s\n\Usage: %s [ arguments ], where arguments are:\n\        <device>        Communicate over the named device\n\        <speed>         Set the baud rate to <speed>\n\        <loc>:<rem>     Set the local and/or remote interface IP\n\                        addresses.  Either one may be omitted.\n\        asyncmap <n>    Set the desired async map to hex <n>\n\        auth            Require authentication from peer\n\        connect <p>     Invoke shell command <p> to set up the serial line\n\        defaultroute    Add default route through interface\n\        file <f>        Take options from file <f>\n\        modem           Use modem control lines\n\        mru <n>         Set MRU value to <n> for negotiation\n\        netmask <n>     Set interface netmask to <n>\n\See pppd(8) for more options.\n\";#endif	/* notyet *//* * parse_args - parse a string of arguments, from the command * line or from a file. */intparse_args(unit, devname, local_addr, remote_addr, baud, options, fileName)    int unit;    char *devname;    char *local_addr;    char *remote_addr;    int baud;    PPP_OPTIONS *options;    char *fileName;{    if (options) {        if (options->flags & OPT_NO_ALL)            noopt();        if (options->flags & OPT_NO_ACC)            noaccomp();        if (options->flags & OPT_NO_ASYNCMAP)            noasyncmap();        if (options->flags & OPT_DEBUG)            setdebug();        if (options->flags & OPT_DRIVER_DEBUG)            setkdebug();        if (options->flags & OPT_NO_IP)            noipaddr();        if (options->flags & OPT_NO_MN)            nomagicnumber();        if (options->flags & OPT_NO_MRU)            nomru();        if (options->flags & OPT_PASSIVE_MODE)            setpassive();        if (options->flags & OPT_NO_PC)            nopcomp();        if (options->flags & OPT_NO_PAP)            nopap();        if (options->flags & OPT_NO_CHAP)            nochap();        if (options->flags & OPT_REQUIRE_PAP)            reqpap();        if (options->flags & OPT_REQUIRE_CHAP)            reqchap();        if (options->flags & OPT_NO_VJ)            setnovj();        if (options->flags & OPT_NO_VJCCOMP)            setnovjccomp();        if (options->flags & OPT_SILENT_MODE)            setsilent();        if (options->flags & OPT_DEFAULTROUTE)            setdefaultroute();        if (options->flags & OPT_PROXYARP)            setproxyarp();        if (options->flags & OPT_LOGIN)            setdologin();        if (options->flags & OPT_IPCP_ACCEPT_LOCAL)            setipcpaccl();        if (options->flags & OPT_IPCP_ACCEPT_REMOTE)            setipcpaccr();        if (options->asyncmap)            if (!setasyncmap(options->asyncmap)) {	        syslog(LOG_ERR, "asyncmap error");	        return 0;            }        if (options->vj_max_slots)            if (!setvjslots(options->vj_max_slots)) {	        syslog(LOG_ERR, "vj_max_slots error");	        return 0;            }        if (options->escape_chars)            if (!setescape(options->escape_chars)) {	        syslog(LOG_ERR, "escape chars error");	        return 0;            }        if (options->pap_file)            if (!setupapfile(options->pap_file)) {	        syslog(LOG_ERR, "pap file error");	        return 0;            }        if (options->chap_file)            if (!setchapfile(options->chap_file)) {                syslog(LOG_ERR, "chap file error");                return 0;            }        if (options->mru)            if (!setmru(options->mru)) {	        syslog(LOG_ERR, "mru error");	        return 0;            }        if (options->mtu)            if (!setmtu(options->mtu)) {	        syslog(LOG_ERR, "mtu error");	        return 0;            }        if (options->netmask)            if (!setnetmask(options->netmask)) {	        syslog(LOG_ERR, "netmask error");	        return 0;            }        if (options->local_auth_name)            if (!setname(options->local_auth_name)) {	        syslog(LOG_ERR, "local auth name error");	        return 0;            }        if (options->pap_user_name)            if (!setuser(options->pap_user_name)) {	        syslog(LOG_ERR, "pap auth name error");	        return 0;            }        if (options->pap_passwd)            if (!setpasswd(options->pap_passwd)) {	        syslog(LOG_ERR, "pap auth password error");	        return 0;            }        if (options->remote_auth_name)            if (!setremote(options->remote_auth_name)) {	        syslog(LOG_ERR, "remote auth name error");	        return 0;            }        if (options->lcp_echo_failure)            if (!setlcpechofails(options->lcp_echo_failure)) {	        syslog(LOG_ERR, "lcp echo failure error");	        return 0;            }        if (options->lcp_echo_interval)            if (!setlcpechointv(options->lcp_echo_interval)) {	        syslog(LOG_ERR, "lcp echo interval error");	        return 0;            }        if (options->lcp_restart)            if (!setlcptimeout(options->lcp_restart)) {	        syslog(LOG_ERR, "lcp timeout error");	        return 0;            }        if (options->lcp_max_terminate)            if (!setlcpterm(options->lcp_max_terminate)) {	        syslog(LOG_ERR, "lcp max terminate error");	        return 0;            }        if (options->lcp_max_configure)            if (!setlcpconf(options->lcp_max_configure)) {	        syslog(LOG_ERR, "lcp max configure error");	        return 0;            }        if (options->lcp_max_failure)            if (!setlcpfails(options->lcp_max_failure)) {	        syslog(LOG_ERR, "lcp max failure error");	        return 0;            }        if (options->ipcp_restart)            if (!setipcptimeout(options->ipcp_restart)) {	        syslog(LOG_ERR, "ipcp restart error");	        return 0;            }        if (options->ipcp_max_terminate)            if (!setipcpterm(options->ipcp_max_terminate)) {	        syslog(LOG_ERR, "ipcp max terminate error");	        return 0;            }        if (options->ipcp_max_configure)            if (!setipcpconf(options->ipcp_max_configure)) {	        syslog(LOG_ERR, "ipcp max configure error");	        return 0;            }        if (options->ipcp_max_failure)            if (!setipcpfails(options->ipcp_max_failure)) {	        syslog(LOG_ERR, "ipcp max failure error");	        return 0;            }        if (options->pap_restart)            if (!setpaptimeout(options->pap_restart)) {	        syslog(LOG_ERR, "pap restart error");	        return 0;            }        if (options->pap_max_authreq)            if (!setpapreqs(options->pap_max_authreq)) {	        syslog(LOG_ERR, "pap max reqs error");	        return 0;            }        if (options->chap_restart)            if (!setchaptimeout(options->chap_restart)) {	        syslog(LOG_ERR, "chap restart error");	        return 0;            }        if (options->chap_max_challenge)            if (!setchapchal(options->chap_max_challenge)) {	        syslog(LOG_ERR, "chap max challenge error");	        return 0;            }        if (options->chap_interval)            if (!setchapintv(options->chap_interval)) {	        syslog(LOG_ERR, "chap interval error");	        return 0;            }    }    if (fileName)        if (!readfile(fileName)) {	    syslog(LOG_ERR, "options file error");	    return 0;        }    if (!setdevname(devname)) {	syslog(LOG_ERR, "error setting device name");	return 0;    }    if (!setspeed(baud, 0)) {	syslog(LOG_ERR, "error setting baud rate");	return 0;    }    if (!setipaddr(local_addr, remote_addr)) {	syslog(LOG_ERR, "error setting address");	return 0;    }    return 1;}/* * usage - print out a message telling how to use the program. */#ifdef	notyetstatic voidusage(){    logMsg(usage_string, VERSION, PATCHLEVEL, IMPLEMENTATION,           "pppInit");}#endif	/* notyet *//* * options_from_file - Read a string of options from a file, * and interpret them. */intoptions_from_file(fileName, must_exist, check_prot)    char *fileName;    int must_exist;    int check_prot;{    FILE *f;    int i, newline;    struct cmd *cmdp;    char *argv[MAXARGS];    char args[MAXARGS][MAXWORDLEN];    char cmd[MAXWORDLEN];    if ((f = fopen(fileName, "r")) == NULL) {	if (!must_exist)	    return 1;        syslog(LOG_ERR, "%s: could not open\n", fileName);	return 0;    }    if (check_prot && !readable(fileno(f))) {        syslog(LOG_ERR, "%s: access denied\n", fileName);        fclose(f);        return 0;    }    while (getword(f, cmd, &newline, fileName)) {	/*	 * First see if it's a command.	 */	for (cmdp = cmds; cmdp->cmd_name; cmdp++)

⌨️ 快捷键说明

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