changeset 2:b1c364729a93

libutil: add NANP number validation function
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 25 Jun 2022 18:58:00 -0800
parents dbc0a8677b69
children d712d518059e
files libutil/Makefile libutil/nanp_valid.c
diffstat 2 files changed, 23 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libutil/Makefile	Sat Jun 25 18:33:29 2022 -0800
+++ b/libutil/Makefile	Sat Jun 25 18:58:00 2022 -0800
@@ -1,6 +1,6 @@
 CC=	gcc
 CFLAGS=	-O2
-OBJS=	mncc_utils.o sockinit.o
+OBJS=	mncc_utils.o nanp_valid.o sockinit.o
 LIB=	libutil.a
 
 all:	${LIB}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libutil/nanp_valid.c	Sat Jun 25 18:58:00 2022 -0800
@@ -0,0 +1,22 @@
+/*
+ * Utility functions for NANP number validation.
+ */
+
+is_nanp_valid_prefix(s)
+	char *s;
+{
+	/* validate NPA part */
+	if (s[0] < '2')
+		return(0);
+	if (s[1] == '1' && s[2] == '1')
+		return(0);
+	if (s[1] == '9')
+		return(0);
+	/* validate exchange part */
+	if (s[3] < '2')
+		return(0);
+	if (s[4] == '1' && s[5] == '1')
+		return(0);
+	/* all checks passed */
+	return(1);
+}