djbdnscurve6
38
djbdnscurve6
djbdnscurve6-38
src
clientloc.c
Go to the documentation of this file.
1
#include <sys/types.h>
2
#include <unistd.h>
3
#include "open.h"
4
#include "byte.h"
5
#include "cdbread.h"
6
#include "ip.h"
7
8
int
find_client_loc
(
char
loc[2],
const
char
ip
[16])
9
{
10
int
r,
fd
;
11
char
key[32 + 3];
12
static
struct
cdb
c
;
13
14
fd
= open_read(
"data.cdb"
);
15
if
(
fd
== -1)
return
0;
16
cdb_init(&
c
,
fd
);
17
18
byte_zero(loc,2);
19
key[0] = 0;
20
key[1] =
'%'
;
21
if
(byte_equal(
ip
,12,V4mappedprefix)) {
22
key[2] =
'f'
;
23
byte_copy(key + 3,4,
ip
+ 12);
24
r = cdb_find(&
c
,key,7);
25
if
(!r) r = cdb_find(&
c
,key,6);
26
if
(!r) r = cdb_find(&
c
,key,5);
27
if
(!r) r = cdb_find(&
c
,key,4);
28
if
(!r) r = cdb_find(&
c
,key,3);
29
if
(r == -1)
return
0;
30
if
(r && (cdb_datalen(&
c
) == 2))
31
if
(cdb_read(&
c
,loc,2,cdb_datapos(&
c
)) == -1)
return
0;
32
}
else
{
33
unsigned
int
n;
34
key[2] =
's'
;
35
ip6_fmt_flat(key + 3,
ip
);
36
for
(n = 19; n > 3; --n) {
37
r = cdb_find(&
c
,key,n);
38
if
(r)
break
;
39
}
40
if
(r == -1)
return
0;
41
if
(r && (cdb_datalen(&
c
) == 2))
42
if
(cdb_read(&
c
,loc,2,cdb_datapos(&
c
)) == -1)
return
0;
43
}
44
45
cdb_free(&
c
);
46
close(
fd
);
47
return
r;
48
}
fd
int fd
Definition:
axfr-get.c:103
ip
char ip[16]
Definition:
axfrdns.c:126
find_client_loc
int find_client_loc(char loc[2], const char ip[16])
Definition:
clientloc.c:8
c
void c(const char *home, const char *subdir, const char *file, int uid, int gid, int mode)
cdb
struct cdb_make cdb
Definition:
rbldns-data.c:36
Generated on Tue Aug 3 2021 23:28:56 for djbdnscurve6 by
1.9.1