FreeCalypso > hg > themwi-nanp
comparison utils/themwi-check-own.c @ 6:1e548c7a24a1
themwi-check-own: old source as starting point
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 13 Dec 2023 03:14:35 +0000 |
parents | |
children | dc1554b7dfb8 |
comparison
equal
deleted
inserted
replaced
5:2729f94f38fb | 6:1e548c7a24a1 |
---|---|
1 /* | |
2 * This utility performs a lookup in ThemWi number database to see | |
3 * if a given NANP number is owned by us. | |
4 */ | |
5 | |
6 #include <stdio.h> | |
7 #include <stdint.h> | |
8 #include <stdlib.h> | |
9 #include <syslog.h> | |
10 #include "../include/number_db_v2.h" | |
11 #include "../libnumdb2/lookup_func.h" | |
12 | |
13 main(argc, argv) | |
14 char **argv; | |
15 { | |
16 char nanp[11]; | |
17 struct owned_number_rec *rec; | |
18 | |
19 if (argc != 2) { | |
20 usage: fprintf(stderr, "usage: %s 10-digit-number\n", argv[0]); | |
21 exit(1); | |
22 } | |
23 if (grok_number_string(argv[1], 1) != 10) | |
24 goto usage; | |
25 dehyphen_number_string(argv[1], nanp); | |
26 if (!is_nanp_valid_prefix(nanp)) { | |
27 fprintf(stderr, "error: number violates NANP rules\n"); | |
28 exit(1); | |
29 } | |
30 openlog("themwi-check-own", 0, LOG_LOCAL5); | |
31 if (read_number_db() < 0) { | |
32 fprintf(stderr, "error reading number database\n"); | |
33 exit(1); | |
34 } | |
35 rec = numdb_lookup_nanp(nanp); | |
36 printf("+1-%.3s-%.3s-%s is ", nanp, nanp+3, nanp+6); | |
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 } | |
56 exit(0); | |
57 } |