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.60 1999/07/21 00:24:31 paulus Exp $";
35 #include <sys/types.h>
37 #include <netinet/in.h>
38 #include <arpa/inet.h>
41 #include <pcap-int.h> /* XXX: To get struct pcap */
45 #include "pathnames.h"
46 #include "patchlevel.h"
54 #include <net/ppp-comp.h>
56 #if defined(ultrix) || defined(NeXT)
57 char *strdup __P((char *));
61 * Option variables and default values.
64 int dflag = 0; /* Tell libpcap we want debugging */
66 int debug = 0; /* Debug flag */
67 int kdebugflag = 0; /* Tell kernel to print debug messages */
68 int default_device = 1; /* Using /dev/tty or equivalent */
69 char devnam[MAXPATHLEN]; /* Device name */
70 int crtscts = 0; /* Use hardware flow control */
71 bool modem = 1; /* Use modem control lines */
72 int inspeed = 0; /* Input/Output speed requested */
73 u_int32_t netmask = 0; /* IP netmask to set on interface */
74 bool lockflag = 0; /* Create lock file to lock the serial dev */
75 bool nodetach = 0; /* Don't detach from controlling tty */
76 bool updetach = 0; /* Detach once link is up */
77 char *initializer = NULL; /* Script to initialize physical link */
78 char *connector = NULL; /* Script to establish physical link */
79 char *disconnector = NULL; /* Script to disestablish physical link */
80 char *welcomer = NULL; /* Script to run after phys link estab. */
81 char *ptycommand = NULL; /* Command to run on other side of pty */
82 int maxconnect = 0; /* Maximum connect time */
83 char user[MAXNAMELEN]; /* Username for PAP */
84 char passwd[MAXSECRETLEN]; /* Password for PAP */
85 bool persist = 0; /* Reopen link after it goes down */
86 char our_name[MAXNAMELEN]; /* Our name for authentication purposes */
87 bool demand = 0; /* do dial-on-demand */
88 char *ipparam = NULL; /* Extra parameter for ip up/down scripts */
89 int idle_time_limit = 0; /* Disconnect if idle for this many seconds */
90 int holdoff = 30; /* # seconds to pause before reconnecting */
91 bool notty = 0; /* Stdin/out is not a tty */
92 char *record_file = NULL; /* File to record chars sent/received */
94 bool sync_serial = 0; /* Device is synchronous serial device */
95 int log_to_fd = 1; /* send log messages to this fd too */
97 extern option_t auth_options[];
98 extern struct stat devstat;
99 extern int prepass; /* Doing pre-pass to find device name */
101 struct option_info initializer_info;
102 struct option_info connector_info;
103 struct option_info disconnector_info;
104 struct option_info welcomer_info;
105 struct option_info devnam_info;
106 struct option_info ptycommand_info;
109 struct bpf_program pass_filter;/* Filter program for packets to pass */
110 struct bpf_program active_filter; /* Filter program for link-active pkts */
111 pcap_t pc; /* Fake struct pcap so we can compile expr */
114 char *current_option; /* the name of the option being parsed */
115 int privileged_option; /* set iff the current option came from root */
116 char *option_source; /* string saying where the option came from */
117 bool log_to_file; /* log_to_fd is a file opened by us */
122 static int setdevname __P((char *));
123 static int setipaddr __P((char *));
124 static int setspeed __P((char *));
125 static int noopt __P((char **));
126 static int setdomain __P((char **));
127 static int setnetmask __P((char **));
128 static int setxonxoff __P((char **));
129 static int readfile __P((char **));
130 static int callfile __P((char **));
131 static int showversion __P((char **));
132 static int showhelp __P((char **));
133 static void usage __P((void));
134 static int setlogfile __P((char **));
137 static int setpassfilter __P((char **));
138 static int setactivefilter __P((char **));
142 static option_t *find_option __P((char *name));
143 static int process_option __P((option_t *, char **));
144 static int n_arguments __P((option_t *));
145 static int number_option __P((char *, u_int32_t *, int));
150 option_t general_options[] = {
151 { "debug", o_int, &debug,
152 "Increase debugging level", OPT_INC|OPT_NOARG|1 },
153 { "-d", o_int, &debug,
154 "Increase debugging level", OPT_INC|OPT_NOARG|1 },
155 { "kdebug", o_int, &kdebugflag,
156 "Set kernel driver debug level" },
157 { "nodetach", o_bool, &nodetach,
158 "Don't detach from controlling tty", 1 },
159 { "-detach", o_bool, &nodetach,
160 "Don't detach from controlling tty", 1 },
161 { "updetach", o_bool, &updetach,
162 "Detach from controlling tty once link is up", 1 },
163 { "holdoff", o_int, &holdoff,
164 "Set time in seconds before retrying connection" },
165 { "idle", o_int, &idle_time_limit,
166 "Set time in seconds before disconnecting idle link" },
167 { "lock", o_bool, &lockflag,
168 "Lock serial device with UUCP-style lock file", 1 },
169 { "-all", o_special_noarg, noopt,
170 "Don't request/allow any LCP or IPCP options (useless)" },
171 { "init", o_string, &initializer,
172 "A program to initialize the device",
173 OPT_A2INFO | OPT_PRIVFIX, &initializer_info },
174 { "connect", o_string, &connector,
175 "A program to set up a connection",
176 OPT_A2INFO | OPT_PRIVFIX, &connector_info },
177 { "disconnect", o_string, &disconnector,
178 "Program to disconnect serial device",
179 OPT_A2INFO | OPT_PRIVFIX, &disconnector_info },
180 { "welcome", o_string, &welcomer,
181 "Script to welcome client",
182 OPT_A2INFO | OPT_PRIVFIX, &welcomer_info },
183 { "pty", o_string, &ptycommand,
184 "Script to run on pseudo-tty master side",
185 OPT_A2INFO | OPT_PRIVFIX | OPT_DEVNAM, &ptycommand_info },
186 { "notty", o_bool, ¬ty,
187 "Input/output is not a tty", OPT_DEVNAM | 1 },
188 { "record", o_string, &record_file,
189 "Record characters sent/received to file" },
190 { "maxconnect", o_int, &maxconnect,
191 "Set connection time limit", OPT_LLIMIT|OPT_NOINCR|OPT_ZEROINF },
192 { "crtscts", o_int, &crtscts,
193 "Set hardware (RTS/CTS) flow control", OPT_NOARG|OPT_VAL(1) },
194 { "nocrtscts", o_int, &crtscts,
195 "Disable hardware flow control", OPT_NOARG|OPT_VAL(-1) },
196 { "-crtscts", o_int, &crtscts,
197 "Disable hardware flow control", OPT_NOARG|OPT_VAL(-1) },
198 { "cdtrcts", o_int, &crtscts,
199 "Set alternate hardware (DTR/CTS) flow control", OPT_NOARG|OPT_VAL(2) },
200 { "nocdtrcts", o_int, &crtscts,
201 "Disable hardware flow control", OPT_NOARG|OPT_VAL(-1) },
202 { "xonxoff", o_special_noarg, setxonxoff,
203 "Set software (XON/XOFF) flow control" },
204 { "domain", o_special, setdomain,
205 "Add given domain name to hostname" },
206 { "mtu", o_int, &lcp_allowoptions[0].mru,
207 "Set our MTU", OPT_LIMITS, NULL, MAXMRU, MINMRU },
208 { "netmask", o_special, setnetmask,
210 { "modem", o_bool, &modem,
211 "Use modem control lines", 1 },
212 { "local", o_bool, &modem,
213 "Don't use modem control lines" },
214 { "file", o_special, readfile,
215 "Take options from a file", OPT_PREPASS },
216 { "call", o_special, callfile,
217 "Take options from a privileged file", OPT_PREPASS },
218 { "persist", o_bool, &persist,
219 "Keep on reopening connection after close", 1 },
220 { "nopersist", o_bool, &persist,
221 "Turn off persist option" },
222 { "demand", o_bool, &demand,
223 "Dial on demand", OPT_INITONLY | 1, &persist },
224 { "--version", o_special_noarg, showversion,
225 "Show version number" },
226 { "--help", o_special_noarg, showhelp,
227 "Show brief listing of options" },
228 { "-h", o_special_noarg, showhelp,
229 "Show brief listing of options" },
230 { "sync", o_bool, &sync_serial,
231 "Use synchronous HDLC serial encoding", 1 },
232 { "logfd", o_int, &log_to_fd,
233 "Send log messages to this file descriptor" },
234 { "logfile", o_special, setlogfile,
235 "Append log messages to this file" },
236 { "nolog", o_int, &log_to_fd,
237 "Don't send log messages to any file",
238 OPT_NOARG | OPT_VAL(-1) },
239 { "nologfd", o_int, &log_to_fd,
240 "Don't send log messages to any file descriptor",
241 OPT_NOARG | OPT_VAL(-1) },
244 { "pdebug", o_int, &dflag,
245 "libpcap debugging" },
246 { "pass-filter", 1, setpassfilter,
247 "set filter for packets to pass" },
248 { "active-filter", 1, setactivefilter,
249 "set filter for active pkts" },
255 #ifndef IMPLEMENTATION
256 #define IMPLEMENTATION ""
259 static char *usage_string = "\
260 pppd version %s.%d%s\n\
261 Usage: %s [ options ], where options are:\n\
262 <device> Communicate over the named device\n\
263 <speed> Set the baud rate to <speed>\n\
264 <loc>:<rem> Set the local and/or remote interface IP\n\
265 addresses. Either one may be omitted.\n\
266 asyncmap <n> Set the desired async map to hex <n>\n\
267 auth Require authentication from peer\n\
268 connect <p> Invoke shell command <p> to set up the serial line\n\
269 crtscts Use hardware RTS/CTS flow control\n\
270 defaultroute Add default route through interface\n\
271 file <f> Take options from file <f>\n\
272 modem Use modem control lines\n\
273 mru <n> Set MRU value to <n> for negotiation\n\
274 See pppd(8) for more options.\n\
278 * parse_args - parse a string of arguments from the command line.
279 * If prepass is true, we are scanning for the device name and only
280 * processing a few options, so error messages are suppressed.
283 parse_args(argc, argv)
291 privileged_option = privileged;
292 option_source = "command line";
298 * First see if it's an option in the new option list.
300 opt = find_option(arg);
302 int n = n_arguments(opt);
304 option_error("too few parameters for option %s", arg);
307 current_option = arg;
308 if (!process_option(opt, argv))
316 * Maybe a tty name, speed or IP address?
318 if ((ret = setdevname(arg)) == 0
319 && (ret = setspeed(arg)) == 0
320 && (ret = setipaddr(arg)) == 0) {
321 option_error("unrecognized option '%s'", arg);
325 if (ret < 0) /* error */
333 * scan_args - scan the command line arguments to get the tty name,
334 * if specified. Also checks whether the notty or pty option was given.
337 scan_args(argc, argv)
344 privileged_option = privileged;
349 if (strcmp(arg, "notty") == 0 || strcmp(arg, "pty") == 0)
352 /* Skip options and their arguments */
353 opt = find_option(arg);
355 int n = n_arguments(opt);
361 /* Check if it's a tty name and copy it if so */
362 (void) setdevname(arg, 1);
368 * options_from_file - Read a string of options from a file,
369 * and interpret them.
372 options_from_file(filename, must_exist, check_prot, priv)
379 int i, newline, ret, err;
384 char args[MAXARGS][MAXWORDLEN];
385 char cmd[MAXWORDLEN];
389 f = fopen(filename, "r");
394 if (!must_exist && err == ENOENT)
397 option_error("Can't open options file %s: %m", filename);
401 oldpriv = privileged_option;
402 privileged_option = priv;
403 oldsource = option_source;
404 option_source = strdup(filename);
405 if (option_source == NULL)
406 option_source = "file";
408 while (getword(f, cmd, &newline, filename)) {
410 * First see if it's a command.
412 opt = find_option(cmd);
414 int n = n_arguments(opt);
415 for (i = 0; i < n; ++i) {
416 if (!getword(f, args[i], &newline, filename)) {
418 "In file %s: too few parameters for option '%s'",
424 current_option = cmd;
425 if ((opt->flags & OPT_DEVEQUIV) && devnam_fixed) {
426 option_error("the %s option may not be used in the %s file",
430 if (!process_option(opt, argv))
436 * Maybe a tty name, speed or IP address?
438 if ((i = setdevname(cmd)) == 0
439 && (i = setspeed(cmd)) == 0
440 && (i = setipaddr(cmd)) == 0) {
441 option_error("In file %s: unrecognized option '%s'",
445 if (i < 0) /* error */
452 privileged_option = oldpriv;
453 option_source = oldsource;
458 * options_from_user - See if the use has a ~/.ppprc file,
459 * and if so, interpret options from it.
464 char *user, *path, *file;
469 pw = getpwuid(getuid());
470 if (pw == NULL || (user = pw->pw_dir) == NULL || user[0] == 0)
472 file = _PATH_USEROPT;
473 pl = strlen(user) + strlen(file) + 2;
476 novm("init file name");
477 slprintf(path, pl, "%s/%s", user, file);
478 ret = options_from_file(path, 0, 1, privileged);
484 * options_for_tty - See if an options file exists for the serial
485 * device, and if so, interpret options from it.
490 char *dev, *path, *p;
495 if (strncmp(dev, "/dev/", 5) == 0)
497 if (dev[0] == 0 || strcmp(dev, "tty") == 0)
498 return 1; /* don't look for /etc/ppp/options.tty */
499 pl = strlen(_PATH_TTYOPT) + strlen(dev) + 1;
502 novm("tty init file name");
503 slprintf(path, pl, "%s%s", _PATH_TTYOPT, dev);
504 /* Turn slashes into dots, for Solaris case (e.g. /dev/term/a) */
505 for (p = path + strlen(_PATH_TTYOPT); *p != 0; ++p)
508 ret = options_from_file(path, 0, 0, 1);
514 * options_from_list - process a string of options in a wordlist.
517 options_from_list(w, priv)
525 privileged_option = priv;
526 option_source = "secrets file";
530 * First see if it's a command.
532 opt = find_option(w->word);
534 int n = n_arguments(opt);
535 struct wordlist *w0 = w;
536 for (i = 0; i < n; ++i) {
540 "In secrets file: too few parameters for option '%s'",
546 current_option = w0->word;
547 if (!process_option(opt, argv))
553 * Maybe a tty name, speed or IP address?
555 if ((i = setdevname(w->word)) == 0
556 && (i = setspeed(w->word)) == 0
557 && (i = setipaddr(w->word)) == 0) {
558 option_error("In secrets file: unrecognized option '%s'",
562 if (i < 0) /* error */
572 * find_option - scan the option lists for the various protocols
573 * looking for an entry with the given name.
574 * This could be optimized by using a hash table.
583 for (opt = general_options; opt->name != NULL; ++opt)
584 if (strcmp(name, opt->name) == 0)
586 for (opt = auth_options; opt->name != NULL; ++opt)
587 if (strcmp(name, opt->name) == 0)
589 for (i = 0; protocols[i] != NULL; ++i)
590 if ((opt = protocols[i]->options) != NULL)
591 for (; opt->name != NULL; ++opt)
592 if (strcmp(name, opt->name) == 0)
598 * process_option - process one new-style option.
601 process_option(opt, argv)
608 int (*parser) __P((char **));
610 if ((opt->flags & OPT_PREPASS) == 0 && prepass)
612 if ((opt->flags & OPT_INITONLY) && phase != PHASE_INITIALIZE) {
613 option_error("it's too late to use the %s option", opt->name);
616 if ((opt->flags & OPT_PRIV) && !privileged_option) {
617 option_error("using the %s option requires root privilege", opt->name);
620 if ((opt->flags & OPT_ENABLE) && *(bool *)(opt->addr2) == 0) {
621 option_error("%s option is disabled", opt->name);
624 if ((opt->flags & OPT_PRIVFIX) && !privileged_option) {
625 struct option_info *ip = (struct option_info *) opt->addr2;
626 if (ip && ip->priv) {
627 option_error("%s option cannot be overridden", opt->name);
634 v = opt->flags & OPT_VALUE;
635 *(bool *)(opt->addr) = v;
636 if (opt->addr2 && (opt->flags & OPT_A2COPY))
637 *(bool *)(opt->addr2) = v;
642 if ((opt->flags & OPT_NOARG) == 0) {
643 if (!int_option(*argv, &iv))
645 if ((((opt->flags & OPT_LLIMIT) && iv < opt->lower_limit)
646 || ((opt->flags & OPT_ULIMIT) && iv > opt->upper_limit))
647 && !((opt->flags & OPT_ZEROOK && iv == 0))) {
648 char *zok = (opt->flags & OPT_ZEROOK)? " zero or": "";
649 switch (opt->flags & OPT_LIMITS) {
651 option_error("%s value must be%s >= %d",
652 opt->name, zok, opt->lower_limit);
655 option_error("%s value must be%s <= %d",
656 opt->name, zok, opt->upper_limit);
659 option_error("%s value must be%s between %d and %d",
660 opt->name, opt->lower_limit, opt->upper_limit);
666 a = opt->flags & OPT_VALUE;
668 a -= 256; /* sign extend */
670 if (opt->flags & OPT_INC)
671 iv += *(int *)(opt->addr);
672 if ((opt->flags & OPT_NOINCR) && !privileged_option) {
673 int oldv = *(int *)(opt->addr);
674 if ((opt->flags & OPT_ZEROINF) ?
675 (oldv != 0 && (iv == 0 || iv > oldv)) : (iv > oldv)) {
676 option_error("%s value cannot be increased", opt->name);
680 *(int *)(opt->addr) = iv;
681 if (opt->addr2 && (opt->flags & OPT_A2COPY))
682 *(int *)(opt->addr2) = iv;
686 if (opt->flags & OPT_NOARG) {
687 v = opt->flags & OPT_VALUE;
688 } else if (!number_option(*argv, &v, 16))
690 if (opt->flags & OPT_OR)
691 v |= *(u_int32_t *)(opt->addr);
692 *(u_int32_t *)(opt->addr) = v;
693 if (opt->addr2 && (opt->flags & OPT_A2COPY))
694 *(u_int32_t *)(opt->addr2) = v;
698 if (opt->flags & OPT_STATIC) {
699 strlcpy((char *)(opt->addr), *argv, opt->upper_limit);
703 novm("option argument");
704 *(char **)(opt->addr) = sv;
708 case o_special_noarg:
710 parser = (int (*) __P((char **))) opt->addr;
711 if (!(*parser)(argv))
717 if (opt->flags & OPT_A2INFO) {
718 struct option_info *ip = (struct option_info *) opt->addr2;
719 ip->priv = privileged_option;
720 ip->source = option_source;
721 } else if ((opt->flags & (OPT_A2COPY|OPT_ENABLE)) == 0)
722 *(bool *)(opt->addr2) = 1;
729 * n_arguments - tell how many arguments an option takes
735 return (opt->type == o_bool || opt->type == o_special_noarg
736 || (opt->flags & OPT_NOARG))? 0: 1;
740 * usage - print out a message telling how to use the program.
745 if (phase == PHASE_INITIALIZE)
746 fprintf(stderr, usage_string, VERSION, PATCHLEVEL, IMPLEMENTATION,
751 * showhelp - print out usage message and exit.
757 if (phase == PHASE_INITIALIZE) {
765 * showversion - print out the version number and exit.
771 if (phase == PHASE_INITIALIZE) {
772 fprintf(stderr, "pppd version %s.%d%s\n",
773 VERSION, PATCHLEVEL, IMPLEMENTATION);
780 * option_error - print a message about an error in an option.
781 * The message is logged, and also sent to
782 * stderr if phase == PHASE_INITIALIZE.
785 option_error __V((char *fmt, ...))
795 fmt = va_arg(args, char *);
801 vslprintf(buf, sizeof(buf), fmt, args);
803 if (phase == PHASE_INITIALIZE)
804 fprintf(stderr, "%s: %s\n", progname, buf);
805 syslog(LOG_ERR, "%s", buf);
810 * readable - check if a file is readable by the real user.
823 if (fstat(fd, &sbuf) != 0)
825 if (sbuf.st_uid == uid)
826 return sbuf.st_mode & S_IRUSR;
827 if (sbuf.st_gid == getgid())
828 return sbuf.st_mode & S_IRGRP;
829 for (i = 0; i < ngroups; ++i)
830 if (sbuf.st_gid == groups[i])
831 return sbuf.st_mode & S_IRGRP;
832 return sbuf.st_mode & S_IROTH;
837 * Read a word from a file.
838 * Words are delimited by white-space or by quotes (" or ').
839 * Quotes, white-space and \ may be escaped with \.
840 * \<newline> is ignored.
843 getword(f, word, newlinep, filename)
851 int value, digit, got, n;
853 #define isoctal(c) ((c) >= '0' && (c) < '8')
861 * First skip white-space and comments.
869 * A newline means the end of a comment; backslash-newline
870 * is ignored. Note that we cannot have escape && comment.
882 * Ignore characters other than newline in a comment.
888 * If this character is escaped, we have a word start.
894 * If this is the escape character, look at the next character.
902 * If this is the start of a comment, ignore the rest of the line.
910 * A non-whitespace character is the start of a word.
917 * Save the delimiter for quoted strings.
919 if (!escape && (c == '"' || c == '\'')) {
926 * Process characters until the end of the word.
931 * This character is escaped: backslash-newline is ignored,
932 * various other characters indicate particular values
933 * as for C backslash-escapes.
968 * \ddd octal sequence
971 for (n = 0; n < 3 && isoctal(c); ++n) {
972 value = (value << 3) + (c & 07);
981 * \x<hex_string> sequence
985 for (n = 0; n < 2 && isxdigit(c); ++n) {
986 digit = toupper(c) - '0';
988 digit += '0' + 10 - 'A';
989 value = (value << 4) + digit;
997 * Otherwise the character stands for itself.
1004 * Store the resulting character for the escape sequence.
1006 if (len < MAXWORDLEN-1)
1017 * Not escaped: see if we've reached the end of the word.
1023 if (isspace(c) || c == '#') {
1030 * Backslash starts an escape sequence.
1039 * An ordinary character: store it in the word and get another.
1041 if (len < MAXWORDLEN-1)
1049 * End of the word: check for errors.
1055 option_error("Error reading %s: %m", filename);
1059 * If len is zero, then we didn't find a word before the
1067 * Warn if the word was too long, and append a terminating null.
1069 if (len >= MAXWORDLEN) {
1070 option_error("warning: word in file %s too long (%.20s...)",
1072 len = MAXWORDLEN - 1;
1083 * number_option - parse an unsigned numeric parameter for an option.
1086 number_option(str, valp, base)
1093 *valp = strtoul(str, &ptr, base);
1095 option_error("invalid numeric parameter '%s' for %s option",
1096 str, current_option);
1104 * int_option - like number_option, but valp is int *,
1105 * the base is assumed to be 0, and *valp is not changed
1106 * if there is an error.
1109 int_option(str, valp)
1115 if (!number_option(str, &v, 0))
1123 * The following procedures parse options.
1127 * readfile - take commands from a file.
1133 return options_from_file(*argv, 1, 1, privileged_option);
1137 * callfile - take commands from /etc/ppp/peers/<name>.
1138 * Name may not contain /../, start with / or ../, or end in /..
1144 char *fname, *arg, *p;
1149 if (arg[0] == '/' || arg[0] == 0)
1152 for (p = arg; *p != 0; ) {
1153 if (p[0] == '.' && p[1] == '.' && (p[2] == '/' || p[2] == 0)) {
1157 while (*p != '/' && *p != 0)
1164 option_error("call option value may not contain .. or start with /");
1168 l = strlen(arg) + strlen(_PATH_PEERFILES) + 1;
1169 if ((fname = (char *) malloc(l)) == NULL)
1170 novm("call file name");
1171 slprintf(fname, l, "%s%s", _PATH_PEERFILES, arg);
1173 ok = options_from_file(fname, 1, 1, 1);
1181 * setpdebug - Set libpcap debugging level.
1187 return int_option(*argv, &dflag);
1191 * setpassfilter - Set the pass filter for packets
1197 pc.linktype = DLT_PPP;
1198 pc.snapshot = PPP_HDRLEN;
1200 if (pcap_compile(&pc, &pass_filter, *argv, 1, netmask) == 0)
1202 option_error("error in pass-filter expression: %s\n", pcap_geterr(&pc));
1207 * setactivefilter - Set the active filter for packets
1210 setactivefilter(argv)
1213 pc.linktype = DLT_PPP;
1214 pc.snapshot = PPP_HDRLEN;
1216 if (pcap_compile(&pc, &active_filter, *argv, 1, netmask) == 0)
1218 option_error("error in active-filter expression: %s\n", pcap_geterr(&pc));
1224 * noopt - Disable all options.
1230 BZERO((char *) &lcp_wantoptions[0], sizeof (struct lcp_options));
1231 BZERO((char *) &lcp_allowoptions[0], sizeof (struct lcp_options));
1232 BZERO((char *) &ipcp_wantoptions[0], sizeof (struct ipcp_options));
1233 BZERO((char *) &ipcp_allowoptions[0], sizeof (struct ipcp_options));
1239 * setdomain - Set domain name to append to hostname
1245 if (!privileged_option) {
1246 option_error("using the domain option requires root privilege");
1249 gethostname(hostname, MAXNAMELEN);
1252 strncat(hostname, ".", MAXNAMELEN - strlen(hostname));
1253 strncat(hostname, *argv, MAXNAMELEN - strlen(hostname));
1255 hostname[MAXNAMELEN-1] = 0;
1261 * setspeed - Set the speed.
1270 spd = strtol(arg, &ptr, 0);
1271 if (ptr == arg || *ptr != 0 || spd == 0)
1279 * setdevname - Set the device name.
1285 struct stat statbuf;
1286 char dev[MAXPATHLEN];
1291 if (strncmp("/dev/", cp, 5) != 0) {
1292 strlcpy(dev, "/dev/", sizeof(dev));
1293 strlcat(dev, cp, sizeof(dev));
1298 * Check if there is a character device by this name.
1300 if (stat(cp, &statbuf) < 0) {
1301 if (errno == ENOENT)
1303 option_error("Couldn't stat %s: %m", cp);
1306 if (!S_ISCHR(statbuf.st_mode)) {
1307 option_error("%s is not a character device", cp);
1311 if (phase != PHASE_INITIALIZE) {
1312 option_error("device name cannot be changed after initialization");
1314 } else if (devnam_fixed) {
1315 option_error("per-tty options file may not specify device name");
1319 if (devnam_info.priv && !privileged_option) {
1320 option_error("device name cannot be overridden");
1324 strlcpy(devnam, cp, sizeof(devnam));
1327 devnam_info.priv = privileged_option;
1328 devnam_info.source = option_source;
1335 * setipaddr - Set the IP address
1343 u_int32_t local, remote;
1344 ipcp_options *wo = &ipcp_wantoptions[0];
1347 * IP address pair separated by ":".
1349 if ((colon = strchr(arg, ':')) == NULL)
1355 * If colon first character, then no local addr.
1359 if ((local = inet_addr(arg)) == -1) {
1360 if ((hp = gethostbyname(arg)) == NULL) {
1361 option_error("unknown host: %s", arg);
1364 local = *(u_int32_t *)hp->h_addr;
1367 if (bad_ip_adrs(local)) {
1368 option_error("bad local IP address %s", ip_ntoa(local));
1372 wo->ouraddr = local;
1377 * If colon last character, then no remote addr.
1379 if (*++colon != '\0') {
1380 if ((remote = inet_addr(colon)) == -1) {
1381 if ((hp = gethostbyname(colon)) == NULL) {
1382 option_error("unknown host: %s", colon);
1385 remote = *(u_int32_t *)hp->h_addr;
1386 if (remote_name[0] == 0)
1387 strlcpy(remote_name, colon, sizeof(remote_name));
1390 if (bad_ip_adrs(remote)) {
1391 option_error("bad remote IP address %s", ip_ntoa(remote));
1395 wo->hisaddr = remote;
1403 * setnetmask - set the netmask to be used on the interface.
1414 * Unfortunately, if we use inet_addr, we can't tell whether
1415 * a result of all 1s is an error or a valid 255.255.255.255.
1421 b = strtoul(p, &endp, 0);
1424 if (b < 0 || b > 255) {
1426 /* accept e.g. 0xffffff00 */
1432 mask |= b << (n * 8);
1434 if (*p != '.' || n == 0)
1441 if (*p != 0 || (netmask & ~mask) != 0) {
1442 option_error("invalid netmask value '%s'", *argv);
1454 lcp_wantoptions[0].asyncmap |= 0x000A0000; /* escape ^S and ^Q */
1455 lcp_wantoptions[0].neg_asyncmap = 1;
1467 if (!privileged_option)
1469 fd = open(*argv, O_WRONLY | O_APPEND);
1471 if (!privileged_option)
1475 option_error("Can't open log file %s: %m", *argv);
1478 if (log_to_file && log_to_fd >= 0)