diff utils/sim-iccid-mkfull.c @ 17:372ecc4aa2c4

off-line utils ported over
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 14 Mar 2021 07:48:55 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/utils/sim-iccid-mkfull.c	Sun Mar 14 07:48:55 2021 +0000
@@ -0,0 +1,30 @@
+/*
+ * This program is a special utility for constructing ICCIDs
+ * following the 18+1 convention.  The argument is an 18-digit ICCID
+ * base, usually entered in shorthand, and the output is the full
+ * 19-digit ICCID.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+main(argc, argv)
+	char **argv;
+{
+	u_char digits[19];
+	char asc[20];
+	int rc;
+
+	if (argc != 2) {
+		fprintf(stderr, "usage: %s shorthand-iccid\n", argv[0]);
+		exit(1);
+	}
+	rc = parse_decimal_shorthand(argv[1], digits, 18);
+	if (rc < 0)
+		exit(1);	/* error msg already printed */
+	digits[18] = compute_iccid_luhn(digits);
+	nibbles_to_ascii(digits, 19, asc);
+	puts(asc);
+	exit(0);
+}