aa6a300fb7cee0d67074ac515ab9cf20e0f0bb69
10 #include <sys/socket.h>
11 #include <netinet/in.h>
19 struct { char *command
; int pkt_type
; int params
; } commands
[] = {
20 { "load_plugin", PKT_LOAD_PLUGIN
, 1 },
21 { "unload_plugin", PKT_UNLOAD_PLUGIN
, 1 },
22 { "garden", PKT_GARDEN
, 1 },
23 { "ungarden", PKT_UNGARDEN
, 1 },
26 char *dest_host
= NULL
;
27 unsigned int dest_port
= 1702;
30 int main(int argc
, char *argv
[])
42 printf("Usage: %s <host> <command> [args...]\n", argv
[0]);
46 dest_host
= strdup(argv
[1]);
51 struct sockaddr_in addr
;
53 memset(&addr
, 0, sizeof(addr
));
54 addr
.sin_family
= AF_INET
;
55 addr
.sin_port
= htons(1703);
56 udpfd
= socket(AF_INET
, SOCK_DGRAM
, 17);
57 setsockopt(udpfd
, SOL_SOCKET
, SO_REUSEADDR
, &on
, sizeof(on
));
58 if (bind(udpfd
, (void *) &addr
, sizeof(addr
)) < 0)
66 struct hostent
*h
= gethostbyname(dest_host
);
67 if (h
) dest_ip
= ntohl(*(unsigned int *)h
->h_addr
);
68 if (!dest_ip
) dest_ip
= ntohl(inet_addr(dest_host
));
71 printf("Can't resolve \"%s\"\n", dest_host
);
76 if (!(packet
= calloc(1400, 1)))
84 // Deal with command & params
85 for (i
= 0; i
< (sizeof(commands
) / sizeof(commands
[0])); i
++)
87 if (strcasecmp(commands
[i
].command
, argv
[2]) == 0)
90 pkt_type
= commands
[i
].pkt_type
;
91 len
= new_packet(pkt_type
, packet
);
92 if (argc
< (commands
[i
].params
+ 3))
94 printf("Not enough parameters for %s\n", argv
[2]);
97 for (p
= 0; p
< commands
[i
].params
; p
++)
99 strncpy((packet
+ len
), argv
[p
+ 3], 1400 - len
- 1);
100 len
+= strlen(argv
[p
+ 3]) + 1;
107 printf("Unknown command\n");
111 send_packet(udpfd
, dest_ip
, dest_port
, packet
, len
);
116 struct timeval timeout
;
123 n
= select(udpfd
+ 1, &r
, 0, 0, &timeout
);
126 printf("Timeout waiting for packet\n");
130 if ((len
= read_packet(udpfd
, packet
)))
133 dump_packet(packet
, stdout
);