summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuis R. Rodriguez <mcgrof@frijolero.org>2012-01-18 13:59:46 -0800
committerLuis R. Rodriguez <mcgrof@frijolero.org>2012-01-18 15:39:22 -0800
commit7a09f4dd2ace905831cb60cf4c8f5a9ca855123f (patch)
tree534eac9e08064a792f218ad2fff8bfc47ea1c6f6
parentebcbfcf45a3a80f075c777473fcc0be0b38cee38 (diff)
downloadcrda-7a09f4dd2ace905831cb60cf4c8f5a9ca855123f.tar.gz
crda-7a09f4dd2ace905831cb60cf4c8f5a9ca855123f.tar.bz2
crda-7a09f4dd2ace905831cb60cf4c8f5a9ca855123f.zip
crda: make intersect.c use reglib_for_each_country()
Signed-off-by: Luis R. Rodriguez <mcgrof@frijolero.org>
-rw-r--r--intersect.c93
1 files changed, 12 insertions, 81 deletions
diff --git a/intersect.c b/intersect.c
index 2e5dacf..6d3d393 100644
--- a/intersect.c
+++ b/intersect.c
@@ -182,101 +182,26 @@ static struct ieee80211_regdomain *regdom_intersect(
int main(int argc, char **argv)
{
- int fd;
- struct stat stat;
- uint8_t *db;
- struct regdb_file_header *header;
- struct regdb_file_reg_country *countries;
- int dblen, siglen, num_countries, i, r = 0;
+ int r = 0;
struct ieee80211_regdomain *prev_world = NULL, *rd = NULL, *world = NULL;
int intersected = 0;
+ unsigned int idx = 0;
if (argc != 2) {
- fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
- return 2;
- }
-
- fd = open(argv[1], O_RDONLY);
- if (fd < 0) {
- perror("failed to open db file");
- return 2;
- }
-
- if (fstat(fd, &stat)) {
- perror("failed to fstat db file");
- return 2;
- }
-
- dblen = stat.st_size;
-
- db = mmap(NULL, dblen, PROT_READ, MAP_PRIVATE, fd, 0);
- if (db == MAP_FAILED) {
- perror("failed to mmap db file");
- return 2;
- }
-
- header = crda_get_file_ptr(db, dblen, sizeof(*header), 0);
-
- if (ntohl(header->magic) != REGDB_MAGIC) {
- fprintf(stderr, "Invalid database magic\n");
- return 2;
- }
-
- if (ntohl(header->version) != REGDB_VERSION) {
- fprintf(stderr, "Invalid database version\n");
- return 2;
- }
-
- siglen = ntohl(header->signature_length);
- /* adjust dblen so later sanity checks don't run into the signature */
- dblen -= siglen;
-
- if (dblen <= (int)sizeof(*header)) {
- fprintf(stderr, "Invalid signature length %d\n", siglen);
- return 2;
- }
-
- /* verify signature */
- if (!crda_verify_db_signature(db, dblen, siglen))
+ fprintf(stderr, "You must specify a file\n");
return -EINVAL;
-
- num_countries = ntohl(header->reg_country_num);
-
- if (num_countries <= 0)
- return 0;
-
- countries = crda_get_file_ptr(db, dblen,
- sizeof(struct regdb_file_reg_country) * num_countries,
- header->reg_country_ptr);
+ }
/* We intersect only when we have to rd structures ready */
- for (i = 0; i < num_countries; i++) {
- struct regdb_file_reg_country *country = countries + i;
-
- if (is_world_regdom((const char *) country->alpha2))
+ reglib_for_each_country(rd, idx, argv[1]) {
+ if (is_world_regdom((const char *) rd->alpha2))
continue;
- /* Gets the rd for the current country */
- rd = country2rd(db, dblen, country);
- if (!rd) {
- r = -ENOMEM;
- fprintf(stderr, "Could not covert country "
- "(%.2s) to rd\n", country->alpha2);
- goto out;
- }
-
- if (num_countries == 1) {
- world = rd;
- rd = NULL;
- break;
- }
-
if (!prev_world) {
prev_world = rd;
continue;
}
-
if (world) {
free(prev_world);
prev_world = world;
@@ -318,6 +243,12 @@ int main(int argc, char **argv)
intersected++;
}
+ if (idx == 1) {
+ world = rd;
+ rd = NULL;
+ }
+
+
if (intersected > 1)
printf("%d regulatory domains intersected\n", intersected);
else