File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / miniupnpd / miniupnpdctl.c
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Mon Jul 22 00:32:35 2013 UTC (11 years, 5 months ago) by misho
Branches: miniupnpd, elwix, MAIN
CVS tags: v1_8p0, v1_8, HEAD
1.8

    1: /* $Id: miniupnpdctl.c,v 1.1.1.2 2013/07/22 00:32:35 misho 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 */
    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: #include "macros.h"
   18: 
   19: #if 0
   20: static void sighandler(int sig)
   21: {
   22: 	printf("received signal %d\n", sig);
   23: }
   24: #endif
   25: 
   26: int
   27: main(int argc, char * * argv)
   28: {
   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);
   37: 
   38: 	/*signal(SIGINT, sighandler);*/
   39: 	s = socket(AF_UNIX, SOCK_STREAM, 0);
   40: 	if(s<0)
   41: 	{
   42: 		perror("socket");
   43: 		return 1;
   44: 	}
   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)
   49: 	{
   50: 		perror("connect");
   51: 		close(s);
   52: 		return 1;
   53: 	}
   54: 
   55: 	printf("Connected.\n");
   56: 	if(write(s, command, sizeof(command)) < 0)
   57: 	{
   58: 		perror("write");
   59: 		close(s);
   60: 		return 1;
   61: 	}
   62: 	for(;;)
   63: 	{
   64: 		l = read(s, buf, sizeof(buf));
   65: 		if(l<0)
   66: 		{
   67: 			perror("read");
   68: 			break;
   69: 		}
   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");
   76: 		}
   77: 		/*printf("\n");*/
   78: 	}
   79: 
   80: 	close(s);
   81: 	return 0;
   82: }
   83: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>