FreeCalypso > hg > themwi-system-sw
comparison utils/themwi-check-own.c @ 238:697fe2c87fec
themwi-check-own: convert to libnumdb2
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 14 Aug 2023 14:42:59 -0800 |
parents | 26b98505684e |
children |
comparison
equal
deleted
inserted
replaced
237:f78c097108a7 | 238:697fe2c87fec |
---|---|
2 * This utility performs a lookup in ThemWi number database to see | 2 * This utility performs a lookup in ThemWi number database to see |
3 * if a given NANP number is owned by us. | 3 * if a given NANP number is owned by us. |
4 */ | 4 */ |
5 | 5 |
6 #include <stdio.h> | 6 #include <stdio.h> |
7 #include <stdint.h> | |
7 #include <stdlib.h> | 8 #include <stdlib.h> |
8 #include <syslog.h> | 9 #include <syslog.h> |
10 #include "../include/number_db_v2.h" | |
11 #include "../libnumdb2/lookup_func.h" | |
9 | 12 |
10 main(argc, argv) | 13 main(argc, argv) |
11 char **argv; | 14 char **argv; |
12 { | 15 { |
13 char nanp[11]; | 16 char nanp[11]; |
17 struct owned_number_rec *rec; | |
14 | 18 |
15 if (argc != 2) { | 19 if (argc != 2) { |
16 usage: fprintf(stderr, "usage: %s 10-digit-number\n", argv[0]); | 20 usage: fprintf(stderr, "usage: %s 10-digit-number\n", argv[0]); |
17 exit(1); | 21 exit(1); |
18 } | 22 } |
26 openlog("themwi-check-own", 0, LOG_LOCAL5); | 30 openlog("themwi-check-own", 0, LOG_LOCAL5); |
27 if (read_number_db() < 0) { | 31 if (read_number_db() < 0) { |
28 fprintf(stderr, "error reading number database\n"); | 32 fprintf(stderr, "error reading number database\n"); |
29 exit(1); | 33 exit(1); |
30 } | 34 } |
31 printf("+1-%.3s-%.3s-%s is %s\n", nanp, nanp+3, nanp+6, | 35 rec = numdb_lookup_nanp(nanp); |
32 is_nanp_locally_owned(nanp) ? "locally owned" | 36 printf("+1-%.3s-%.3s-%s is ", nanp, nanp+3, nanp+6); |
33 : "NOT owned by us"); | 37 if (!rec) { |
38 puts("NOT owned by us"); | |
39 exit(1); | |
40 } | |
41 fputs("locally owned, ", stdout); | |
42 switch (rec->usage & NUMBER_USAGE_MASK) { | |
43 case NUMBER_USAGE_TYPE_RSVD: | |
44 puts("reserved"); | |
45 break; | |
46 case NUMBER_USAGE_TYPE_GSM_SUB: | |
47 puts("assigned to a GSM subscriber"); | |
48 break; | |
49 case NUMBER_USAGE_TYPE_ALIAS: | |
50 printf("mapped to +1-%03u-%03u-%04u\n", rec->remap[0], | |
51 rec->remap[1], rec->remap[2]); | |
52 break; | |
53 default: | |
54 printf("unknown usage byte 0x%02X\n", rec->usage); | |
55 } | |
34 exit(0); | 56 exit(0); |
35 } | 57 } |