summaryrefslogtreecommitdiff
path: root/sbin/ipnat/ipnat.c
diff options
context:
space:
mode:
authorKjell Wooding <kjell@cvs.openbsd.org>1999-12-16 07:38:46 +0000
committerKjell Wooding <kjell@cvs.openbsd.org>1999-12-16 07:38:46 +0000
commit4f440c694f2d8c97f3ea6413d87298acf9dede02 (patch)
tree2de13d91a5cc205cd9adb0c66b417e8d05904689 /sbin/ipnat/ipnat.c
parente5dff6f25f2c2c0db9a353f6ae9c9b19adc5b953 (diff)
Add the ability to use interface names in place of addresses
in firewall rules. i.e. block return-rst in quick on fxp0 proto tcp from any to fxp0 port = 9999 This will make things like DHCP much easier to deal with in the future.
Diffstat (limited to 'sbin/ipnat/ipnat.c')
-rw-r--r--sbin/ipnat/ipnat.c76
1 files changed, 3 insertions, 73 deletions
diff --git a/sbin/ipnat/ipnat.c b/sbin/ipnat/ipnat.c
index 3ca847b5063..ab3cd70dfdd 100644
--- a/sbin/ipnat/ipnat.c
+++ b/sbin/ipnat/ipnat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ipnat.c,v 1.32 1999/12/15 05:20:24 kjell Exp $ */
+/* $OpenBSD: ipnat.c,v 1.33 1999/12/16 07:38:45 kjell Exp $ */
/*
* Copyright (C) 1993-1998 by Darren Reed.
*
@@ -47,9 +47,6 @@
#include <netinet/ip_proxy.h>
#include <netinet/ip_nat.h>
#include "kmem.h"
-#if defined(__OpenBSD__)
-#include <err.h>
-#endif
#if defined(sun) && !SOLARIS2
# define STRERROR(x) sys_errlist[x]
@@ -60,7 +57,7 @@ extern char *sys_errlist[];
#if !defined(lint)
static const char sccsid[] ="@(#)ipnat.c 1.9 6/5/96 (C) 1993 Darren Reed";
-static const char rcsid[] = "@(#)$Id: ipnat.c,v 1.32 1999/12/15 05:20:24 kjell Exp $";
+static const char rcsid[] = "@(#)$Id: ipnat.c,v 1.33 1999/12/16 07:38:45 kjell Exp $";
#endif
@@ -75,7 +72,7 @@ extern void natparsefile __P((int, char *, int));
extern void printnat __P((ipnat_t *, int, void *));
#if defined(__OpenBSD__)
-int if_addr __P((char *, struct in_addr *));
+extern int if_addr __P((char *, struct in_addr *));
#endif
u_32_t hostnum __P((char *, int *, int));
@@ -405,73 +402,6 @@ char *msk;
return mask;
}
-#if defined(__OpenBSD__)
-/*
- * if_addr():
- * given a string containing an interface name (e.g. "ppp0")
- * return the IP address it represents
- *
- * The OpenBSD community considers this feature to be quite useful and
- * suggests inclusion into other platforms. The closest alternative is
- * to define /etc/networks with suitable values.
- */
-int if_addr(name, ap)
-char *name;
-struct in_addr *ap;
-{
- struct ifconf ifc;
- struct ifreq ifreq, *ifr;
- char *inbuf = NULL;
- int s, i, len = 8192;
-
- if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
- warn("socket");
- return 0;
- }
-
- while (1) {
- ifc.ifc_len = len;
- ifc.ifc_buf = inbuf = realloc(inbuf, len);
- if (inbuf == NULL)
- err(1, "malloc");
- if (ioctl(s, SIOCGIFCONF, &ifc) < 0) {
- warn("SIOCGIFCONF");
- goto if_addr_lose;
- }
- if (ifc.ifc_len + sizeof(ifreq) < len)
- break;
- len *= 2;
- }
- ifr = ifc.ifc_req;
- ifreq.ifr_name[0] = '\0';
- for (i = 0; i < ifc.ifc_len; ) {
- ifr = (struct ifreq *)((caddr_t)ifc.ifc_req + i);
- i += sizeof(ifr->ifr_name) +
- (ifr->ifr_addr.sa_len > sizeof(struct sockaddr)
- ? ifr->ifr_addr.sa_len
- : sizeof(struct sockaddr));
- ifreq = *ifr;
- if (ioctl(s, SIOCGIFADDR, (caddr_t)ifr) < 0)
- continue;
- if (ifr->ifr_addr.sa_family != AF_INET)
- continue;
- if (!strcmp(name, ifr->ifr_name)) {
- struct sockaddr_in *sin;
- close(s);
- free(inbuf);
- sin = (struct sockaddr_in *)&ifr->ifr_addr;
- *ap = sin->sin_addr;
- return (1);
- }
- }
-
-if_addr_lose:
- close(s);
- free(inbuf);
- return 0;
-}
-#endif
-
/*
* returns an ip address as a long var as a result of either a DNS lookup or
* straight inet_addr() call