summaryrefslogtreecommitdiffstats
path: root/src/blob.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2013-02-06 14:01:46 +0200
committerTimo Teräs <timo.teras@iki.fi>2013-02-06 14:01:46 +0200
commit89362a08fe4da0992e8dc10374b3d898fc78a4ea (patch)
tree91fb7bc180a184d6b0e78d303d49d6cb98fc5209 /src/blob.c
parentda50a45d29de99a8ed49e24e9c2e1e6d400fc4c3 (diff)
downloadsquark-89362a08fe4da0992e8dc10374b3d898fc78a4ea.tar.bz2
squark-89362a08fe4da0992e8dc10374b3d898fc78a4ea.tar.xz
auth-snmp: allow specifying management network prefix
So we don't go and try querying untrusted LLDP capable devices in non-managed subnets.
Diffstat (limited to 'src/blob.c')
-rw-r--r--src/blob.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/blob.c b/src/blob.c
index ea02ea4..a6ccc62 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -139,23 +139,31 @@ int blob_icmp(blob_t a, blob_t b)
return strncasecmp(a.ptr, b.ptr, a.len);
}
-unsigned long blob_inet_addr(blob_t b)
+int blob_pull_inet_addr(blob_t *b, struct in_addr *saddr)
{
unsigned long ip = 0;
int i;
for (i = 0; i < 3; i++) {
- ip += blob_pull_uint(&b, 10);
+ ip += blob_pull_uint(b, 10);
ip <<= 8;
- if (!blob_pull_matching(&b, BLOB_STR(".")))
+ if (!blob_pull_matching(b, BLOB_STR(".")))
return 0;
}
- ip += blob_pull_uint(&b, 10);
- if (b.len != 0)
- return 0;
- return htonl(ip);
+ ip += blob_pull_uint(b, 10);
+ saddr->s_addr = htonl(ip);
+ return 1;
}
+unsigned long blob_inet_addr(blob_t b)
+{
+ struct in_addr saddr;
+
+ if (blob_pull_inet_addr(&b, &saddr) && b.len == 0)
+ return saddr.s_addr;
+
+ return 0;
+}
blob_t blob_pushed(blob_t buffer, blob_t left)
{