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.21 1995/06/12 12:02:20 paulus Exp $";
34 #include <sys/types.h>
36 #include <netinet/in.h>
39 #include "pathnames.h"
40 #include "patchlevel.h"
48 #include <net/ppp-comp.h>
53 #if defined(ultrix) || defined(NeXT)
54 char *strdup __P((char *));
58 #define GIDSET_TYPE gid_t
62 * Option variables and default values.
64 int debug = 0; /* Debug flag */
65 int kdebugflag = 0; /* Tell kernel to print debug messages */
66 int default_device = 1; /* Using /dev/tty or equivalent */
67 char devnam[MAXPATHLEN] = "/dev/tty"; /* Device name */
68 int crtscts = 0; /* Use hardware flow control */
69 int modem = 1; /* Use modem control lines */
70 int inspeed = 0; /* Input/Output speed requested */
71 u_int32_t netmask = 0; /* IP netmask to set on interface */
72 int lockflag = 0; /* Create lock file to lock the serial dev */
73 int nodetach = 0; /* Don't detach from controlling tty */
74 char *connector = NULL; /* Script to establish physical link */
75 char *disconnector = NULL; /* Script to disestablish physical link */
76 char user[MAXNAMELEN]; /* Username for PAP */
77 char passwd[MAXSECRETLEN]; /* Password for PAP */
78 int auth_required = 0; /* Peer is required to authenticate */
79 int defaultroute = 0; /* assign default route through interface */
80 int proxyarp = 0; /* Set up proxy ARP entry for peer */
81 int persist = 0; /* Reopen link after it goes down */
82 int uselogin = 0; /* Use /etc/passwd for checking PAP */
83 int lcp_echo_interval = 0; /* Interval between LCP echo-requests */
84 int lcp_echo_fails = 0; /* Tolerance to unanswered echo-requests */
85 char our_name[MAXNAMELEN]; /* Our name for authentication purposes */
86 char remote_name[MAXNAMELEN]; /* Peer's name for authentication */
87 int usehostname = 0; /* Use hostname for our_name */
88 int disable_defaultip = 0; /* Don't use hostname for default IP adrs */
89 char *ipparam = NULL; /* Extra parameter for ip up/down scripts */
90 int cryptpap; /* Passwords in pap-secrets are encrypted */
93 int idle_time_limit = 0;
94 static int setidle __P((char **));
100 static int setdebug __P((void));
101 static int setkdebug __P((char **));
102 static int setpassive __P((void));
103 static int setsilent __P((void));
104 static int noopt __P((void));
105 static int setnovj __P((void));
106 static int setnovjccomp __P((void));
107 static int setvjslots __P((char **));
108 static int reqpap __P((void));
109 static int nopap __P((void));
110 static int setupapfile __P((char **));
111 static int nochap __P((void));
112 static int reqchap __P((void));
113 static int setspeed __P((char *));
114 static int noaccomp __P((void));
115 static int noasyncmap __P((void));
116 static int noipaddr __P((void));
117 static int nomagicnumber __P((void));
118 static int setasyncmap __P((char **));
119 static int setescape __P((char **));
120 static int setmru __P((char **));
121 static int setmtu __P((char **));
122 static int nomru __P((void));
123 static int nopcomp __P((void));
124 static int setconnector __P((char **));
125 static int setdisconnector __P((char **));
126 static int setdomain __P((char **));
127 static int setnetmask __P((char **));
128 static int setcrtscts __P((void));
129 static int setnocrtscts __P((void));
130 static int setxonxoff __P((void));
131 static int setnodetach __P((void));
132 static int setmodem __P((void));
133 static int setlocal __P((void));
134 static int setlock __P((void));
135 static int setname __P((char **));
136 static int setuser __P((char **));
137 static int setremote __P((char **));
138 static int setauth __P((void));
139 static int readfile __P((char **));
140 static int setdefaultroute __P((void));
141 static int setproxyarp __P((void));
142 static int setpersist __P((void));
143 static int setdologin __P((void));
144 static int setusehostname __P((void));
145 static int setnoipdflt __P((void));
146 static int setlcptimeout __P((char **));
147 static int setlcpterm __P((char **));
148 static int setlcpconf __P((char **));
149 static int setlcpfails __P((char **));
150 static int setipcptimeout __P((char **));
151 static int setipcpterm __P((char **));
152 static int setipcpconf __P((char **));
153 static int setipcpfails __P((char **));
154 static int setpaptimeout __P((char **));
155 static int setpapreqs __P((char **));
156 static int setpapreqtime __P((char **));
157 static int setchaptimeout __P((char **));
158 static int setchapchal __P((char **));
159 static int setchapintv __P((char **));
160 static int setipcpaccl __P((void));
161 static int setipcpaccr __P((void));
162 static int setlcpechointv __P((char **));
163 static int setlcpechofails __P((char **));
164 static int setbsdcomp __P((char **));
165 static int setnobsdcomp __P((void));
166 static int setipparam __P((char **));
167 static int setpapcrypt __P((void));
169 static int number_option __P((char *, u_int32_t *, int));
170 static int readable __P((int fd));
182 {"-all", 0, noopt}, /* Don't request/allow any options */
183 {"-ac", 0, noaccomp}, /* Disable Address/Control compress */
184 {"-am", 0, noasyncmap}, /* Disable asyncmap negotiation */
185 {"-as", 1, setasyncmap}, /* set the desired async map */
186 {"-d", 0, setdebug}, /* Increase debugging level */
187 {"-detach", 0, setnodetach}, /* don't fork */
188 {"-ip", 0, noipaddr}, /* Disable IP address negotiation */
189 {"-mn", 0, nomagicnumber}, /* Disable magic number negotiation */
190 {"-mru", 0, nomru}, /* Disable mru negotiation */
191 {"-p", 0, setpassive}, /* Set passive mode */
192 {"-pc", 0, nopcomp}, /* Disable protocol field compress */
193 {"+ua", 1, setupapfile}, /* Get PAP user and password from file */
194 {"+pap", 0, reqpap}, /* Require PAP auth from peer */
195 {"-pap", 0, nopap}, /* Don't allow UPAP authentication with peer */
196 {"+chap", 0, reqchap}, /* Require CHAP authentication from peer */
197 {"-chap", 0, nochap}, /* Don't allow CHAP authentication with peer */
198 {"-vj", 0, setnovj}, /* disable VJ compression */
199 {"-vjccomp", 0, setnovjccomp}, /* disable VJ connection-ID compression */
200 {"vj-max-slots", 1, setvjslots}, /* Set maximum VJ header slots */
201 {"asyncmap", 1, setasyncmap}, /* set the desired async map */
202 {"escape", 1, setescape}, /* set chars to escape on transmission */
203 {"connect", 1, setconnector}, /* A program to set up a connection */
204 {"disconnect", 1, setdisconnector}, /* program to disconnect serial dev. */
205 {"crtscts", 0, setcrtscts}, /* set h/w flow control */
206 {"-crtscts", 0, setnocrtscts}, /* clear h/w flow control */
207 {"xonxoff", 0, setxonxoff}, /* set s/w flow control */
208 {"debug", 0, setdebug}, /* Increase debugging level */
209 {"kdebug", 1, setkdebug}, /* Enable kernel-level debugging */
210 {"domain", 1, setdomain}, /* Add given domain name to hostname*/
211 {"mru", 1, setmru}, /* Set MRU value for negotiation */
212 {"mtu", 1, setmtu}, /* Set our MTU */
213 {"netmask", 1, setnetmask}, /* set netmask */
214 {"passive", 0, setpassive}, /* Set passive mode */
215 {"silent", 0, setsilent}, /* Set silent mode */
216 {"modem", 0, setmodem}, /* Use modem control lines */
217 {"local", 0, setlocal}, /* Don't use modem control lines */
218 {"lock", 0, setlock}, /* Lock serial device (with lock file) */
219 {"name", 1, setname}, /* Set local name for authentication */
220 {"user", 1, setuser}, /* Set username for PAP auth with peer */
221 {"usehostname", 0, setusehostname}, /* Must use hostname for auth. */
222 {"remotename", 1, setremote}, /* Set remote name for authentication */
223 {"auth", 0, setauth}, /* Require authentication from peer */
224 {"file", 1, readfile}, /* Take options from a file */
225 {"defaultroute", 0, setdefaultroute}, /* Add default route */
226 {"proxyarp", 0, setproxyarp}, /* Add proxy ARP entry */
227 {"persist", 0, setpersist}, /* Keep on reopening connection after close */
228 {"login", 0, setdologin}, /* Use system password database for UPAP */
229 {"noipdefault", 0, setnoipdflt}, /* Don't use name for default IP adrs */
230 {"lcp-echo-failure", 1, setlcpechofails}, /* consecutive echo failures */
231 {"lcp-echo-interval", 1, setlcpechointv}, /* time for lcp echo events */
232 {"lcp-restart", 1, setlcptimeout}, /* Set timeout for LCP */
233 {"lcp-max-terminate", 1, setlcpterm}, /* Set max #xmits for term-reqs */
234 {"lcp-max-configure", 1, setlcpconf}, /* Set max #xmits for conf-reqs */
235 {"lcp-max-failure", 1, setlcpfails}, /* Set max #conf-naks for LCP */
236 {"ipcp-restart", 1, setipcptimeout}, /* Set timeout for IPCP */
237 {"ipcp-max-terminate", 1, setipcpterm}, /* Set max #xmits for term-reqs */
238 {"ipcp-max-configure", 1, setipcpconf}, /* Set max #xmits for conf-reqs */
239 {"ipcp-max-failure", 1, setipcpfails}, /* Set max #conf-naks for IPCP */
240 {"pap-restart", 1, setpaptimeout}, /* Set retransmit timeout for PAP */
241 {"pap-max-authreq", 1, setpapreqs}, /* Set max #xmits for auth-reqs */
242 {"pap-timeout", 1, setpapreqtime}, /* Set time limit for peer PAP auth. */
243 {"chap-restart", 1, setchaptimeout}, /* Set timeout for CHAP */
244 {"chap-max-challenge", 1, setchapchal}, /* Set max #xmits for challenge */
245 {"chap-interval", 1, setchapintv}, /* Set interval for rechallenge */
246 {"ipcp-accept-local", 0, setipcpaccl}, /* Accept peer's address for us */
247 {"ipcp-accept-remote", 0, setipcpaccr}, /* Accept peer's address for it */
248 {"bsdcomp", 1, setbsdcomp}, /* request BSD-Compress */
249 {"-bsdcomp", 0, setnobsdcomp}, /* don't allow BSD-Compress */
250 {"ipparam", 1, setipparam}, /* set ip script parameter */
251 {"papcrypt", 0, setpapcrypt}, /* PAP passwords encrypted */
253 {"idle-disconnect", 1, setidle}, /* seconds for disconnect of idle IP */
259 #ifndef IMPLEMENTATION
260 #define IMPLEMENTATION ""
263 static char *usage_string = "\
264 pppd version %s patch level %d%s\n\
265 Usage: %s [ arguments ], where arguments are:\n\
266 <device> Communicate over the named device\n\
267 <speed> Set the baud rate to <speed>\n\
268 <loc>:<rem> Set the local and/or remote interface IP\n\
269 addresses. Either one may be omitted.\n\
270 asyncmap <n> Set the desired async map to hex <n>\n\
271 auth Require authentication from peer\n\
272 connect <p> Invoke shell command <p> to set up the serial line\n\
273 crtscts Use hardware RTS/CTS flow control\n\
274 defaultroute Add default route through interface\n\
275 file <f> Take options from file <f>\n\
276 modem Use modem control lines\n\
277 mru <n> Set MRU value to <n> for negotiation\n\
278 netmask <n> Set interface netmask to <n>\n\
279 See pppd(8) for more options.\n\
284 * parse_args - parse a string of arguments, from the command
285 * line or from a file.
288 parse_args(argc, argv)
301 * First see if it's a command.
303 for (cmdp = cmds; cmdp->cmd_name; cmdp++)
304 if (!strcmp(arg, cmdp->cmd_name))
307 if (cmdp->cmd_name != NULL) {
308 if (argc < cmdp->num_args) {
309 fprintf(stderr, "Too few parameters for command %s\n", arg);
312 if (!(*cmdp->cmd_func)(argv))
314 argc -= cmdp->num_args;
315 argv += cmdp->num_args;
319 * Maybe a tty name, speed or IP address?
321 if ((ret = setdevname(arg)) == 0
322 && (ret = setspeed(arg)) == 0
323 && (ret = setipaddr(arg)) == 0) {
324 fprintf(stderr, "%s: unrecognized command\n", arg);
328 if (ret < 0) /* error */
336 * usage - print out a message telling how to use the program.
341 fprintf(stderr, usage_string, VERSION, PATCHLEVEL, IMPLEMENTATION,
346 * options_from_file - Read a string of options from a file,
347 * and interpret them.
350 options_from_file(filename, must_exist, check_prot)
359 char args[MAXARGS][MAXWORDLEN];
360 char cmd[MAXWORDLEN];
362 if ((f = fopen(filename, "r")) == NULL) {
363 if (!must_exist && errno == ENOENT)
368 if (check_prot && !readable(fileno(f))) {
369 fprintf(stderr, "%s: access denied\n", filename);
374 while (getword(f, cmd, &newline, filename)) {
376 * First see if it's a command.
378 for (cmdp = cmds; cmdp->cmd_name; cmdp++)
379 if (!strcmp(cmd, cmdp->cmd_name))
382 if (cmdp->cmd_name != NULL) {
383 for (i = 0; i < cmdp->num_args; ++i) {
384 if (!getword(f, args[i], &newline, filename)) {
386 "In file %s: too few parameters for command %s\n",
393 if (!(*cmdp->cmd_func)(argv)) {
400 * Maybe a tty name, speed or IP address?
402 if ((ret = setdevname(cmd)) == 0
403 && (ret = setspeed(cmd)) == 0
404 && (ret = setipaddr(cmd)) == 0) {
405 fprintf(stderr, "In file %s: unrecognized command %s\n",
410 if (ret < 0) /* error */
418 * options_from_user - See if the use has a ~/.ppprc file,
419 * and if so, interpret options from it.
424 char *user, *path, *file;
428 pw = getpwuid(getuid());
429 if (pw == NULL || (user = pw->pw_dir) == NULL || user[0] == 0)
431 file = _PATH_USEROPT;
432 path = malloc(strlen(user) + strlen(file) + 2);
434 novm("init file name");
438 ret = options_from_file(path, 0, 1);
444 * options_for_tty - See if an options file exists for the serial
445 * device, and if so, interpret options from it.
453 dev = strrchr(devnam, '/');
458 if (strcmp(dev, "tty") == 0)
459 return 1; /* don't look for /etc/ppp/options.tty */
460 path = malloc(strlen(_PATH_TTYOPT) + strlen(dev) + 1);
462 novm("tty init file name");
463 strcpy(path, _PATH_TTYOPT);
465 ret = options_from_file(path, 0, 0);
471 * readable - check if a file is readable by the real user.
480 GIDSET_TYPE groups[NGROUPS_MAX];
485 if (fstat(fd, &sbuf) != 0)
487 if (sbuf.st_uid == uid)
488 return sbuf.st_mode & S_IRUSR;
489 if (sbuf.st_gid == getgid())
490 return sbuf.st_mode & S_IRGRP;
491 ngroups = getgroups(NGROUPS_MAX, groups);
492 for (i = 0; i < ngroups; ++i)
493 if (sbuf.st_gid == groups[i])
494 return sbuf.st_mode & S_IRGRP;
495 return sbuf.st_mode & S_IROTH;
499 * Read a word from a file.
500 * Words are delimited by white-space or by quotes (" or ').
501 * Quotes, white-space and \ may be escaped with \.
502 * \<newline> is ignored.
506 getword(f, word, newlinep, filename)
514 int value, digit, got, n;
516 #define isoctal(c) ((c) >= '0' && (c) < '8')
524 * First skip white-space and comments.
532 * A newline means the end of a comment; backslash-newline
533 * is ignored. Note that we cannot have escape && comment.
545 * Ignore characters other than newline in a comment.
551 * If this character is escaped, we have a word start.
557 * If this is the escape character, look at the next character.
565 * If this is the start of a comment, ignore the rest of the line.
573 * A non-whitespace character is the start of a word.
580 * Save the delimiter for quoted strings.
582 if (!escape && (c == '"' || c == '\'')) {
589 * Process characters until the end of the word.
594 * This character is escaped: backslash-newline is ignored,
595 * various other characters indicate particular values
596 * as for C backslash-escapes.
631 * \ddd octal sequence
634 for (n = 0; n < 3 && isoctal(c); ++n) {
635 value = (value << 3) + (c & 07);
644 * \x<hex_string> sequence
648 for (n = 0; n < 2 && isxdigit(c); ++n) {
649 digit = toupper(c) - '0';
651 digit += '0' + 10 - 'A';
652 value = (value << 4) + digit;
660 * Otherwise the character stands for itself.
667 * Store the resulting character for the escape sequence.
669 if (len < MAXWORDLEN-1)
680 * Not escaped: see if we've reached the end of the word.
686 if (isspace(c) || c == '#') {
693 * Backslash starts an escape sequence.
702 * An ordinary character: store it in the word and get another.
704 if (len < MAXWORDLEN-1)
712 * End of the word: check for errors.
722 * If len is zero, then we didn't find a word before the
730 * Warn if the word was too long, and append a terminating null.
732 if (len >= MAXWORDLEN) {
733 fprintf(stderr, "%s: warning: word in file %s too long (%.20s...)\n",
734 progname, filename, word);
735 len = MAXWORDLEN - 1;
746 * number_option - parse an unsigned numeric parameter for an option.
749 number_option(str, valp, base)
756 *valp = strtoul(str, &ptr, base);
758 fprintf(stderr, "%s: invalid number: %s\n", progname, str);
766 * int_option - like number_option, but valp is int *,
767 * the base is assumed to be 0, and *valp is not changed
768 * if there is an error.
771 int_option(str, valp)
777 if (!number_option(str, &v, 0))
785 * The following procedures execute commands.
789 * readfile - take commands from a file.
795 return options_from_file(*argv, 1, 1);
799 * setdebug - Set debug (command line argument).
809 * setkdebug - Set kernel debugging level.
815 return int_option(*argv, &kdebugflag);
819 * noopt - Disable all options.
824 BZERO((char *) &lcp_wantoptions[0], sizeof (struct lcp_options));
825 BZERO((char *) &lcp_allowoptions[0], sizeof (struct lcp_options));
826 BZERO((char *) &ipcp_wantoptions[0], sizeof (struct ipcp_options));
827 BZERO((char *) &ipcp_allowoptions[0], sizeof (struct ipcp_options));
832 * noaccomp - Disable Address/Control field compression negotiation.
837 lcp_wantoptions[0].neg_accompression = 0;
838 lcp_allowoptions[0].neg_accompression = 0;
844 * noasyncmap - Disable async map negotiation.
849 lcp_wantoptions[0].neg_asyncmap = 0;
850 lcp_allowoptions[0].neg_asyncmap = 0;
856 * noipaddr - Disable IP address negotiation.
861 ipcp_wantoptions[0].neg_addr = 0;
862 ipcp_allowoptions[0].neg_addr = 0;
868 * nomagicnumber - Disable magic number negotiation.
873 lcp_wantoptions[0].neg_magicnumber = 0;
874 lcp_allowoptions[0].neg_magicnumber = 0;
880 * nomru - Disable mru negotiation.
885 lcp_wantoptions[0].neg_mru = 0;
886 lcp_allowoptions[0].neg_mru = 0;
892 * setmru - Set MRU for negotiation.
900 if (!number_option(*argv, &mru, 0))
902 lcp_wantoptions[0].mru = mru;
903 lcp_wantoptions[0].neg_mru = 1;
909 * setmru - Set the largest MTU we'll use.
917 if (!number_option(*argv, &mtu, 0))
919 if (mtu < MINMRU || mtu > MAXMRU) {
920 fprintf(stderr, "mtu option value of %ld is too %s\n", mtu,
921 (mtu < MINMRU? "small": "large"));
924 lcp_allowoptions[0].mru = mtu;
930 * nopcomp - Disable Protocol field compression negotiation.
935 lcp_wantoptions[0].neg_pcompression = 0;
936 lcp_allowoptions[0].neg_pcompression = 0;
942 * setpassive - Set passive mode (don't give up if we time out sending
943 * LCP configure-requests).
948 lcp_wantoptions[0].passive = 1;
954 * setsilent - Set silent mode (don't start sending LCP configure-requests
955 * until we get one from the peer).
960 lcp_wantoptions[0].silent = 1;
966 * nopap - Disable PAP authentication with peer.
971 lcp_allowoptions[0].neg_upap = 0;
977 * reqpap - Require PAP authentication from peer.
982 lcp_wantoptions[0].neg_upap = 1;
989 * setupapfile - specifies UPAP info for authenticating with peer.
998 lcp_allowoptions[0].neg_upap = 1;
1000 /* open user info file */
1001 if ((ufile = fopen(*argv, "r")) == NULL) {
1002 fprintf(stderr, "unable to open user login data file %s\n", *argv);
1005 if (!readable(fileno(ufile))) {
1006 fprintf(stderr, "%s: access denied\n", *argv);
1009 check_access(ufile, *argv);
1012 if (fgets(user, MAXNAMELEN - 1, ufile) == NULL
1013 || fgets(passwd, MAXSECRETLEN - 1, ufile) == NULL){
1014 fprintf(stderr, "Unable to read user login data file %s.\n", *argv);
1019 /* get rid of newlines */
1021 if (l > 0 && user[l-1] == '\n')
1024 if (l > 0 && passwd[l-1] == '\n')
1032 * nochap - Disable CHAP authentication with peer.
1037 lcp_allowoptions[0].neg_chap = 0;
1043 * reqchap - Require CHAP authentication from peer.
1048 lcp_wantoptions[0].neg_chap = 1;
1055 * setnovj - disable vj compression
1060 ipcp_wantoptions[0].neg_vj = 0;
1061 ipcp_allowoptions[0].neg_vj = 0;
1067 * setnovjccomp - disable VJ connection-ID compression
1072 ipcp_wantoptions[0].cflag = 0;
1073 ipcp_allowoptions[0].cflag = 0;
1079 * setvjslots - set maximum number of connection slots for VJ compression
1087 if (!int_option(*argv, &value))
1089 if (value < 2 || value > 16) {
1090 fprintf(stderr, "pppd: vj-max-slots value must be between 2 and 16\n");
1093 ipcp_wantoptions [0].maxslotindex =
1094 ipcp_allowoptions[0].maxslotindex = value - 1;
1100 * setconnector - Set a program to connect to a serial line
1106 connector = strdup(*argv);
1107 if (connector == NULL)
1108 novm("connector string");
1114 * setdisconnector - Set a program to disconnect from the serial line
1117 setdisconnector(argv)
1120 disconnector = strdup(*argv);
1121 if (disconnector == NULL)
1122 novm("disconnector string");
1129 * setdomain - Set domain name to append to hostname
1135 strncat(hostname, *argv, MAXNAMELEN - strlen(hostname));
1136 hostname[MAXNAMELEN-1] = 0;
1142 * setasyncmap - add bits to asyncmap (what we request peer to escape).
1150 if (!number_option(*argv, &asyncmap, 16))
1152 lcp_wantoptions[0].asyncmap |= asyncmap;
1153 lcp_wantoptions[0].neg_asyncmap = 1;
1159 * setescape - add chars to the set we escape on transmission.
1171 n = strtol(p, &endp, 16);
1173 fprintf(stderr, "%s: invalid hex number: %s\n", progname, p);
1177 if (n < 0 || 0x20 <= n && n <= 0x3F || n == 0x5E || n > 0xFF) {
1178 fprintf(stderr, "%s: can't escape character 0x%x\n", progname, n);
1181 xmit_accm[0][n >> 5] |= 1 << (n & 0x1F);
1182 while (*p == ',' || *p == ' ')
1190 * setspeed - Set the speed.
1199 spd = strtol(arg, &ptr, 0);
1200 if (ptr == arg || *ptr != 0 || spd == 0)
1208 * setdevname - Set the device name.
1214 struct stat statbuf;
1215 char *tty, *ttyname();
1216 char dev[MAXPATHLEN];
1218 if (strncmp("/dev/", cp, 5) != 0) {
1219 strcpy(dev, "/dev/");
1220 strncat(dev, cp, MAXPATHLEN - 5);
1221 dev[MAXPATHLEN-1] = 0;
1226 * Check if there is a device by this name.
1228 if (stat(cp, &statbuf) < 0) {
1229 if (errno == ENOENT)
1231 syslog(LOG_ERR, cp);
1235 (void) strncpy(devnam, cp, MAXPATHLEN);
1236 devnam[MAXPATHLEN-1] = 0;
1237 default_device = FALSE;
1244 * setipaddr - Set the IP address
1252 u_int32_t local, remote;
1253 ipcp_options *wo = &ipcp_wantoptions[0];
1256 * IP address pair separated by ":".
1258 if ((colon = strchr(arg, ':')) == NULL)
1262 * If colon first character, then no local addr.
1266 if ((local = inet_addr(arg)) == -1) {
1267 if ((hp = gethostbyname(arg)) == NULL) {
1268 fprintf(stderr, "unknown host: %s\n", arg);
1271 local = *(u_int32_t *)hp->h_addr;
1272 if (our_name[0] == 0) {
1273 strncpy(our_name, arg, MAXNAMELEN);
1274 our_name[MAXNAMELEN-1] = 0;
1278 if (bad_ip_adrs(local)) {
1279 fprintf(stderr, "bad local IP address %s\n", ip_ntoa(local));
1283 wo->ouraddr = local;
1288 * If colon last character, then no remote addr.
1290 if (*++colon != '\0') {
1291 if ((remote = inet_addr(colon)) == -1) {
1292 if ((hp = gethostbyname(colon)) == NULL) {
1293 fprintf(stderr, "unknown host: %s\n", colon);
1296 remote = *(u_int32_t *)hp->h_addr;
1297 if (remote_name[0] == 0) {
1298 strncpy(remote_name, colon, MAXNAMELEN);
1299 remote_name[MAXNAMELEN-1] = 0;
1303 if (bad_ip_adrs(remote)) {
1304 fprintf(stderr, "bad remote IP address %s\n", ip_ntoa(remote));
1308 wo->hisaddr = remote;
1316 * setnoipdflt - disable setipdefault()
1321 disable_defaultip = 1;
1327 * setipcpaccl - accept peer's idea of our address
1332 ipcp_wantoptions[0].accept_local = 1;
1338 * setipcpaccr - accept peer's idea of its address
1343 ipcp_wantoptions[0].accept_remote = 1;
1349 * setipdefault - default our local IP address based on our hostname.
1356 ipcp_options *wo = &ipcp_wantoptions[0];
1359 * If local IP address already given, don't bother.
1361 if (wo->ouraddr != 0 || disable_defaultip)
1365 * Look up our hostname (possibly with domain name appended)
1366 * and take the first IP address as our local IP address.
1367 * If there isn't an IP address for our hostname, too bad.
1369 wo->accept_local = 1; /* don't insist on this default value */
1370 if ((hp = gethostbyname(hostname)) == NULL)
1372 local = *(u_int32_t *)hp->h_addr;
1373 if (local != 0 && !bad_ip_adrs(local))
1374 wo->ouraddr = local;
1379 * setnetmask - set the netmask to be used on the interface.
1387 if ((mask = inet_addr(*argv)) == -1 || (netmask & ~mask) != 0) {
1388 fprintf(stderr, "Invalid netmask %s\n", *argv);
1413 lcp_wantoptions[0].asyncmap |= 0x000A0000; /* escape ^S and ^Q */
1414 lcp_wantoptions[0].neg_asyncmap = 1;
1459 if (our_name[0] == 0) {
1460 strncpy(our_name, argv[0], MAXNAMELEN);
1461 our_name[MAXNAMELEN-1] = 0;
1470 strncpy(user, argv[0], MAXNAMELEN);
1471 user[MAXNAMELEN-1] = 0;
1479 strncpy(remote_name, argv[0], MAXNAMELEN);
1480 remote_name[MAXNAMELEN-1] = 0;
1494 ipcp_wantoptions[0].default_route = 1;
1501 ipcp_wantoptions[0].proxy_arp = 1;
1520 * Functions to set the echo interval for modem-less monitors
1524 setlcpechointv(argv)
1527 return int_option(*argv, &lcp_echo_interval);
1531 setlcpechofails(argv)
1534 return int_option(*argv, &lcp_echo_fails);
1538 * Functions to set timeouts, max transmits, etc.
1544 return int_option(*argv, &lcp_fsm[0].timeouttime);
1551 return int_option(*argv, &lcp_fsm[0].maxtermtransmits);
1558 return int_option(*argv, &lcp_fsm[0].maxconfreqtransmits);
1565 return int_option(*argv, &lcp_fsm[0].maxnakloops);
1569 setipcptimeout(argv)
1572 return int_option(*argv, &ipcp_fsm[0].timeouttime);
1579 return int_option(*argv, &ipcp_fsm[0].maxtermtransmits);
1586 return int_option(*argv, &ipcp_fsm[0].maxconfreqtransmits);
1593 return int_option(*argv, &lcp_fsm[0].maxnakloops);
1600 return int_option(*argv, &upap[0].us_timeouttime);
1607 return int_option(*argv, &upap[0].us_reqtimeout);
1614 return int_option(*argv, &upap[0].us_maxtransmits);
1618 setchaptimeout(argv)
1621 return int_option(*argv, &chap[0].timeouttime);
1628 return int_option(*argv, &chap[0].max_transmits);
1635 return int_option(*argv, &chap[0].chal_interval);
1646 abits = rbits = strtol(str, &endp, 0);
1647 if (endp != str && *endp == ',') {
1649 abits = strtol(str, &endp, 0);
1651 if (*endp != 0 || endp == str) {
1652 fprintf(stderr, "%s: invalid argument format for bsdcomp option\n",
1656 if (rbits != 0 && (rbits < BSD_MIN_BITS || rbits > BSD_MAX_BITS)
1657 || abits != 0 && (abits < BSD_MIN_BITS || abits > BSD_MAX_BITS)) {
1658 fprintf(stderr, "%s: bsdcomp option values must be 0 or %d .. %d\n",
1659 progname, BSD_MIN_BITS, BSD_MAX_BITS);
1663 ccp_wantoptions[0].bsd_compress = 1;
1664 ccp_wantoptions[0].bsd_bits = rbits;
1666 ccp_wantoptions[0].bsd_compress = 0;
1668 ccp_allowoptions[0].bsd_compress = 1;
1669 ccp_allowoptions[0].bsd_bits = abits;
1671 ccp_allowoptions[0].bsd_compress = 0;
1678 ccp_wantoptions[0].bsd_compress = 0;
1679 ccp_allowoptions[0].bsd_compress = 0;
1687 ipparam = strdup(*argv);
1688 if (ipparam == NULL)
1689 novm("ipparam string");
1702 static int setidle (argv)
1705 return int_option(*argv, &idle_time_limit);