forked from jcyfkimi/aprs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresendaprs.c
79 lines (71 loc) · 1.4 KB
/
resendaprs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* resendaprsudp [ -d ] [ -h host ] [ -p port ] [ -i interval ]
功能:
从标准输入读入aprs,发送给host:port
默认是 127.0.0.1 14580
*/
#include <stdio.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <syslog.h>
#include <errno.h>
#include <signal.h>
#include <ctype.h>
#include "sock.h"
#define MAXLEN 16384
#define PORT 14580
int debug = 0;
char host[MAXLEN];
int port = 14580;
int sleep_t = 0;
#include "sendudp.c"
int main(int argc, char **argv)
{
int c;
char buf[MAXLEN];
int len;
while ((c = getopt(argc, argv, "dh:p:i:")) != EOF)
switch (c) {
case 'd':
debug = 1;
break;
case 'h':
strncpy(host, optarg, MAXLEN);
break;
case 'p':
port = atoi(optarg);
break;
case 'i':
sleep_t = atoi(optarg);
break;
}
if (host[0] == 0)
strcpy(host, "127.0.0.1");
while (fgets(buf, MAXLEN, stdin)) {
len = strlen(buf);
if (len < 10)
continue;
buf[len] = 0;
if ((buf[len - 1] == '\n') || (buf[len - 1] == '\r'))
len--;
if ((buf[len - 1] == '\n') || (buf[len - 1] == '\r'))
len--;
buf[len] = 0x0d;
buf[len + 1] = 0x0a;
buf[len + 2] = 0;
len += 2;
if (debug)
printf("got %s", buf);
sendudp(buf, len, host, port);
if (sleep_t > 0)
sleep(sleep_t);
}
return 0;
}