forked from tobez/validns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eui64.c
53 lines (42 loc) · 1.08 KB
/
eui64.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* Part of DNS zone file validator `validns`.
*
* Copyright 2016 Pieter Lexis <[email protected]>
* Modified BSD license.
* (See LICENSE file in the distribution.)
*
*/
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "common.h"
#include "textparse.h"
#include "mempool.h"
#include "carp.h"
#include "rr.h"
static struct rr* eui64_parse(char *name, long ttl, int type, char *s)
{
struct rr_eui64 *rr = getmem(sizeof(*rr));
uint8_t r[8];
if (sscanf(s, "%2hhx-%2hhx-%2hhx-%2hhx-%2hhx-%2hhx-%2hhx-%2hhx",
r+0, r+1, r+2, r+3, r+4, r+5, r+6, r+7) != 8) {
return bitch("%s: in wrong format", name);
}
memmove(rr->address, r, 8);
return store_record(type, name, ttl, rr);
}
static struct binary_data eui64_wirerdata(struct rr *rrv)
{
RRCAST(eui64);
struct binary_data r;
r.length = sizeof(rr->address);
r.data = (void *)&rr->address;
return r;
}
static char* eui64_human(struct rr *rrv)
{
return "...";
}
struct rr_methods eui64_methods = { eui64_parse, eui64_human, eui64_wirerdata, NULL, NULL };