Debian Codegraph @

ax25/axctl.c

raw
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <ctype.h>
5 #include <unistd.h>
6 #include <pwd.h>
7
8 #include <config.h>
9 #include <scm-version.h>
10
11 #include <sys/types.h>
12 #include <sys/ioctl.h>
13
14 #include <sys/socket.h>
15
16 #include <netax25/ax25.h>
17 #include <netrose/rose.h>
18
19 #include <netax25/axlib.h>
20 #include <netax25/axconfig.h>
21
22 int main(int argc, char **argv)
23 {
24 struct ax25_ctl_struct ax25_ctl;
25 char *addr;
26 int s;
27
28 if (argc == 2 && strncmp(argv[1], "-v", 2) == 0) {
29 printf("axctl: %s\n", FULL_VER);
30 return 0;
31 }
32
33 if (argc < 5) {
34 fprintf(stderr, "Usage: axctl [-v] port dest src t1|t2|t3|n2|paclen|idle|window|maxq|kill [parm]\n");
35 return 1;
36 }
37
38 if (ax25_config_load_ports() == 0) {
39 fprintf(stderr, "axctl: no AX.25 port data configured\n");
40 return 1;
41 }
42
43 addr = ax25_config_get_addr(argv[1]);
44 if (addr == NULL) {
45 fprintf(stderr, "axctl: invalid port name - %s\n", argv[1]);
46 return 1;
47 }
48
49 if (ax25_aton_entry(addr, (char *)&ax25_ctl.port_addr) == -1)
50 return 1;
51 if (ax25_aton_entry(argv[2], (char *)&ax25_ctl.dest_addr) == -1)
52 return 1;
53 if (ax25_aton_entry(argv[3], (char *)&ax25_ctl.source_addr) == -1)
54 return 1;
55
56 s = socket(AF_AX25, SOCK_SEQPACKET, 0);
57 if (s < 0) {
58 perror("axctl: socket");
59 return 1;
60 }
61
62 if (strcmp(argv[4], "kill") == 0 || strcmp(argv[4], "-kill") == 0) {
63 ax25_ctl.cmd = AX25_KILL;
64 ax25_ctl.arg = 0;
65 } else {
66 if (argc < 6) {
67 fprintf(stderr,"axctl: parameter missing\n");
68 return 1;
69 }
70 ax25_ctl.arg = atoi(argv[5]);
71
72 if (strcmp(argv[4], "t1") == 0 || strcmp(argv[4], "-t1") == 0)
73 ax25_ctl.cmd = AX25_T1;
74 else if (strcmp(argv[4], "t2") == 0 || strcmp(argv[4], "-t2") == 0)
75 ax25_ctl.cmd = AX25_T2;
76 else if (strcmp(argv[4], "t3") == 0 || strcmp(argv[4], "-t3") == 0)
77 ax25_ctl.cmd = AX25_T3;
78 else if (strcmp(argv[4], "idle") == 0 || strcmp(argv[4], "-idle") == 0)
79 ax25_ctl.cmd = AX25_IDLE;
80 else if (strcmp(argv[4], "n2") == 0 || strcmp(argv[4], "-n2") == 0)
81 ax25_ctl.cmd = AX25_N2;
82 else if (strcmp(argv[4], "window") == 0 || strcmp(argv[4], "-window") == 0)
83 ax25_ctl.cmd = AX25_WINDOW;
84 else if (strcmp(argv[4], "paclen") == 0 || strcmp(argv[4], "-paclen") == 0)
85 ax25_ctl.cmd = AX25_PACLEN;
86 }
87
88 ax25_ctl.digi_count = 0;
89
90 if (ioctl(s, SIOCAX25CTLCON, &ax25_ctl) != 0) {
91 perror("axctl: SIOCAX25CTLCON");
92 return 1;
93 }
94
95 return 0;
96 }