]> git.ipfire.org Git - people/ms/libloc.git/blob - src/loc/format.h
downloader: Check DNS for most recent version
[people/ms/libloc.git] / src / loc / format.h
1 /*
2 libloc - A library to determine the location of someone on the Internet
3
4 Copyright (C) 2017 IPFire Development Team <info@ipfire.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15 */
16
17 #ifndef LIBLOC_FORMAT_H
18 #define LIBLOC_FORMAT_H
19
20 #include <stdint.h>
21
22 #define LOC_DATABASE_MAGIC "LOCDBXX"
23
24 #ifdef LIBLOC_PRIVATE
25
26 #define LOC_DATABASE_VERSION 0
27
28 #define STR(x) #x
29 #define LOC_DATABASE_DOMAIN_LATEST(version) "_latest._v" STR(version) ".location.ipfire.org"
30
31 #define LOC_DATABASE_PAGE_SIZE 4096
32
33 struct loc_database_magic {
34 char magic[7];
35
36 // Database version information
37 uint8_t version;
38 };
39
40 struct loc_database_header_v0 {
41 // UNIX timestamp when the database was created
42 uint64_t created_at;
43
44 // Vendor who created the database
45 uint32_t vendor;
46
47 // Description of the database
48 uint32_t description;
49
50 // License of the database
51 uint32_t license;
52
53 // Tells us where the ASes start
54 uint32_t as_offset;
55 uint32_t as_length;
56
57 // Tells us where the networks start
58 uint32_t network_data_offset;
59 uint32_t network_data_length;
60
61 // Tells us where the network nodes start
62 uint32_t network_tree_offset;
63 uint32_t network_tree_length;
64
65 // Tells us where the countries start
66 uint32_t countries_offset;
67 uint32_t countries_length;
68
69 // Tells us where the pool starts
70 uint32_t pool_offset;
71 uint32_t pool_length;
72
73 // Add some padding for future extensions
74 char padding[32];
75 };
76
77 struct loc_database_network_node_v0 {
78 uint32_t zero;
79 uint32_t one;
80
81 uint32_t network;
82 };
83
84 struct loc_database_network_v0 {
85 // The start address and prefix will be encoded in the tree
86
87 // The country this network is located in
88 char country_code[2];
89
90 // ASN
91 uint32_t asn;
92
93 // Flags
94 uint16_t flags;
95
96 // Reserved
97 char padding[2];
98 };
99
100 struct loc_database_as_v0 {
101 // The AS number
102 uint32_t number;
103
104 // Name
105 uint32_t name;
106 };
107
108 struct loc_database_country_v0 {
109 char code[2];
110 char continent_code[2];
111
112 // Name in the string pool
113 uint32_t name;
114 };
115
116 #endif
117 #endif