-
Notifications
You must be signed in to change notification settings - Fork 26
/
srv.c
78 lines (64 loc) · 1.78 KB
/
srv.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* Part of DNS zone file validator `validns`.
*
* Copyright 2011-2014 Anton Berezin <[email protected]>
* Modified BSD license.
* (See LICENSE file in the distribution.)
*
*/
#include <sys/types.h>
#include <stdio.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 *srv_parse(char *name, long ttl, int type, char *s)
{
struct rr_srv *rr = getmem(sizeof(*rr));
int i;
/* TODO validate `name` (underscores etc) http://tools.ietf.org/html/rfc2782 */
i = extract_integer(&s, "priority", NULL);
if (i < 0)
return NULL;
if (i >= 65536)
return bitch("priority range is not valid");
rr->priority = i;
i = extract_integer(&s, "weight", NULL);
if (i < 0)
return NULL;
if (i >= 65536)
return bitch("weight range is not valid");
rr->weight = i;
i = extract_integer(&s, "port", NULL);
if (i < 0)
return NULL;
if (i >= 65536)
return bitch("port range is not valid");
rr->port = i;
rr->target = extract_name(&s, "target", 0);
if (!rr->target)
return NULL;
if (*s) {
return bitch("garbage after valid SRV data");
}
return store_record(type, name, ttl, rr);
}
static char* srv_human(struct rr *rrv)
{
RRCAST(srv);
char s[1024];
snprintf(s, 1024, "%hu %hu %hu %s",
rr->priority, rr->weight, rr->port, rr->target);
return quickstrdup_temp(s);
}
static struct binary_data srv_wirerdata(struct rr *rrv)
{
RRCAST(srv);
return compose_binary_data("222d", 1,
rr->priority, rr->weight, rr->port,
name2wire_name(rr->target));
}
struct rr_methods srv_methods = { srv_parse, srv_human, srv_wirerdata, NULL, NULL };