summaryrefslogtreecommitdiff
path: root/sys/netgraph/ng_parse.c
diff options
context:
space:
mode:
authorRuslan Ermilov <ru@FreeBSD.org>2003-12-17 12:40:34 +0000
committerRuslan Ermilov <ru@FreeBSD.org>2003-12-17 12:40:34 +0000
commit8c7e4101f87192b1033d85842714bfb3dd453c3e (patch)
treecb79deb87f430caf11f013eff4540c587f790642 /sys/netgraph/ng_parse.c
parent7304a833fb9f3eba196c3ca67ce19509b1dca3af (diff)
Notes
Diffstat (limited to 'sys/netgraph/ng_parse.c')
-rw-r--r--sys/netgraph/ng_parse.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/sys/netgraph/ng_parse.c b/sys/netgraph/ng_parse.c
index cff5fcbfa6c3..58389e853364 100644
--- a/sys/netgraph/ng_parse.c
+++ b/sys/netgraph/ng_parse.c
@@ -48,6 +48,8 @@
#include <sys/malloc.h>
#include <sys/ctype.h>
+#include <net/ethernet.h>
+
#include <netinet/in.h>
#include <netgraph/ng_message.h>
@@ -999,6 +1001,62 @@ const struct ng_parse_type ng_parse_ipaddr_type = {
};
/************************************************************************
+ ETHERNET ADDRESS TYPE
+ ************************************************************************/
+
+static int
+ng_enaddr_parse(const struct ng_parse_type *type,
+ const char *s, int *const off, const u_char *const start,
+ u_char *const buf, int *const buflen)
+{
+ char *eptr;
+ u_long val;
+ int i;
+
+ if (*buflen < ETHER_ADDR_LEN)
+ return (ERANGE);
+ for (i = 0; i < ETHER_ADDR_LEN; i++) {
+ val = strtoul(s + *off, &eptr, 16);
+ if (val > 0xff || eptr == s + *off)
+ return (EINVAL);
+ buf[i] = (u_char)val;
+ *off = (eptr - s);
+ if (i < ETHER_ADDR_LEN - 1) {
+ if (*eptr != ':')
+ return (EINVAL);
+ (*off)++;
+ }
+ }
+ *buflen = ETHER_ADDR_LEN;
+ return (0);
+}
+
+static int
+ng_enaddr_unparse(const struct ng_parse_type *type,
+ const u_char *data, int *off, char *cbuf, int cbuflen)
+{
+ int len;
+
+ len = snprintf(cbuf, cbuflen, "%02x:%02x:%02x:%02x:%02x:%02x",
+ data[*off], data[*off + 1], data[*off + 2],
+ data[*off + 3], data[*off + 4], data[*off + 5]);
+ if (len >= cbuflen)
+ return (ERANGE);
+ *off += ETHER_ADDR_LEN;
+ return (0);
+}
+
+const struct ng_parse_type ng_parse_enaddr_type = {
+ NULL,
+ NULL,
+ NULL,
+ ng_enaddr_parse,
+ ng_enaddr_unparse,
+ NULL,
+ 0
+};
+
+/************************************************************************
BYTE ARRAY TYPE
************************************************************************/