FreeCalypso > hg > osmo-playpen
comparison smsc-sendmt/read_pdu.c @ 12:7543aa173634
proto-smsc-sendmt program written, compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 27 Aug 2023 16:36:28 -0800 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
11:44148d13283c | 12:7543aa173634 |
---|---|
1 /* | |
2 * This module implements the reading of hex-encoded SMS-DELIVER TPDU | |
3 * from stdin. | |
4 */ | |
5 | |
6 #include <stdio.h> | |
7 #include <stdint.h> | |
8 #include <stdlib.h> | |
9 #include <string.h> | |
10 | |
11 extern int decode_hex_line(const char *inbuf, uint8_t *outbuf, unsigned outmax); | |
12 | |
13 uint8_t tpdu_buf[176]; | |
14 unsigned tpdu_len; | |
15 | |
16 void read_pdu_from_stdin(void) | |
17 { | |
18 char linebuf[512], *nl; | |
19 int rc; | |
20 | |
21 if (!fgets(linebuf, sizeof(linebuf), stdin)) { | |
22 fprintf(stderr, "error: empty stdin is not acceptable\n"); | |
23 exit(1); | |
24 } | |
25 nl = strchr(linebuf, '\n'); | |
26 if (!nl) { | |
27 fprintf(stderr, | |
28 "error: stdin line is too long or unterminated\n"); | |
29 exit(1); | |
30 } | |
31 *nl = '\0'; | |
32 rc = decode_hex_line(linebuf, tpdu_buf, sizeof(tpdu_buf)); | |
33 if (rc <= 0) { | |
34 fprintf(stderr, "error: stdin line is not a valid hex PDU\n"); | |
35 exit(1); | |
36 } | |
37 tpdu_len = rc; | |
38 } |