2 * options.c - handles option processing for PPP.
4 * Copyright (c) 1989 Carnegie Mellon University.
7 * Redistribution and use in source and binary forms are permitted
8 * provided that the above copyright notice and this paragraph are
9 * duplicated in all such forms and that any documentation,
10 * advertising materials, and other materials related to such
11 * distribution and use acknowledge that the software was developed
12 * by Carnegie Mellon University. The name of the
13 * University may not be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 static char rcsid[] = "$Id: options.c,v 1.15 1994/09/16 02:34:52 paulus Exp $";
34 #include <sys/types.h>
36 #include <netinet/in.h>
40 #include "pathnames.h"
41 #include "patchlevel.h"
53 char *strdup __ARGS((char *));
57 #define GIDSET_TYPE gid_t
61 * Option variables and default values.
63 int debug = 0; /* Debug flag */
64 int kdebugflag = 0; /* Tell kernel to print debug messages */
65 int default_device = 1; /* Using /dev/tty or equivalent */
66 char devnam[MAXPATHLEN] = "/dev/tty"; /* Device name */
67 int crtscts = 0; /* Use hardware flow control */
68 int modem = 1; /* Use modem control lines */
69 int inspeed = 0; /* Input/Output speed requested */
70 uint32 netmask = 0; /* IP netmask to set on interface */
71 int lockflag = 0; /* Create lock file to lock the serial dev */
72 int nodetach = 0; /* Don't detach from controlling tty */
73 char *connector = NULL; /* Script to establish physical link */
74 char *disconnector = NULL; /* Script to disestablish physical link */
75 char user[MAXNAMELEN]; /* Username for PAP */
76 char passwd[MAXSECRETLEN]; /* Password for PAP */
77 int auth_required = 0; /* Peer is required to authenticate */
78 int defaultroute = 0; /* assign default route through interface */
79 int proxyarp = 0; /* Set up proxy ARP entry for peer */
80 int persist = 0; /* Reopen link after it goes down */
81 int uselogin = 0; /* Use /etc/passwd for checking PAP */
82 int lcp_echo_interval = 0; /* Interval between LCP echo-requests */
83 int lcp_echo_fails = 0; /* Tolerance to unanswered echo-requests */
84 char our_name[MAXNAMELEN]; /* Our name for authentication purposes */
85 char remote_name[MAXNAMELEN]; /* Peer's name for authentication */
86 int usehostname = 0; /* Use hostname for our_name */
87 int disable_defaultip = 0; /* Don't use hostname for default IP adrs */
92 static int setdebug __ARGS((void));
93 static int setkdebug __ARGS((char **));
94 static int setpassive __ARGS((void));
95 static int setsilent __ARGS((void));
96 static int noopt __ARGS((void));
97 static int setnovj __ARGS((void));
98 static int setnovjccomp __ARGS((void));
99 static int setvjslots __ARGS((char **));
100 static int reqpap __ARGS((void));
101 static int nopap __ARGS((void));
102 static int setupapfile __ARGS((char **));
103 static int nochap __ARGS((void));
104 static int reqchap __ARGS((void));
105 static int setspeed __ARGS((char *));
106 static int noaccomp __ARGS((void));
107 static int noasyncmap __ARGS((void));
108 static int noipaddr __ARGS((void));
109 static int nomagicnumber __ARGS((void));
110 static int setasyncmap __ARGS((char **));
111 static int setescape __ARGS((char **));
112 static int setmru __ARGS((char **));
113 static int setmtu __ARGS((char **));
114 static int nomru __ARGS((void));
115 static int nopcomp __ARGS((void));
116 static int setconnector __ARGS((char **));
117 static int setdisconnector __ARGS((char **));
118 static int setdomain __ARGS((char **));
119 static int setnetmask __ARGS((char **));
120 static int setcrtscts __ARGS((void));
121 static int setnocrtscts __ARGS((void));
122 static int setxonxoff __ARGS((void));
123 static int setnodetach __ARGS((void));
124 static int setmodem __ARGS((void));
125 static int setlocal __ARGS((void));
126 static int setlock __ARGS((void));
127 static int setname __ARGS((char **));
128 static int setuser __ARGS((char **));
129 static int setremote __ARGS((char **));
130 static int setauth __ARGS((void));
131 static int readfile __ARGS((char **));
132 static int setdefaultroute __ARGS((void));
133 static int setproxyarp __ARGS((void));
134 static int setpersist __ARGS((void));
135 static int setdologin __ARGS((void));
136 static int setusehostname __ARGS((void));
137 static int setnoipdflt __ARGS((void));
138 static int setlcptimeout __ARGS((char **));
139 static int setlcpterm __ARGS((char **));
140 static int setlcpconf __ARGS((char **));
141 static int setlcpfails __ARGS((char **));
142 static int setipcptimeout __ARGS((char **));
143 static int setipcpterm __ARGS((char **));
144 static int setipcpconf __ARGS((char **));
145 static int setipcpfails __ARGS((char **));
146 static int setpaptimeout __ARGS((char **));
147 static int setpapreqs __ARGS((char **));
148 static int setchaptimeout __ARGS((char **));
149 static int setchapchal __ARGS((char **));
150 static int setchapintv __ARGS((char **));
151 static int setipcpaccl __ARGS((void));
152 static int setipcpaccr __ARGS((void));
153 static int setlcpechointv __ARGS((char **));
154 static int setlcpechofails __ARGS((char **));
155 static int setbsdcomp __ARGS((char **));
156 static int setnobsdcomp __ARGS((void));
158 static int number_option __ARGS((char *, long *, int));
159 static int readable __ARGS((int fd));
169 {"-all", 0, noopt}, /* Don't request/allow any options */
170 {"-ac", 0, noaccomp}, /* Disable Address/Control compress */
171 {"-am", 0, noasyncmap}, /* Disable asyncmap negotiation */
172 {"-as", 1, setasyncmap}, /* set the desired async map */
173 {"-d", 0, setdebug}, /* Increase debugging level */
174 {"-detach", 0, setnodetach}, /* don't fork */
175 {"-ip", 0, noipaddr}, /* Disable IP address negotiation */
176 {"-mn", 0, nomagicnumber}, /* Disable magic number negotiation */
177 {"-mru", 0, nomru}, /* Disable mru negotiation */
178 {"-p", 0, setpassive}, /* Set passive mode */
179 {"-pc", 0, nopcomp}, /* Disable protocol field compress */
180 {"+ua", 1, setupapfile}, /* Get PAP user and password from file */
181 {"+pap", 0, reqpap}, /* Require PAP auth from peer */
182 {"-pap", 0, nopap}, /* Don't allow UPAP authentication with peer */
183 {"+chap", 0, reqchap}, /* Require CHAP authentication from peer */
184 {"-chap", 0, nochap}, /* Don't allow CHAP authentication with peer */
185 {"-vj", 0, setnovj}, /* disable VJ compression */
186 {"-vjccomp", 0, setnovjccomp}, /* disable VJ connection-ID compression */
187 {"vj-max-slots", 1, setvjslots}, /* Set maximum VJ header slots */
188 {"asyncmap", 1, setasyncmap}, /* set the desired async map */
189 {"escape", 1, setescape}, /* set chars to escape on transmission */
190 {"connect", 1, setconnector}, /* A program to set up a connection */
191 {"disconnect", 1, setdisconnector}, /* program to disconnect serial dev. */
192 {"crtscts", 0, setcrtscts}, /* set h/w flow control */
193 {"-crtscts", 0, setnocrtscts}, /* clear h/w flow control */
194 {"xonxoff", 0, setxonxoff}, /* set s/w flow control */
195 {"debug", 0, setdebug}, /* Increase debugging level */
196 {"kdebug", 1, setkdebug}, /* Enable kernel-level debugging */
197 {"domain", 1, setdomain}, /* Add given domain name to hostname*/
198 {"mru", 1, setmru}, /* Set MRU value for negotiation */
199 {"mtu", 1, setmtu}, /* Set our MTU */
200 {"netmask", 1, setnetmask}, /* set netmask */
201 {"passive", 0, setpassive}, /* Set passive mode */
202 {"silent", 0, setsilent}, /* Set silent mode */
203 {"modem", 0, setmodem}, /* Use modem control lines */
204 {"local", 0, setlocal}, /* Don't use modem control lines */
205 {"lock", 0, setlock}, /* Lock serial device (with lock file) */
206 {"name", 1, setname}, /* Set local name for authentication */
207 {"user", 1, setuser}, /* Set username for PAP auth with peer */
208 {"usehostname", 0, setusehostname}, /* Must use hostname for auth. */
209 {"remotename", 1, setremote}, /* Set remote name for authentication */
210 {"auth", 0, setauth}, /* Require authentication from peer */
211 {"file", 1, readfile}, /* Take options from a file */
212 {"defaultroute", 0, setdefaultroute}, /* Add default route */
213 {"proxyarp", 0, setproxyarp}, /* Add proxy ARP entry */
214 {"persist", 0, setpersist}, /* Keep on reopening connection after close */
215 {"login", 0, setdologin}, /* Use system password database for UPAP */
216 {"noipdefault", 0, setnoipdflt}, /* Don't use name for default IP adrs */
217 {"lcp-echo-failure", 1, setlcpechofails}, /* consecutive echo failures */
218 {"lcp-echo-interval", 1, setlcpechointv}, /* time for lcp echo events */
219 {"lcp-restart", 1, setlcptimeout}, /* Set timeout for LCP */
220 {"lcp-max-terminate", 1, setlcpterm}, /* Set max #xmits for term-reqs */
221 {"lcp-max-configure", 1, setlcpconf}, /* Set max #xmits for conf-reqs */
222 {"lcp-max-failure", 1, setlcpfails}, /* Set max #conf-naks for LCP */
223 {"ipcp-restart", 1, setipcptimeout}, /* Set timeout for IPCP */
224 {"ipcp-max-terminate", 1, setipcpterm}, /* Set max #xmits for term-reqs */
225 {"ipcp-max-configure", 1, setipcpconf}, /* Set max #xmits for conf-reqs */
226 {"ipcp-max-failure", 1, setipcpfails}, /* Set max #conf-naks for IPCP */
227 {"pap-restart", 1, setpaptimeout}, /* Set timeout for UPAP */
228 {"pap-max-authreq", 1, setpapreqs}, /* Set max #xmits for auth-reqs */
229 {"chap-restart", 1, setchaptimeout}, /* Set timeout for CHAP */
230 {"chap-max-challenge", 1, setchapchal}, /* Set max #xmits for challenge */
231 {"chap-interval", 1, setchapintv}, /* Set interval for rechallenge */
232 {"ipcp-accept-local", 0, setipcpaccl}, /* Accept peer's address for us */
233 {"ipcp-accept-remote", 0, setipcpaccr}, /* Accept peer's address for it */
234 {"bsdcomp", 1, setbsdcomp}, /* request BSD-Compress */
235 {"-bsdcomp", 0, setnobsdcomp}, /* don't allow BSD-Compress */
240 #ifndef IMPLEMENTATION
241 #define IMPLEMENTATION ""
244 static char *usage_string = "\
245 pppd version %s patch level %d%s\n\
246 Usage: %s [ arguments ], where arguments are:\n\
247 <device> Communicate over the named device\n\
248 <speed> Set the baud rate to <speed>\n\
249 <loc>:<rem> Set the local and/or remote interface IP\n\
250 addresses. Either one may be omitted.\n\
251 asyncmap <n> Set the desired async map to hex <n>\n\
252 auth Require authentication from peer\n\
253 connect <p> Invoke shell command <p> to set up the serial line\n\
254 crtscts Use hardware RTS/CTS flow control\n\
255 defaultroute Add default route through interface\n\
256 file <f> Take options from file <f>\n\
257 modem Use modem control lines\n\
258 mru <n> Set MRU value to <n> for negotiation\n\
259 netmask <n> Set interface netmask to <n>\n\
260 See pppd(8) for more options.\n\
265 * parse_args - parse a string of arguments, from the command
266 * line or from a file.
269 parse_args(argc, argv)
282 * First see if it's a command.
284 for (cmdp = cmds; cmdp->cmd_name; cmdp++)
285 if (!strcmp(arg, cmdp->cmd_name))
288 if (cmdp->cmd_name != NULL) {
289 if (argc < cmdp->num_args) {
290 fprintf(stderr, "Too few parameters for command %s\n", arg);
293 if (!(*cmdp->cmd_func)(argv))
295 argc -= cmdp->num_args;
296 argv += cmdp->num_args;
300 * Maybe a tty name, speed or IP address?
302 if ((ret = setdevname(arg)) == 0
303 && (ret = setspeed(arg)) == 0
304 && (ret = setipaddr(arg)) == 0) {
305 fprintf(stderr, "%s: unrecognized command\n", arg);
309 if (ret < 0) /* error */
317 * usage - print out a message telling how to use the program.
321 fprintf(stderr, usage_string, VERSION, PATCHLEVEL, IMPLEMENTATION,
326 * options_from_file - Read a string of options from a file,
327 * and interpret them.
330 options_from_file(filename, must_exist, check_prot)
339 char args[MAXARGS][MAXWORDLEN];
340 char cmd[MAXWORDLEN];
342 if ((f = fopen(filename, "r")) == NULL) {
343 if (!must_exist && errno == ENOENT)
348 if (check_prot && !readable(fileno(f))) {
349 fprintf(stderr, "%s: access denied\n", filename);
354 while (getword(f, cmd, &newline, filename)) {
356 * First see if it's a command.
358 for (cmdp = cmds; cmdp->cmd_name; cmdp++)
359 if (!strcmp(cmd, cmdp->cmd_name))
362 if (cmdp->cmd_name != NULL) {
363 for (i = 0; i < cmdp->num_args; ++i) {
364 if (!getword(f, args[i], &newline, filename)) {
366 "In file %s: too few parameters for command %s\n",
373 if (!(*cmdp->cmd_func)(argv)) {
380 * Maybe a tty name, speed or IP address?
382 if ((ret = setdevname(cmd)) == 0
383 && (ret = setspeed(cmd)) == 0
384 && (ret = setipaddr(cmd)) == 0) {
385 fprintf(stderr, "In file %s: unrecognized command %s\n",
390 if (ret < 0) /* error */
398 * options_from_user - See if the use has a ~/.ppprc file,
399 * and if so, interpret options from it.
404 char *user, *path, *file;
408 pw = getpwuid(getuid());
409 if (pw == NULL || (user = pw->pw_dir) == NULL || user[0] == 0)
411 file = _PATH_USEROPT;
412 path = malloc(strlen(user) + strlen(file) + 2);
414 novm("init file name");
418 ret = options_from_file(path, 0, 1);
424 * options_for_tty - See if an options file exists for the serial
425 * device, and if so, interpret options from it.
433 dev = strrchr(devnam, '/');
438 if (strcmp(dev, "tty") == 0)
439 return 1; /* don't look for /etc/ppp/options.tty */
440 path = malloc(strlen(_PATH_TTYOPT) + strlen(dev) + 1);
442 novm("tty init file name");
443 strcpy(path, _PATH_TTYOPT);
445 ret = options_from_file(path, 0, 0);
451 * readable - check if a file is readable by the real user.
460 GIDSET_TYPE groups[NGROUPS_MAX];
465 if (fstat(fd, &sbuf) != 0)
467 if (sbuf.st_uid == uid)
468 return sbuf.st_mode & S_IRUSR;
469 if (sbuf.st_gid == getgid())
470 return sbuf.st_mode & S_IRGRP;
471 ngroups = getgroups(NGROUPS_MAX, groups);
472 for (i = 0; i < ngroups; ++i)
473 if (sbuf.st_gid == groups[i])
474 return sbuf.st_mode & S_IRGRP;
475 return sbuf.st_mode & S_IROTH;
479 * Read a word from a file.
480 * Words are delimited by white-space or by quotes (").
481 * Quotes, white-space and \ may be escaped with \.
482 * \<newline> is ignored.
485 getword(f, word, newlinep, filename)
500 * First skip white-space and comments
502 while ((c = getc(f)) != EOF) {
505 * \<newline> is ignored; \ followed by anything else
508 if ((c = getc(f)) == '\n')
515 *newlinep = 1; /* next word starts a line */
517 /* comment - ignore until EOF or \n */
518 while ((c = getc(f)) != EOF && c != '\n')
523 } else if (!isspace(c))
528 * End of file or error - fail
540 * Is this character escaped by \ ?
544 --len; /* ignore \<newline> */
545 else if (c == '"' || isspace(c) || c == '\\')
546 word[len-1] = c; /* put special char in word */
548 if (len < MAXWORDLEN-1)
553 } else if (c == '"') {
555 } else if (!quoted && (isspace(c) || c == '#')) {
559 if (len < MAXWORDLEN-1)
565 if ((c = getc(f)) == EOF)
574 if (len >= MAXWORDLEN) {
575 word[MAXWORDLEN-1] = 0;
576 fprintf(stderr, "%s: warning: word in file %s too long (%.20s...)\n",
577 progname, filename, word);
585 * number_option - parse a numeric parameter for an option
588 number_option(str, valp, base)
595 *valp = strtol(str, &ptr, base);
597 fprintf(stderr, "%s: invalid number: %s\n", progname, str);
605 * int_option - like number_option, but valp is int *,
606 * the base is assumed to be 0, and *valp is not changed
607 * if there is an error.
610 int_option(str, valp)
616 if (!number_option(str, &v, 0))
624 * The following procedures execute commands.
628 * readfile - take commands from a file.
634 return options_from_file(*argv, 1, 1);
638 * setdebug - Set debug (command line argument).
648 * setkdebug - Set kernel debugging level.
654 return int_option(*argv, &kdebugflag);
658 * noopt - Disable all options.
663 BZERO((char *) &lcp_wantoptions[0], sizeof (struct lcp_options));
664 BZERO((char *) &lcp_allowoptions[0], sizeof (struct lcp_options));
665 BZERO((char *) &ipcp_wantoptions[0], sizeof (struct ipcp_options));
666 BZERO((char *) &ipcp_allowoptions[0], sizeof (struct ipcp_options));
671 * noaccomp - Disable Address/Control field compression negotiation.
676 lcp_wantoptions[0].neg_accompression = 0;
677 lcp_allowoptions[0].neg_accompression = 0;
683 * noasyncmap - Disable async map negotiation.
688 lcp_wantoptions[0].neg_asyncmap = 0;
689 lcp_allowoptions[0].neg_asyncmap = 0;
695 * noipaddr - Disable IP address negotiation.
700 ipcp_wantoptions[0].neg_addr = 0;
701 ipcp_allowoptions[0].neg_addr = 0;
707 * nomagicnumber - Disable magic number negotiation.
712 lcp_wantoptions[0].neg_magicnumber = 0;
713 lcp_allowoptions[0].neg_magicnumber = 0;
719 * nomru - Disable mru negotiation.
724 lcp_wantoptions[0].neg_mru = 0;
725 lcp_allowoptions[0].neg_mru = 0;
731 * setmru - Set MRU for negotiation.
739 if (!number_option(*argv, &mru, 0))
741 lcp_wantoptions[0].mru = mru;
742 lcp_wantoptions[0].neg_mru = 1;
748 * setmru - Set the largest MTU we'll use.
756 if (!number_option(*argv, &mtu, 0))
758 if (mtu < MINMRU || mtu > MAXMRU) {
759 fprintf(stderr, "mtu option value of %d is too %s\n", mtu,
760 (mtu < MINMRU? "small": "large"));
763 lcp_allowoptions[0].mru = mtu;
769 * nopcomp - Disable Protocol field compression negotiation.
774 lcp_wantoptions[0].neg_pcompression = 0;
775 lcp_allowoptions[0].neg_pcompression = 0;
781 * setpassive - Set passive mode (don't give up if we time out sending
782 * LCP configure-requests).
787 lcp_wantoptions[0].passive = 1;
793 * setsilent - Set silent mode (don't start sending LCP configure-requests
794 * until we get one from the peer).
799 lcp_wantoptions[0].silent = 1;
805 * nopap - Disable PAP authentication with peer.
810 lcp_allowoptions[0].neg_upap = 0;
816 * reqpap - Require PAP authentication from peer.
821 lcp_wantoptions[0].neg_upap = 1;
827 * setupapfile - specifies UPAP info for authenticating with peer.
836 lcp_allowoptions[0].neg_upap = 1;
838 /* open user info file */
839 if ((ufile = fopen(*argv, "r")) == NULL) {
840 fprintf(stderr, "unable to open user login data file %s\n", *argv);
843 if (!readable(fileno(ufile))) {
844 fprintf(stderr, "%s: access denied\n", *argv);
847 check_access(ufile, *argv);
850 if (fgets(user, MAXNAMELEN - 1, ufile) == NULL
851 || fgets(passwd, MAXSECRETLEN - 1, ufile) == NULL){
852 fprintf(stderr, "Unable to read user login data file %s.\n", *argv);
857 /* get rid of newlines */
859 if (l > 0 && user[l-1] == '\n')
862 if (l > 0 && passwd[l-1] == '\n')
870 * nochap - Disable CHAP authentication with peer.
875 lcp_allowoptions[0].neg_chap = 0;
881 * reqchap - Require CHAP authentication from peer.
886 lcp_wantoptions[0].neg_chap = 1;
893 * setnovj - disable vj compression
898 ipcp_wantoptions[0].neg_vj = 0;
899 ipcp_allowoptions[0].neg_vj = 0;
905 * setnovjccomp - disable VJ connection-ID compression
910 ipcp_wantoptions[0].cflag = 0;
911 ipcp_allowoptions[0].cflag = 0;
916 * setvjslots - set maximum number of connection slots for VJ compression
924 if (!int_option(*argv, &value))
926 if (value < 2 || value > 16) {
927 fprintf(stderr, "pppd: vj-max-slots value must be between 2 and 16\n");
930 ipcp_wantoptions [0].maxslotindex =
931 ipcp_allowoptions[0].maxslotindex = value - 1;
937 * setconnector - Set a program to connect to a serial line
943 connector = strdup(*argv);
944 if (connector == NULL)
945 novm("connector string");
951 * setdisconnector - Set a program to disconnect from the serial line
954 setdisconnector(argv)
957 disconnector = strdup(*argv);
958 if (disconnector == NULL)
959 novm("disconnector string");
966 * setdomain - Set domain name to append to hostname
972 strncat(hostname, *argv, MAXNAMELEN - strlen(hostname));
973 hostname[MAXNAMELEN-1] = 0;
979 * setasyncmap - add bits to asyncmap (what we request peer to escape).
987 if (!number_option(*argv, &asyncmap, 16))
989 lcp_wantoptions[0].asyncmap |= asyncmap;
990 lcp_wantoptions[0].neg_asyncmap = 1;
996 * setescape - add chars to the set we escape on transmission.
1008 n = strtol(p, &endp, 16);
1010 fprintf(stderr, "%s: invalid hex number: %s\n", progname, p);
1014 if (n < 0 || 0x20 <= n && n <= 0x3F || n == 0x5E || n > 0xFF) {
1015 fprintf(stderr, "%s: can't escape character 0x%x\n", n);
1018 xmit_accm[0][n >> 5] |= 1 << (n & 0x1F);
1019 while (*p == ',' || *p == ' ')
1027 * setspeed - Set the speed.
1036 spd = strtol(arg, &ptr, 0);
1037 if (ptr == arg || *ptr != 0 || spd == 0)
1045 * setdevname - Set the device name.
1051 struct stat statbuf;
1052 char *tty, *ttyname();
1053 char dev[MAXPATHLEN];
1055 if (strncmp("/dev/", cp, 5) != 0) {
1056 strcpy(dev, "/dev/");
1057 strncat(dev, cp, MAXPATHLEN - 5);
1058 dev[MAXPATHLEN-1] = 0;
1063 * Check if there is a device by this name.
1065 if (stat(cp, &statbuf) < 0) {
1066 if (errno == ENOENT)
1068 syslog(LOG_ERR, cp);
1072 (void) strncpy(devnam, cp, MAXPATHLEN);
1073 devnam[MAXPATHLEN-1] = 0;
1074 default_device = FALSE;
1081 * setipaddr - Set the IP address
1088 char *colon, *index();
1089 uint32 local, remote;
1090 ipcp_options *wo = &ipcp_wantoptions[0];
1093 * IP address pair separated by ":".
1095 if ((colon = index(arg, ':')) == NULL)
1099 * If colon first character, then no local addr.
1103 if ((local = inet_addr(arg)) == -1) {
1104 if ((hp = gethostbyname(arg)) == NULL) {
1105 fprintf(stderr, "unknown host: %s\n", arg);
1108 local = *(long *)hp->h_addr;
1109 if (our_name[0] == 0) {
1110 strncpy(our_name, arg, MAXNAMELEN);
1111 our_name[MAXNAMELEN-1] = 0;
1115 if (bad_ip_adrs(local)) {
1116 fprintf(stderr, "bad local IP address %s\n", ip_ntoa(local));
1120 wo->ouraddr = local;
1125 * If colon last character, then no remote addr.
1127 if (*++colon != '\0') {
1128 if ((remote = inet_addr(colon)) == -1) {
1129 if ((hp = gethostbyname(colon)) == NULL) {
1130 fprintf(stderr, "unknown host: %s\n", colon);
1133 remote = *(long *)hp->h_addr;
1134 if (remote_name[0] == 0) {
1135 strncpy(remote_name, colon, MAXNAMELEN);
1136 remote_name[MAXNAMELEN-1] = 0;
1140 if (bad_ip_adrs(remote)) {
1141 fprintf(stderr, "bad remote IP address %s\n", ip_ntoa(remote));
1145 wo->hisaddr = remote;
1153 * setnoipdflt - disable setipdefault()
1158 disable_defaultip = 1;
1164 * setipcpaccl - accept peer's idea of our address
1169 ipcp_wantoptions[0].accept_local = 1;
1175 * setipcpaccr - accept peer's idea of its address
1180 ipcp_wantoptions[0].accept_remote = 1;
1186 * setipdefault - default our local IP address based on our hostname.
1193 ipcp_options *wo = &ipcp_wantoptions[0];
1196 * If local IP address already given, don't bother.
1198 if (wo->ouraddr != 0 || disable_defaultip)
1202 * Look up our hostname (possibly with domain name appended)
1203 * and take the first IP address as our local IP address.
1204 * If there isn't an IP address for our hostname, too bad.
1206 wo->accept_local = 1; /* don't insist on this default value */
1207 if ((hp = gethostbyname(hostname)) == NULL)
1209 local = *(long *)hp->h_addr;
1210 if (local != 0 && !bad_ip_adrs(local))
1211 wo->ouraddr = local;
1216 * setnetmask - set the netmask to be used on the interface.
1224 if ((mask = inet_addr(*argv)) == -1 || (netmask & ~mask) != 0) {
1225 fprintf(stderr, "Invalid netmask %s\n", *argv);
1234 * Return user specified netmask. A value of zero means no netmask has
1306 if (our_name[0] == 0) {
1307 strncpy(our_name, argv[0], MAXNAMELEN);
1308 our_name[MAXNAMELEN-1] = 0;
1317 strncpy(user, argv[0], MAXNAMELEN);
1318 user[MAXNAMELEN-1] = 0;
1326 strncpy(remote_name, argv[0], MAXNAMELEN);
1327 remote_name[MAXNAMELEN-1] = 0;
1341 ipcp_wantoptions[0].default_route = 1;
1348 ipcp_wantoptions[0].proxy_arp = 1;
1367 * Functions to set the echo interval for modem-less monitors
1371 setlcpechointv(argv)
1374 return int_option(*argv, &lcp_echo_interval);
1378 setlcpechofails(argv)
1381 return int_option(*argv, &lcp_echo_fails);
1385 * Functions to set timeouts, max transmits, etc.
1391 return int_option(*argv, &lcp_fsm[0].timeouttime);
1394 static int setlcpterm(argv)
1397 return int_option(*argv, &lcp_fsm[0].maxtermtransmits);
1400 static int setlcpconf(argv)
1403 return int_option(*argv, &lcp_fsm[0].maxconfreqtransmits);
1406 static int setlcpfails(argv)
1409 return int_option(*argv, &lcp_fsm[0].maxnakloops);
1412 static int setipcptimeout(argv)
1415 return int_option(*argv, &ipcp_fsm[0].timeouttime);
1418 static int setipcpterm(argv)
1421 return int_option(*argv, &ipcp_fsm[0].maxtermtransmits);
1424 static int setipcpconf(argv)
1427 return int_option(*argv, &ipcp_fsm[0].maxconfreqtransmits);
1430 static int setipcpfails(argv)
1433 return int_option(*argv, &lcp_fsm[0].maxnakloops);
1436 static int setpaptimeout(argv)
1439 return int_option(*argv, &upap[0].us_timeouttime);
1442 static int setpapreqs(argv)
1445 return int_option(*argv, &upap[0].us_maxtransmits);
1448 static int setchaptimeout(argv)
1451 return int_option(*argv, &chap[0].timeouttime);
1454 static int setchapchal(argv)
1457 return int_option(*argv, &chap[0].max_transmits);
1460 static int setchapintv(argv)
1463 return int_option(*argv, &chap[0].chal_interval);
1466 static int setbsdcomp(argv)
1473 abits = rbits = strtol(str, &endp, 0);
1474 if (endp != str && *endp == ',') {
1476 abits = strtol(str, &endp, 0);
1478 if (*endp != 0 || endp == str) {
1479 fprintf(stderr, "%s: invalid argument format for bsdcomp option\n",
1483 if (rbits != 0 && (rbits < MIN_BSD_BITS || rbits > MAX_BSD_BITS)
1484 || abits != 0 && (abits < MIN_BSD_BITS || abits > MAX_BSD_BITS)) {
1485 fprintf(stderr, "%s: bsdcomp option values must be 0 or %d .. %d\n",
1486 progname, MIN_BSD_BITS, MAX_BSD_BITS);
1490 ccp_wantoptions[0].bsd_compress = 1;
1491 ccp_wantoptions[0].bsd_bits = rbits;
1493 ccp_wantoptions[0].bsd_compress = 0;
1495 ccp_allowoptions[0].bsd_compress = 1;
1496 ccp_allowoptions[0].bsd_bits = abits;
1498 ccp_allowoptions[0].bsd_compress = 0;
1502 static int setnobsdcomp()
1504 ccp_wantoptions[0].bsd_compress = 0;
1505 ccp_allowoptions[0].bsd_compress = 0;