summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2013-01-02 16:12:02 +0100
committerFelix Fietkau <nbd@openwrt.org>2013-01-02 16:12:02 +0100
commit6dfd8f67760b977ec7e345aece872c2a40a3be1e (patch)
tree7c8610278da9f7aabe0dc209b1adf1ba3318677e
parent7aec47491eb4b77361d8618cb3860607e2ec80e1 (diff)
add uh_addr_rfc1918()
-rw-r--r--uhttpd.h9
-rw-r--r--utils.c15
-rw-r--r--utils.h10
3 files changed, 25 insertions, 9 deletions
diff --git a/uhttpd.h b/uhttpd.h
index cb56fcd..f47c743 100644
--- a/uhttpd.h
+++ b/uhttpd.h
@@ -136,15 +136,6 @@ struct dispatch_handler {
void (*handle_request)(struct client *cl, const char *url, struct path_info *pi);
};
-struct uh_addr {
- uint8_t family;
- uint16_t port;
- union {
- struct in_addr in;
- struct in6_addr in6;
- };
-};
-
struct client {
struct list_head list;
int id;
diff --git a/utils.c b/utils.c
index d2ad296..742e280 100644
--- a/utils.c
+++ b/utils.c
@@ -217,3 +217,18 @@ char *uh_split_header(char *str)
return val;
}
+
+bool uh_addr_rfc1918(struct uh_addr *addr)
+{
+ uint32_t a;
+
+ if (addr->family != AF_INET)
+ return false;
+
+ a = htonl(addr->in.s_addr);
+ return ((a >= 0x0A000000) && (a <= 0x0AFFFFFF)) ||
+ ((a >= 0xAC100000) && (a <= 0xAC1FFFFF)) ||
+ ((a >= 0xC0A80000) && (a <= 0xC0A8FFFF));
+
+ return 0;
+}
diff --git a/utils.h b/utils.h
index 8f67823..a53c256 100644
--- a/utils.h
+++ b/utils.h
@@ -29,6 +29,15 @@
#include <stdlib.h>
#include <unistd.h>
+struct uh_addr {
+ uint8_t family;
+ uint16_t port;
+ union {
+ struct in_addr in;
+ struct in6_addr in6;
+ };
+};
+
#define min(x, y) (((x) < (y)) ? (x) : (y))
#define max(x, y) (((x) > (y)) ? (x) : (y))
@@ -57,5 +66,6 @@ int uh_urlencode(char *buf, int blen, const char *src, int slen);
int uh_b64decode(char *buf, int blen, const void *src, int slen);
bool uh_path_match(const char *prefix, const char *url);
char *uh_split_header(char *str);
+bool uh_addr_rfc1918(struct uh_addr *addr);
#endif