annotate utils/smpp-test1.c @ 223:f11c3e40c87a

new program smpp-send
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 05 Aug 2023 12:24:31 -0800
parents c798a1762c7c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
218
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This program connects to an SMPP server in the role of a client,
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * sends a bind_transceiver request, and then dumps everything
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * that comes back.
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 */
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/types.h>
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <sys/socket.h>
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <netinet/in.h>
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <arpa/inet.h>
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdio.h>
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <stdlib.h>
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <string.h>
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <strings.h>
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include <unistd.h>
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 static int tcpsock;
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 static struct sockaddr_in server_sin;
220
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
19 static u_char bind_req[64];
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
20 static unsigned bind_req_len;
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
21 static char system_id[16], password[9];
218
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 static u_char rx_hdr[16];
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 static unsigned rx_pkt_len;
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 static void
220
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
26 construct_bind_req()
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
27 {
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
28 u_char *dp;
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
29 unsigned slen;
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
30
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
31 dp = bind_req + 4; /* length will be filled last */
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
32 /* command_id */
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
33 *dp++ = 0;
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
34 *dp++ = 0;
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
35 *dp++ = 0;
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
36 *dp++ = 0x09; /* bind_transceiver */
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
37 /* empty command_status */
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
38 *dp++ = 0;
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
39 *dp++ = 0;
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
40 *dp++ = 0;
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
41 *dp++ = 0;
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
42 /* sequence_number */
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
43 *dp++ = 0;
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
44 *dp++ = 0;
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
45 *dp++ = 0;
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
46 *dp++ = 1;
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
47 /* system_id */
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
48 slen = strlen(system_id) + 1;
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
49 bcopy(system_id, dp, slen);
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
50 dp += slen;
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
51 /* password */
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
52 slen = strlen(password) + 1;
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
53 bcopy(password, dp, slen);
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
54 dp += slen;
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
55 /* system_type */
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
56 strcpy(dp, "SMPP");
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
57 dp += 5;
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
58 /* interface_version */
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
59 *dp++ = 0x34;
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
60 /* addr_ton */
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
61 *dp++ = 0;
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
62 /* addr_npi */
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
63 *dp++ = 0;
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
64 /* address_range */
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
65 *dp++ = 0;
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
66 bind_req_len = dp - bind_req;
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
67 bind_req[0] = bind_req_len >> 24;
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
68 bind_req[1] = bind_req_len >> 16;
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
69 bind_req[2] = bind_req_len >> 8;
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
70 bind_req[3] = bind_req_len;
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
71 }
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
72
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
73 static void
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
74 print_bind_req()
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
75 {
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
76 unsigned off, chunk;
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
77 int i, c;
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
78
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
79 printf("Constructed bind request of %u bytes\n", bind_req_len);
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
80 for (off = 0; off < bind_req_len; off += chunk) {
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
81 chunk = bind_req_len - off;
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
82 if (chunk > 16)
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
83 chunk = 16;
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
84 printf("%02X: ", off);
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
85 for (i = 0; i < 16; i++) {
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
86 if (i < chunk)
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
87 printf("%02X ", bind_req[off + i]);
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
88 else
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
89 fputs(" ", stdout);
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
90 if (i == 7 || i == 15)
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
91 putchar(' ');
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
92 }
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
93 for (i = 0; i < chunk; i++) {
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
94 c = bind_req[off + i];
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
95 if (c < ' ' || c > '~')
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
96 c = '.';
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
97 putchar(c);
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
98 }
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
99 putchar('\n');
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
100 }
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
101 }
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
102
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
103 static void
218
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 init_stage()
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 {
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 int rc;
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 rc = connect(tcpsock, (struct sockaddr *) &server_sin,
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 sizeof(struct sockaddr_in));
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 if (rc < 0) {
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 perror("connect");
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 exit(1);
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 }
220
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
114 rc = write(tcpsock, bind_req, bind_req_len);
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
115 if (rc != bind_req_len) {
218
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 perror("write");
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 exit(1);
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 }
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 }
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 static void
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 rx_bytes(buf, need_len)
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 u_char *buf;
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 unsigned need_len;
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 {
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 int cc;
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 unsigned remain;
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 for (remain = need_len; remain; remain -= cc) {
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 cc = read(tcpsock, buf, remain);
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 if (cc <= 0) {
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 perror("read");
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 exit(1);
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 }
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 }
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 }
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 static void
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 print_hdr()
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 {
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 int i, j, pos;
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 fputs("Got header:", stdout);
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 pos = 0;
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 for (i = 0; i < 4; i++) {
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 putchar(' ');
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 for (j = 0; j < 4; j++)
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 printf("%02X", rx_hdr[pos++]);
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 }
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 putchar('\n');
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 }
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 static void
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 preen_rx_len()
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 {
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 rx_pkt_len = (rx_hdr[0] << 24) | (rx_hdr[1] << 16) | (rx_hdr[2] << 8) |
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 rx_hdr[3];
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 printf("Rx packet length: %u bytes\n", rx_pkt_len);
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 if (rx_pkt_len < 16) {
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 printf("Error: packet length is too short\n");
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 exit(1);
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 }
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 }
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 static void
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 read_and_dump_body()
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 {
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 u_char buf[16];
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 unsigned offset, chunk;
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 int i, c;
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 for (offset = 16; offset < rx_pkt_len; offset += chunk) {
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 chunk = rx_pkt_len - offset;
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 if (chunk > 16)
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 chunk = 16;
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 rx_bytes(buf, chunk);
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 printf("%08X: ", offset);
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 for (i = 0; i < 16; i++) {
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 if (i < chunk)
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 printf("%02X ", buf[i]);
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 else
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 fputs(" ", stdout);
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 if (i == 7 || i == 15)
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 putchar(' ');
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 }
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 for (i = 0; i < chunk; i++) {
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 c = buf[i];
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 if (c < ' ' || c > '~')
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 c = '.';
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 putchar(c);
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 }
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 putchar('\n');
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 }
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 }
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 main(argc, argv)
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 char **argv;
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 {
220
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
199 if (argc < 3 || argc > 4) {
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
200 fprintf(stderr, "usage: %s server-ip system-id [password]\n",
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
201 argv[0]);
218
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 exit(1);
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 }
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 server_sin.sin_family = AF_INET;
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 server_sin.sin_addr.s_addr = inet_addr(argv[1]);
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 if (server_sin.sin_addr.s_addr == INADDR_NONE) {
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 fprintf(stderr, "error: invalid IP address argument \"%s\"\n",
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 argv[1]);
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 exit(1);
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 }
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 server_sin.sin_port = htons(2775);
220
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
212 if (strlen(argv[2]) > 15) {
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
213 fprintf(stderr, "error: system-id string is too long\n");
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
214 exit(1);
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
215 }
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
216 strcpy(system_id, argv[2]);
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
217 if (argv[3]) {
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
218 if (strlen(argv[3]) > 8) {
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
219 fprintf(stderr, "error: password string is too long\n");
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
220 exit(1);
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
221 }
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
222 strcpy(password, argv[3]);
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
223 }
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
224 construct_bind_req();
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
225 setlinebuf(stdout);
c798a1762c7c smpp-test1: take strings on the command line, construct bind req
Mychaela Falconia <falcon@freecalypso.org>
parents: 219
diff changeset
226 print_bind_req();
218
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 tcpsock = socket(AF_INET, SOCK_STREAM, 0);
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 if (tcpsock < 0) {
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 perror("socket");
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 exit(1);
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231 }
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232 init_stage();
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 for (;;) {
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 rx_bytes(rx_hdr, 16);
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235 print_hdr();
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236 preen_rx_len();
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237 read_and_dump_body();
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 }
211a043a385f smpp-test1 program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239 }