summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ppp/defs.c
diff options
context:
space:
mode:
authorbrian <brian@FreeBSD.org>1999-02-25 20:05:55 +0000
committerbrian <brian@FreeBSD.org>1999-02-25 20:05:55 +0000
commit909314a3a7d15c37f170149208b7e71611ae2a35 (patch)
treeafdc682e8f39824684da2407e9680b1c33720bb8 /usr.sbin/ppp/defs.c
parenta3fa9785d059a69334c6d4842a24d0e8300c8300 (diff)
downloadFreeBSD-src-909314a3a7d15c37f170149208b7e71611ae2a35.zip
FreeBSD-src-909314a3a7d15c37f170149208b7e71611ae2a35.tar.gz
Parse IP addresses more securely - specifically, don't allow
a bum name to return as 0.0.0.0... we don't want ``delete xxx'' to delete the default route when xxx doesn't resolve. Support IP number specifications as the host when specifying a tcp-style device (rather than *just* hostnames).
Diffstat (limited to 'usr.sbin/ppp/defs.c')
-rw-r--r--usr.sbin/ppp/defs.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/usr.sbin/ppp/defs.c b/usr.sbin/ppp/defs.c
index 32b72b3..0e1ec62 100644
--- a/usr.sbin/ppp/defs.c
+++ b/usr.sbin/ppp/defs.c
@@ -23,10 +23,17 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: defs.c,v 1.16 1998/06/15 19:06:41 brian Exp $
+ * $Id: defs.c,v 1.17 1998/06/27 14:18:05 brian Exp $
*/
+#include <sys/types.h>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <sys/socket.h>
+
+#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <sys/errno.h>
@@ -114,3 +121,33 @@ Nam2mode(const char *name)
return got == -1 ? 0 : modes[got].mode;
}
+
+struct in_addr
+GetIpAddr(const char *cp)
+{
+ struct in_addr ipaddr;
+
+ if (!strcasecmp(cp, "default"))
+ ipaddr.s_addr = INADDR_ANY;
+ else if (inet_aton(cp, &ipaddr) == 0) {
+ const char *ptr;
+
+ /* Any illegal characters ? */
+ for (ptr = cp; *ptr != '\0'; ptr++)
+ if (!isalnum(*ptr) && strchr("-.", *ptr) == NULL)
+ break;
+
+ if (*ptr == '\0') {
+ struct hostent *hp;
+
+ hp = gethostbyname(cp);
+ if (hp && hp->h_addrtype == AF_INET)
+ memcpy(&ipaddr, hp->h_addr, hp->h_length);
+ else
+ ipaddr.s_addr = INADDR_NONE;
+ } else
+ ipaddr.s_addr = INADDR_NONE;
+ }
+
+ return ipaddr;
+}
OpenPOWER on IntegriCloud