FreeCalypso > hg > themwi-nanp
view 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 |
line wrap: on
line source
/* * This utility performs a lookup in ThemWi number database to see * if a given NANP number is owned by us. */ #include <stdio.h> #include <stdint.h> #include <stdlib.h> #include <syslog.h> #include "../include/number_db_v2.h" #include "../libnumdb2/lookup_func.h" main(argc, argv) char **argv; { char nanp[11]; struct owned_number_rec *rec; if (argc != 2) { usage: fprintf(stderr, "usage: %s 10-digit-number\n", argv[0]); exit(1); } if (grok_number_string(argv[1], 1) != 10) goto usage; dehyphen_number_string(argv[1], nanp); if (!is_nanp_valid_prefix(nanp)) { fprintf(stderr, "error: number violates NANP rules\n"); exit(1); } openlog("themwi-check-own", 0, LOG_LOCAL5); if (read_number_db() < 0) { fprintf(stderr, "error reading number database\n"); exit(1); } rec = numdb_lookup_nanp(nanp); printf("+1-%.3s-%.3s-%s is ", nanp, nanp+3, nanp+6); if (!rec) { puts("NOT owned by us"); exit(1); } fputs("locally owned, ", stdout); switch (rec->usage & NUMBER_USAGE_MASK) { case NUMBER_USAGE_TYPE_RSVD: puts("reserved"); break; case NUMBER_USAGE_TYPE_GSM_SUB: puts("assigned to a GSM subscriber"); break; case NUMBER_USAGE_TYPE_ALIAS: printf("mapped to +1-%03u-%03u-%04u\n", rec->remap[0], rec->remap[1], rec->remap[2]); break; default: printf("unknown usage byte 0x%02X\n", rec->usage); } exit(0); }