Annotation of embedaddon/miniupnpd/miniupnpdctl.c, revision 1.1
1.1 ! misho 1: /* $Id: miniupnpdctl.c,v 1.8 2010/02/15 10:19:46 nanard Exp $ */
! 2: /* MiniUPnP project
! 3: * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
! 4: * (c) 2006 Thomas Bernard
! 5: * This software is subject to the conditions detailed
! 6: * in the LICENCE file provided within the distribution */
! 7:
! 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>
! 16:
! 17: #if 0
! 18: static void sighandler(int sig)
! 19: {
! 20: printf("received signal %d\n", sig);
! 21: }
! 22: #endif
! 23:
! 24: int
! 25: main(int argc, char * * argv)
! 26: {
! 27: /*char test[] = "test!";*/
! 28: static const char command[] = "show all\n";
! 29: char buf[256];
! 30: int l;
! 31: int s;
! 32: struct sockaddr_un addr;
! 33:
! 34: // signal(SIGINT, sighandler);
! 35: s = socket(AF_UNIX, SOCK_STREAM, 0);
! 36: if(s<0)
! 37: {
! 38: perror("socket");
! 39: return 1;
! 40: }
! 41: addr.sun_family = AF_UNIX;
! 42: strncpy(addr.sun_path, "/var/run/miniupnpd.ctl",
! 43: sizeof(addr.sun_path));
! 44: if(connect(s, (struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0)
! 45: {
! 46: perror("connect");
! 47: close(s);
! 48: return 1;
! 49: }
! 50:
! 51: printf("Connected.\n");
! 52: if(write(s, command, sizeof(command)) < 0)
! 53: {
! 54: perror("write");
! 55: close(s);
! 56: return 1;
! 57: }
! 58: for(;;)
! 59: {
! 60: l = read(s, buf, sizeof(buf));
! 61: if(l<0)
! 62: {
! 63: perror("read");
! 64: break;
! 65: }
! 66: if(l==0)
! 67: break;
! 68: /*printf("%d bytes read\n", l);*/
! 69: fflush(stdout);
! 70: if(write(fileno(stdout), buf, l) < 0) {
! 71: perror("error writing to stdout");
! 72: }
! 73: /*printf("\n");*/
! 74: }
! 75:
! 76: close(s);
! 77: return 0;
! 78: }
! 79:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>