Stealth Mode script
[tomato.git] / release / src / router / miniupnpd / miniupnpdctl.c
blob5758e0b8aaf194931fac0a166c6aee7988fb4e3b
1 /* $Id: miniupnpdctl.c,v 1.10 2012/04/30 21:08:00 nanard Exp $ */
2 /* MiniUPnP project
3 * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
4 * (c) 2006-2012 Thomas Bernard
5 * This software is subject to the conditions detailed
6 * in the LICENCE file provided within the distribution */
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include <unistd.h>
11 #include <string.h>
12 #include <sys/types.h>
13 #include <sys/socket.h>
14 #include <sys/un.h>
15 #include <signal.h>
17 #include "macros.h"
19 #if 0
20 static void sighandler(int sig)
22 printf("received signal %d\n", sig);
24 #endif
26 int
27 main(int argc, char * * argv)
29 /*char test[] = "test!";*/
30 static const char command[] = "show all\n";
31 char buf[256];
32 int l;
33 int s;
34 struct sockaddr_un addr;
35 UNUSED(argc);
36 UNUSED(argv);
38 /*signal(SIGINT, sighandler);*/
39 s = socket(AF_UNIX, SOCK_STREAM, 0);
40 if(s<0)
42 perror("socket");
43 return 1;
45 addr.sun_family = AF_UNIX;
46 strncpy(addr.sun_path, "/var/run/miniupnpd.ctl",
47 sizeof(addr.sun_path));
48 if(connect(s, (struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0)
50 perror("connect");
51 close(s);
52 return 1;
55 printf("Connected.\n");
56 if(write(s, command, sizeof(command)) < 0)
58 perror("write");
59 close(s);
60 return 1;
62 for(;;)
64 l = read(s, buf, sizeof(buf));
65 if(l<0)
67 perror("read");
68 break;
70 if(l==0)
71 break;
72 /*printf("%d bytes read\n", l);*/
73 fflush(stdout);
74 if(write(fileno(stdout), buf, l) < 0) {
75 perror("error writing to stdout");
77 /*printf("\n");*/
80 close(s);
81 return 0;