FreeCalypso > hg > themwi-system-sw
view utils/themwi-check-own.c @ 247:c6a3fb913c53
top Makefile: mtctest changed to use libnumdb2
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 14 Aug 2023 22:39:28 -0800 |
parents | 697fe2c87fec |
children |
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); }