7 #include <arpa/inet.h> /* ntohl */
12 int main(int argc, char **argv)
17 struct regdb_file_header *header;
18 struct regdb_file_reg_country *countries;
19 int dblen, siglen, num_countries, i, r = 0;
20 struct ieee80211_regdomain *rd = NULL;
23 fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
27 fd = open(argv[1], O_RDONLY);
29 perror("failed to open db file");
33 if (fstat(fd, &stat)) {
34 perror("failed to fstat db file");
40 db = mmap(NULL, dblen, PROT_READ, MAP_PRIVATE, fd, 0);
41 if (db == MAP_FAILED) {
42 perror("failed to mmap db file");
46 header = crda_get_file_ptr(db, dblen, sizeof(*header), 0);
48 if (ntohl(header->magic) != REGDB_MAGIC) {
49 fprintf(stderr, "Invalid database magic\n");
53 if (ntohl(header->version) != REGDB_VERSION) {
54 fprintf(stderr, "Invalid database version\n");
58 siglen = ntohl(header->signature_length);
59 /* adjust dblen so later sanity checks don't run into the signature */
62 if (dblen <= (int)sizeof(*header)) {
63 fprintf(stderr, "Invalid signature length %d\n", siglen);
67 /* verify signature */
68 if (!crda_verify_db_signature(db, dblen, siglen))
71 num_countries = ntohl(header->reg_country_num);
72 countries = crda_get_file_ptr(db, dblen,
73 sizeof(struct regdb_file_reg_country) * num_countries,
74 header->reg_country_ptr);
76 for (i = 0; i < num_countries; i++) {
77 struct regdb_file_reg_country *country = countries + i;
79 rd = country2rd(db, dblen, country);
82 fprintf(stderr, "Could not covert country "
83 "(%.2s) to rd\n", country->alpha2);