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.16 1994/09/21 06:47:37 paulus Exp $";
34 #include <sys/types.h>
36 #include <netinet/in.h>
39 #include "pathnames.h"
40 #include "patchlevel.h"
52 char *strdup __P((char *));
56 #define GIDSET_TYPE gid_t
60 * Option variables and default values.
62 int debug = 0; /* Debug flag */
63 int kdebugflag = 0; /* Tell kernel to print debug messages */
64 int default_device = 1; /* Using /dev/tty or equivalent */
65 char devnam[MAXPATHLEN] = "/dev/tty"; /* Device name */
66 int crtscts = 0; /* Use hardware flow control */
67 int modem = 1; /* Use modem control lines */
68 int inspeed = 0; /* Input/Output speed requested */
69 u_int32_t netmask = 0; /* IP netmask to set on interface */
70 int lockflag = 0; /* Create lock file to lock the serial dev */
71 int nodetach = 0; /* Don't detach from controlling tty */
72 char *connector = NULL; /* Script to establish physical link */
73 char *disconnector = NULL; /* Script to disestablish physical link */
74 char user[MAXNAMELEN]; /* Username for PAP */
75 char passwd[MAXSECRETLEN]; /* Password for PAP */
76 int auth_required = 0; /* Peer is required to authenticate */
77 int defaultroute = 0; /* assign default route through interface */
78 int proxyarp = 0; /* Set up proxy ARP entry for peer */
79 int persist = 0; /* Reopen link after it goes down */
80 int uselogin = 0; /* Use /etc/passwd for checking PAP */
81 int lcp_echo_interval = 0; /* Interval between LCP echo-requests */
82 int lcp_echo_fails = 0; /* Tolerance to unanswered echo-requests */
83 char our_name[MAXNAMELEN]; /* Our name for authentication purposes */
84 char remote_name[MAXNAMELEN]; /* Peer's name for authentication */
85 int usehostname = 0; /* Use hostname for our_name */
86 int disable_defaultip = 0; /* Don't use hostname for default IP adrs */
91 static int setdebug __P((void));
92 static int setkdebug __P((char **));
93 static int setpassive __P((void));
94 static int setsilent __P((void));
95 static int noopt __P((void));
96 static int setnovj __P((void));
97 static int setnovjccomp __P((void));
98 static int setvjslots __P((char **));
99 static int reqpap __P((void));
100 static int nopap __P((void));
101 static int setupapfile __P((char **));
102 static int nochap __P((void));
103 static int reqchap __P((void));
104 static int setspeed __P((char *));
105 static int noaccomp __P((void));
106 static int noasyncmap __P((void));
107 static int noipaddr __P((void));
108 static int nomagicnumber __P((void));
109 static int setasyncmap __P((char **));
110 static int setescape __P((char **));
111 static int setmru __P((char **));
112 static int setmtu __P((char **));
113 static int nomru __P((void));
114 static int nopcomp __P((void));
115 static int setconnector __P((char **));
116 static int setdisconnector __P((char **));
117 static int setdomain __P((char **));
118 static int setnetmask __P((char **));
119 static int setcrtscts __P((void));
120 static int setnocrtscts __P((void));
121 static int setxonxoff __P((void));
122 static int setnodetach __P((void));
123 static int setmodem __P((void));
124 static int setlocal __P((void));
125 static int setlock __P((void));
126 static int setname __P((char **));
127 static int setuser __P((char **));
128 static int setremote __P((char **));
129 static int setauth __P((void));
130 static int readfile __P((char **));
131 static int setdefaultroute __P((void));
132 static int setproxyarp __P((void));
133 static int setpersist __P((void));
134 static int setdologin __P((void));
135 static int setusehostname __P((void));
136 static int setnoipdflt __P((void));
137 static int setlcptimeout __P((char **));
138 static int setlcpterm __P((char **));
139 static int setlcpconf __P((char **));
140 static int setlcpfails __P((char **));
141 static int setipcptimeout __P((char **));
142 static int setipcpterm __P((char **));
143 static int setipcpconf __P((char **));
144 static int setipcpfails __P((char **));
145 static int setpaptimeout __P((char **));
146 static int setpapreqs __P((char **));
147 static int setchaptimeout __P((char **));
148 static int setchapchal __P((char **));
149 static int setchapintv __P((char **));
150 static int setipcpaccl __P((void));
151 static int setipcpaccr __P((void));
152 static int setlcpechointv __P((char **));
153 static int setlcpechofails __P((char **));
154 static int setbsdcomp __P((char **));
155 static int setnobsdcomp __P((void));
157 static int number_option __P((char *, long *, int));
158 static int readable __P((int fd));
168 {"-all", 0, noopt}, /* Don't request/allow any options */
169 {"-ac", 0, noaccomp}, /* Disable Address/Control compress */
170 {"-am", 0, noasyncmap}, /* Disable asyncmap negotiation */
171 {"-as", 1, setasyncmap}, /* set the desired async map */
172 {"-d", 0, setdebug}, /* Increase debugging level */
173 {"-detach", 0, setnodetach}, /* don't fork */
174 {"-ip", 0, noipaddr}, /* Disable IP address negotiation */
175 {"-mn", 0, nomagicnumber}, /* Disable magic number negotiation */
176 {"-mru", 0, nomru}, /* Disable mru negotiation */
177 {"-p", 0, setpassive}, /* Set passive mode */
178 {"-pc", 0, nopcomp}, /* Disable protocol field compress */
179 {"+ua", 1, setupapfile}, /* Get PAP user and password from file */
180 {"+pap", 0, reqpap}, /* Require PAP auth from peer */
181 {"-pap", 0, nopap}, /* Don't allow UPAP authentication with peer */
182 {"+chap", 0, reqchap}, /* Require CHAP authentication from peer */
183 {"-chap", 0, nochap}, /* Don't allow CHAP authentication with peer */
184 {"-vj", 0, setnovj}, /* disable VJ compression */
185 {"-vjccomp", 0, setnovjccomp}, /* disable VJ connection-ID compression */
186 {"vj-max-slots", 1, setvjslots}, /* Set maximum VJ header slots */
187 {"asyncmap", 1, setasyncmap}, /* set the desired async map */
188 {"escape", 1, setescape}, /* set chars to escape on transmission */
189 {"connect", 1, setconnector}, /* A program to set up a connection */
190 {"disconnect", 1, setdisconnector}, /* program to disconnect serial dev. */
191 {"crtscts", 0, setcrtscts}, /* set h/w flow control */
192 {"-crtscts", 0, setnocrtscts}, /* clear h/w flow control */
193 {"xonxoff", 0, setxonxoff}, /* set s/w flow control */
194 {"debug", 0, setdebug}, /* Increase debugging level */
195 {"kdebug", 1, setkdebug}, /* Enable kernel-level debugging */
196 {"domain", 1, setdomain}, /* Add given domain name to hostname*/
197 {"mru", 1, setmru}, /* Set MRU value for negotiation */
198 {"mtu", 1, setmtu}, /* Set our MTU */
199 {"netmask", 1, setnetmask}, /* set netmask */
200 {"passive", 0, setpassive}, /* Set passive mode */
201 {"silent", 0, setsilent}, /* Set silent mode */
202 {"modem", 0, setmodem}, /* Use modem control lines */
203 {"local", 0, setlocal}, /* Don't use modem control lines */
204 {"lock", 0, setlock}, /* Lock serial device (with lock file) */
205 {"name", 1, setname}, /* Set local name for authentication */
206 {"user", 1, setuser}, /* Set username for PAP auth with peer */
207 {"usehostname", 0, setusehostname}, /* Must use hostname for auth. */
208 {"remotename", 1, setremote}, /* Set remote name for authentication */
209 {"auth", 0, setauth}, /* Require authentication from peer */
210 {"file", 1, readfile}, /* Take options from a file */
211 {"defaultroute", 0, setdefaultroute}, /* Add default route */
212 {"proxyarp", 0, setproxyarp}, /* Add proxy ARP entry */
213 {"persist", 0, setpersist}, /* Keep on reopening connection after close */
214 {"login", 0, setdologin}, /* Use system password database for UPAP */
215 {"noipdefault", 0, setnoipdflt}, /* Don't use name for default IP adrs */
216 {"lcp-echo-failure", 1, setlcpechofails}, /* consecutive echo failures */
217 {"lcp-echo-interval", 1, setlcpechointv}, /* time for lcp echo events */
218 {"lcp-restart", 1, setlcptimeout}, /* Set timeout for LCP */
219 {"lcp-max-terminate", 1, setlcpterm}, /* Set max #xmits for term-reqs */
220 {"lcp-max-configure", 1, setlcpconf}, /* Set max #xmits for conf-reqs */
221 {"lcp-max-failure", 1, setlcpfails}, /* Set max #conf-naks for LCP */
222 {"ipcp-restart", 1, setipcptimeout}, /* Set timeout for IPCP */
223 {"ipcp-max-terminate", 1, setipcpterm}, /* Set max #xmits for term-reqs */
224 {"ipcp-max-configure", 1, setipcpconf}, /* Set max #xmits for conf-reqs */
225 {"ipcp-max-failure", 1, setipcpfails}, /* Set max #conf-naks for IPCP */
226 {"pap-restart", 1, setpaptimeout}, /* Set timeout for UPAP */
227 {"pap-max-authreq", 1, setpapreqs}, /* Set max #xmits for auth-reqs */
228 {"chap-restart", 1, setchaptimeout}, /* Set timeout for CHAP */
229 {"chap-max-challenge", 1, setchapchal}, /* Set max #xmits for challenge */
230 {"chap-interval", 1, setchapintv}, /* Set interval for rechallenge */
231 {"ipcp-accept-local", 0, setipcpaccl}, /* Accept peer's address for us */
232 {"ipcp-accept-remote", 0, setipcpaccr}, /* Accept peer's address for it */
233 {"bsdcomp", 1, setbsdcomp}, /* request BSD-Compress */
234 {"-bsdcomp", 0, setnobsdcomp}, /* don't allow BSD-Compress */
239 #ifndef IMPLEMENTATION
240 #define IMPLEMENTATION ""
243 static char *usage_string = "\
244 pppd version %s patch level %d%s\n\
245 Usage: %s [ arguments ], where arguments are:\n\
246 <device> Communicate over the named device\n\
247 <speed> Set the baud rate to <speed>\n\
248 <loc>:<rem> Set the local and/or remote interface IP\n\
249 addresses. Either one may be omitted.\n\
250 asyncmap <n> Set the desired async map to hex <n>\n\
251 auth Require authentication from peer\n\
252 connect <p> Invoke shell command <p> to set up the serial line\n\
253 crtscts Use hardware RTS/CTS flow control\n\
254 defaultroute Add default route through interface\n\
255 file <f> Take options from file <f>\n\
256 modem Use modem control lines\n\
257 mru <n> Set MRU value to <n> for negotiation\n\
258 netmask <n> Set interface netmask to <n>\n\
259 See pppd(8) for more options.\n\
264 * parse_args - parse a string of arguments, from the command
265 * line or from a file.
268 parse_args(argc, argv)
281 * First see if it's a command.
283 for (cmdp = cmds; cmdp->cmd_name; cmdp++)
284 if (!strcmp(arg, cmdp->cmd_name))
287 if (cmdp->cmd_name != NULL) {
288 if (argc < cmdp->num_args) {
289 fprintf(stderr, "Too few parameters for command %s\n", arg);
292 if (!(*cmdp->cmd_func)(argv))
294 argc -= cmdp->num_args;
295 argv += cmdp->num_args;
299 * Maybe a tty name, speed or IP address?
301 if ((ret = setdevname(arg)) == 0
302 && (ret = setspeed(arg)) == 0
303 && (ret = setipaddr(arg)) == 0) {
304 fprintf(stderr, "%s: unrecognized command\n", arg);
308 if (ret < 0) /* error */
316 * usage - print out a message telling how to use the program.
320 fprintf(stderr, usage_string, VERSION, PATCHLEVEL, IMPLEMENTATION,
325 * options_from_file - Read a string of options from a file,
326 * and interpret them.
329 options_from_file(filename, must_exist, check_prot)
338 char args[MAXARGS][MAXWORDLEN];
339 char cmd[MAXWORDLEN];
341 if ((f = fopen(filename, "r")) == NULL) {
342 if (!must_exist && errno == ENOENT)
347 if (check_prot && !readable(fileno(f))) {
348 fprintf(stderr, "%s: access denied\n", filename);
353 while (getword(f, cmd, &newline, filename)) {
355 * First see if it's a command.
357 for (cmdp = cmds; cmdp->cmd_name; cmdp++)
358 if (!strcmp(cmd, cmdp->cmd_name))
361 if (cmdp->cmd_name != NULL) {
362 for (i = 0; i < cmdp->num_args; ++i) {
363 if (!getword(f, args[i], &newline, filename)) {
365 "In file %s: too few parameters for command %s\n",
372 if (!(*cmdp->cmd_func)(argv)) {
379 * Maybe a tty name, speed or IP address?
381 if ((ret = setdevname(cmd)) == 0
382 && (ret = setspeed(cmd)) == 0
383 && (ret = setipaddr(cmd)) == 0) {
384 fprintf(stderr, "In file %s: unrecognized command %s\n",
389 if (ret < 0) /* error */
397 * options_from_user - See if the use has a ~/.ppprc file,
398 * and if so, interpret options from it.
403 char *user, *path, *file;
407 pw = getpwuid(getuid());
408 if (pw == NULL || (user = pw->pw_dir) == NULL || user[0] == 0)
410 file = _PATH_USEROPT;
411 path = malloc(strlen(user) + strlen(file) + 2);
413 novm("init file name");
417 ret = options_from_file(path, 0, 1);
423 * options_for_tty - See if an options file exists for the serial
424 * device, and if so, interpret options from it.
432 dev = strrchr(devnam, '/');
437 if (strcmp(dev, "tty") == 0)
438 return 1; /* don't look for /etc/ppp/options.tty */
439 path = malloc(strlen(_PATH_TTYOPT) + strlen(dev) + 1);
441 novm("tty init file name");
442 strcpy(path, _PATH_TTYOPT);
444 ret = options_from_file(path, 0, 0);
450 * readable - check if a file is readable by the real user.
459 GIDSET_TYPE groups[NGROUPS_MAX];
464 if (fstat(fd, &sbuf) != 0)
466 if (sbuf.st_uid == uid)
467 return sbuf.st_mode & S_IRUSR;
468 if (sbuf.st_gid == getgid())
469 return sbuf.st_mode & S_IRGRP;
470 ngroups = getgroups(NGROUPS_MAX, groups);
471 for (i = 0; i < ngroups; ++i)
472 if (sbuf.st_gid == groups[i])
473 return sbuf.st_mode & S_IRGRP;
474 return sbuf.st_mode & S_IROTH;
478 * Read a word from a file.
479 * Words are delimited by white-space or by quotes (").
480 * Quotes, white-space and \ may be escaped with \.
481 * \<newline> is ignored.
484 getword(f, word, newlinep, filename)
499 * First skip white-space and comments
501 while ((c = getc(f)) != EOF) {
504 * \<newline> is ignored; \ followed by anything else
507 if ((c = getc(f)) == '\n')
514 *newlinep = 1; /* next word starts a line */
516 /* comment - ignore until EOF or \n */
517 while ((c = getc(f)) != EOF && c != '\n')
522 } else if (!isspace(c))
527 * End of file or error - fail
539 * Is this character escaped by \ ?
543 --len; /* ignore \<newline> */
544 else if (c == '"' || isspace(c) || c == '\\')
545 word[len-1] = c; /* put special char in word */
547 if (len < MAXWORDLEN-1)
552 } else if (c == '"') {
554 } else if (!quoted && (isspace(c) || c == '#')) {
558 if (len < MAXWORDLEN-1)
564 if ((c = getc(f)) == EOF)
573 if (len >= MAXWORDLEN) {
574 word[MAXWORDLEN-1] = 0;
575 fprintf(stderr, "%s: warning: word in file %s too long (%.20s...)\n",
576 progname, filename, word);
584 * number_option - parse a numeric parameter for an option
587 number_option(str, valp, base)
594 *valp = strtol(str, &ptr, base);
596 fprintf(stderr, "%s: invalid number: %s\n", progname, str);
604 * int_option - like number_option, but valp is int *,
605 * the base is assumed to be 0, and *valp is not changed
606 * if there is an error.
609 int_option(str, valp)
615 if (!number_option(str, &v, 0))
623 * The following procedures execute commands.
627 * readfile - take commands from a file.
633 return options_from_file(*argv, 1, 1);
637 * setdebug - Set debug (command line argument).
647 * setkdebug - Set kernel debugging level.
653 return int_option(*argv, &kdebugflag);
657 * noopt - Disable all options.
662 BZERO((char *) &lcp_wantoptions[0], sizeof (struct lcp_options));
663 BZERO((char *) &lcp_allowoptions[0], sizeof (struct lcp_options));
664 BZERO((char *) &ipcp_wantoptions[0], sizeof (struct ipcp_options));
665 BZERO((char *) &ipcp_allowoptions[0], sizeof (struct ipcp_options));
670 * noaccomp - Disable Address/Control field compression negotiation.
675 lcp_wantoptions[0].neg_accompression = 0;
676 lcp_allowoptions[0].neg_accompression = 0;
682 * noasyncmap - Disable async map negotiation.
687 lcp_wantoptions[0].neg_asyncmap = 0;
688 lcp_allowoptions[0].neg_asyncmap = 0;
694 * noipaddr - Disable IP address negotiation.
699 ipcp_wantoptions[0].neg_addr = 0;
700 ipcp_allowoptions[0].neg_addr = 0;
706 * nomagicnumber - Disable magic number negotiation.
711 lcp_wantoptions[0].neg_magicnumber = 0;
712 lcp_allowoptions[0].neg_magicnumber = 0;
718 * nomru - Disable mru negotiation.
723 lcp_wantoptions[0].neg_mru = 0;
724 lcp_allowoptions[0].neg_mru = 0;
730 * setmru - Set MRU for negotiation.
738 if (!number_option(*argv, &mru, 0))
740 lcp_wantoptions[0].mru = mru;
741 lcp_wantoptions[0].neg_mru = 1;
747 * setmru - Set the largest MTU we'll use.
755 if (!number_option(*argv, &mtu, 0))
757 if (mtu < MINMRU || mtu > MAXMRU) {
758 fprintf(stderr, "mtu option value of %d is too %s\n", mtu,
759 (mtu < MINMRU? "small": "large"));
762 lcp_allowoptions[0].mru = mtu;
768 * nopcomp - Disable Protocol field compression negotiation.
773 lcp_wantoptions[0].neg_pcompression = 0;
774 lcp_allowoptions[0].neg_pcompression = 0;
780 * setpassive - Set passive mode (don't give up if we time out sending
781 * LCP configure-requests).
786 lcp_wantoptions[0].passive = 1;
792 * setsilent - Set silent mode (don't start sending LCP configure-requests
793 * until we get one from the peer).
798 lcp_wantoptions[0].silent = 1;
804 * nopap - Disable PAP authentication with peer.
809 lcp_allowoptions[0].neg_upap = 0;
815 * reqpap - Require PAP authentication from peer.
820 lcp_wantoptions[0].neg_upap = 1;
826 * setupapfile - specifies UPAP info for authenticating with peer.
835 lcp_allowoptions[0].neg_upap = 1;
837 /* open user info file */
838 if ((ufile = fopen(*argv, "r")) == NULL) {
839 fprintf(stderr, "unable to open user login data file %s\n", *argv);
842 if (!readable(fileno(ufile))) {
843 fprintf(stderr, "%s: access denied\n", *argv);
846 check_access(ufile, *argv);
849 if (fgets(user, MAXNAMELEN - 1, ufile) == NULL
850 || fgets(passwd, MAXSECRETLEN - 1, ufile) == NULL){
851 fprintf(stderr, "Unable to read user login data file %s.\n", *argv);
856 /* get rid of newlines */
858 if (l > 0 && user[l-1] == '\n')
861 if (l > 0 && passwd[l-1] == '\n')
869 * nochap - Disable CHAP authentication with peer.
874 lcp_allowoptions[0].neg_chap = 0;
880 * reqchap - Require CHAP authentication from peer.
885 lcp_wantoptions[0].neg_chap = 1;
892 * setnovj - disable vj compression
897 ipcp_wantoptions[0].neg_vj = 0;
898 ipcp_allowoptions[0].neg_vj = 0;
904 * setnovjccomp - disable VJ connection-ID compression
909 ipcp_wantoptions[0].cflag = 0;
910 ipcp_allowoptions[0].cflag = 0;
915 * setvjslots - set maximum number of connection slots for VJ compression
923 if (!int_option(*argv, &value))
925 if (value < 2 || value > 16) {
926 fprintf(stderr, "pppd: vj-max-slots value must be between 2 and 16\n");
929 ipcp_wantoptions [0].maxslotindex =
930 ipcp_allowoptions[0].maxslotindex = value - 1;
936 * setconnector - Set a program to connect to a serial line
942 connector = strdup(*argv);
943 if (connector == NULL)
944 novm("connector string");
950 * setdisconnector - Set a program to disconnect from the serial line
953 setdisconnector(argv)
956 disconnector = strdup(*argv);
957 if (disconnector == NULL)
958 novm("disconnector string");
965 * setdomain - Set domain name to append to hostname
971 strncat(hostname, *argv, MAXNAMELEN - strlen(hostname));
972 hostname[MAXNAMELEN-1] = 0;
978 * setasyncmap - add bits to asyncmap (what we request peer to escape).
986 if (!number_option(*argv, &asyncmap, 16))
988 lcp_wantoptions[0].asyncmap |= asyncmap;
989 lcp_wantoptions[0].neg_asyncmap = 1;
995 * setescape - add chars to the set we escape on transmission.
1007 n = strtol(p, &endp, 16);
1009 fprintf(stderr, "%s: invalid hex number: %s\n", progname, p);
1013 if (n < 0 || 0x20 <= n && n <= 0x3F || n == 0x5E || n > 0xFF) {
1014 fprintf(stderr, "%s: can't escape character 0x%x\n", n);
1017 xmit_accm[0][n >> 5] |= 1 << (n & 0x1F);
1018 while (*p == ',' || *p == ' ')
1026 * setspeed - Set the speed.
1035 spd = strtol(arg, &ptr, 0);
1036 if (ptr == arg || *ptr != 0 || spd == 0)
1044 * setdevname - Set the device name.
1050 struct stat statbuf;
1051 char *tty, *ttyname();
1052 char dev[MAXPATHLEN];
1054 if (strncmp("/dev/", cp, 5) != 0) {
1055 strcpy(dev, "/dev/");
1056 strncat(dev, cp, MAXPATHLEN - 5);
1057 dev[MAXPATHLEN-1] = 0;
1062 * Check if there is a device by this name.
1064 if (stat(cp, &statbuf) < 0) {
1065 if (errno == ENOENT)
1067 syslog(LOG_ERR, cp);
1071 (void) strncpy(devnam, cp, MAXPATHLEN);
1072 devnam[MAXPATHLEN-1] = 0;
1073 default_device = FALSE;
1080 * setipaddr - Set the IP address
1087 char *colon, *index();
1088 u_int32_t local, remote;
1089 ipcp_options *wo = &ipcp_wantoptions[0];
1092 * IP address pair separated by ":".
1094 if ((colon = index(arg, ':')) == NULL)
1098 * If colon first character, then no local addr.
1102 if ((local = inet_addr(arg)) == -1) {
1103 if ((hp = gethostbyname(arg)) == NULL) {
1104 fprintf(stderr, "unknown host: %s\n", arg);
1107 local = *(long *)hp->h_addr;
1108 if (our_name[0] == 0) {
1109 strncpy(our_name, arg, MAXNAMELEN);
1110 our_name[MAXNAMELEN-1] = 0;
1114 if (bad_ip_adrs(local)) {
1115 fprintf(stderr, "bad local IP address %s\n", ip_ntoa(local));
1119 wo->ouraddr = local;
1124 * If colon last character, then no remote addr.
1126 if (*++colon != '\0') {
1127 if ((remote = inet_addr(colon)) == -1) {
1128 if ((hp = gethostbyname(colon)) == NULL) {
1129 fprintf(stderr, "unknown host: %s\n", colon);
1132 remote = *(long *)hp->h_addr;
1133 if (remote_name[0] == 0) {
1134 strncpy(remote_name, colon, MAXNAMELEN);
1135 remote_name[MAXNAMELEN-1] = 0;
1139 if (bad_ip_adrs(remote)) {
1140 fprintf(stderr, "bad remote IP address %s\n", ip_ntoa(remote));
1144 wo->hisaddr = remote;
1152 * setnoipdflt - disable setipdefault()
1157 disable_defaultip = 1;
1163 * setipcpaccl - accept peer's idea of our address
1168 ipcp_wantoptions[0].accept_local = 1;
1174 * setipcpaccr - accept peer's idea of its address
1179 ipcp_wantoptions[0].accept_remote = 1;
1185 * setipdefault - default our local IP address based on our hostname.
1192 ipcp_options *wo = &ipcp_wantoptions[0];
1195 * If local IP address already given, don't bother.
1197 if (wo->ouraddr != 0 || disable_defaultip)
1201 * Look up our hostname (possibly with domain name appended)
1202 * and take the first IP address as our local IP address.
1203 * If there isn't an IP address for our hostname, too bad.
1205 wo->accept_local = 1; /* don't insist on this default value */
1206 if ((hp = gethostbyname(hostname)) == NULL)
1208 local = *(long *)hp->h_addr;
1209 if (local != 0 && !bad_ip_adrs(local))
1210 wo->ouraddr = local;
1215 * setnetmask - set the netmask to be used on the interface.
1223 if ((mask = inet_addr(*argv)) == -1 || (netmask & ~mask) != 0) {
1224 fprintf(stderr, "Invalid netmask %s\n", *argv);
1233 * Return user specified netmask. A value of zero means no netmask has
1305 if (our_name[0] == 0) {
1306 strncpy(our_name, argv[0], MAXNAMELEN);
1307 our_name[MAXNAMELEN-1] = 0;
1316 strncpy(user, argv[0], MAXNAMELEN);
1317 user[MAXNAMELEN-1] = 0;
1325 strncpy(remote_name, argv[0], MAXNAMELEN);
1326 remote_name[MAXNAMELEN-1] = 0;
1340 ipcp_wantoptions[0].default_route = 1;
1347 ipcp_wantoptions[0].proxy_arp = 1;
1366 * Functions to set the echo interval for modem-less monitors
1370 setlcpechointv(argv)
1373 return int_option(*argv, &lcp_echo_interval);
1377 setlcpechofails(argv)
1380 return int_option(*argv, &lcp_echo_fails);
1384 * Functions to set timeouts, max transmits, etc.
1390 return int_option(*argv, &lcp_fsm[0].timeouttime);
1393 static int setlcpterm(argv)
1396 return int_option(*argv, &lcp_fsm[0].maxtermtransmits);
1399 static int setlcpconf(argv)
1402 return int_option(*argv, &lcp_fsm[0].maxconfreqtransmits);
1405 static int setlcpfails(argv)
1408 return int_option(*argv, &lcp_fsm[0].maxnakloops);
1411 static int setipcptimeout(argv)
1414 return int_option(*argv, &ipcp_fsm[0].timeouttime);
1417 static int setipcpterm(argv)
1420 return int_option(*argv, &ipcp_fsm[0].maxtermtransmits);
1423 static int setipcpconf(argv)
1426 return int_option(*argv, &ipcp_fsm[0].maxconfreqtransmits);
1429 static int setipcpfails(argv)
1432 return int_option(*argv, &lcp_fsm[0].maxnakloops);
1435 static int setpaptimeout(argv)
1438 return int_option(*argv, &upap[0].us_timeouttime);
1441 static int setpapreqs(argv)
1444 return int_option(*argv, &upap[0].us_maxtransmits);
1447 static int setchaptimeout(argv)
1450 return int_option(*argv, &chap[0].timeouttime);
1453 static int setchapchal(argv)
1456 return int_option(*argv, &chap[0].max_transmits);
1459 static int setchapintv(argv)
1462 return int_option(*argv, &chap[0].chal_interval);
1465 static int setbsdcomp(argv)
1472 abits = rbits = strtol(str, &endp, 0);
1473 if (endp != str && *endp == ',') {
1475 abits = strtol(str, &endp, 0);
1477 if (*endp != 0 || endp == str) {
1478 fprintf(stderr, "%s: invalid argument format for bsdcomp option\n",
1482 if (rbits != 0 && (rbits < MIN_BSD_BITS || rbits > MAX_BSD_BITS)
1483 || abits != 0 && (abits < MIN_BSD_BITS || abits > MAX_BSD_BITS)) {
1484 fprintf(stderr, "%s: bsdcomp option values must be 0 or %d .. %d\n",
1485 progname, MIN_BSD_BITS, MAX_BSD_BITS);
1489 ccp_wantoptions[0].bsd_compress = 1;
1490 ccp_wantoptions[0].bsd_bits = rbits;
1492 ccp_wantoptions[0].bsd_compress = 0;
1494 ccp_allowoptions[0].bsd_compress = 1;
1495 ccp_allowoptions[0].bsd_bits = abits;
1497 ccp_allowoptions[0].bsd_compress = 0;
1501 static int setnobsdcomp()
1503 ccp_wantoptions[0].bsd_compress = 0;
1504 ccp_allowoptions[0].bsd_compress = 0;