File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / miniupnpd / minissdpd / showminissdpdnotif.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Sep 27 11:25:11 2023 UTC (14 months, 4 weeks ago) by misho
Branches: miniupnpd, MAIN
CVS tags: v2_3_3p0, HEAD
Version 2.3.3p0

    1: /* $Id: showminissdpdnotif.c,v 1.1.1.1 2023/09/27 11:25:11 misho Exp $ */
    2: /* vim: shiftwidth=4 tabstop=4 noexpandtab
    3:  * MiniUPnP project
    4:  * (c) 2016 Thomas Bernard
    5:  * website : http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
    6:  * This software is subject to the conditions detailed
    7:  * in the LICENCE file provided within the distribution */
    8: 
    9: #include <stdio.h>
   10: #include <string.h>
   11: #include <unistd.h>
   12: #include <errno.h>
   13: #include <signal.h>
   14: #include <sys/types.h>
   15: #include <sys/socket.h>
   16: #include <sys/un.h>
   17: 
   18: #include "codelength.h"
   19: #include "printresponse.h"
   20: 
   21: static volatile sig_atomic_t quitting = 0;
   22: 
   23: static void sighandler(int sig)
   24: {
   25: 	(void)sig;
   26: 	quitting = 1;
   27: }
   28: 
   29: int main(int argc, char * * argv)
   30: {
   31: 	int i;
   32: 	int s;
   33: 	struct sockaddr_un addr;
   34: 	const char * sockpath = "/var/run/minissdpd.sock";
   35: 	unsigned char buffer[4096];
   36: 	ssize_t n;
   37: 	const char command5[] = { 0x05, 0x00 };
   38: 	struct sigaction sa;
   39: 
   40: 	for(i=0; i<argc-1; i++) {
   41: 		if(0==strcmp(argv[i], "-s"))
   42: 			sockpath = argv[++i];
   43: 	}
   44: 
   45: 	/* set signal handlers */
   46: 	memset(&sa, 0, sizeof(struct sigaction));
   47: 	sa.sa_handler = sighandler;
   48: 	if(sigaction(SIGINT, &sa, NULL)) {
   49: 		fprintf(stderr, "Failed to set SIGINT handler.\n");
   50: 	}
   51: 	sa.sa_handler = sighandler;
   52: 	if(sigaction(SIGTERM, &sa, NULL)) {
   53: 		fprintf(stderr, "Failed to set SIGTERM handler.\n");
   54: 	}
   55: 
   56: 	s = socket(AF_UNIX, SOCK_STREAM, 0);
   57: 	addr.sun_family = AF_UNIX;
   58: 	strncpy(addr.sun_path, sockpath, sizeof(addr.sun_path));
   59: 	if(connect(s, (struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0) {
   60: 		fprintf(stderr, "connecting to %s : ", addr.sun_path);
   61: 		perror("connect");
   62: 		return 1;
   63: 	}
   64: 	printf("connected to %s\n", addr.sun_path);
   65: 	n = write(s, command5, sizeof(command5));	/* NOTIF command */
   66: 	printf("%d bytes written\n", (int)n);
   67: 
   68: 	while(!quitting) {
   69: 		n = read(s, buffer, sizeof(buffer));
   70: 		if(n < 0) {
   71: 			if(errno == EINTR) continue;
   72: 			perror("read");
   73: 			break;
   74: 		} else if(n == 0) {
   75: 			printf("Socket closed\n");
   76: 			break;
   77: 		}
   78: 		printf("%d bytes read\n", (int)n);
   79: 		printresponse(buffer, (int)n);
   80: 	}
   81: 	printf("Quit...\n");
   82: 	close(s);
   83: 	return 0;
   84: }
   85: 

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