The multicast interface can now be specified by name with IPv4

This commit is contained in:
Thomas Bernard 2012-01-07 11:40:50 +01:00
parent e6a2c788f4
commit 3917487cb4
4 changed files with 38 additions and 10 deletions

View File

@ -1,6 +1,12 @@
$Id: Changelog.txt,v 1.153 2011/09/12 09:52:01 nanard Exp $ $Id: Changelog.txt,v 1.157 2012/01/07 10:13:24 nanard Exp $
miniUPnP client Changelog. miniUPnP client Changelog.
2012/01/07:
The multicast interface can now be specified by name with IPv4.
2012/01/02:
Install man page
2011/11/25: 2011/11/25:
added header to Port Mappings list in upnpc.c added header to Port Mappings list in upnpc.c

View File

@ -1,4 +1,4 @@
# $Id: Makefile,v 1.81 2011/06/21 15:24:14 nanard Exp $ # $Id: Makefile,v 1.84 2012/01/07 10:13:25 nanard Exp $
# MiniUPnP Project # MiniUPnP Project
# http://miniupnp.free.fr/ # http://miniupnp.free.fr/
# (c) 2005-2011 Thomas Bernard # (c) 2005-2011 Thomas Bernard
@ -12,7 +12,7 @@ OS = $(shell uname -s)
CC ?= gcc CC ?= gcc
#AR = gar #AR = gar
#CFLAGS = -O -Wall -g -DDEBUG #CFLAGS = -O -Wall -g -DDEBUG
CFLAGS ?= -O -Wall -DNDEBUG -DMINIUPNPC_SET_SOCKET_TIMEOUT -Wstrict-prototypes CFLAGS ?= -O -Wall -DNDEBUG -DMINIUPNPC_SET_SOCKET_TIMEOUT -Wstrict-prototypes -D_BSD_SOURCE
# -DNO_GETADDRINFO # -DNO_GETADDRINFO
INSTALL = install INSTALL = install
SH = /bin/sh SH = /bin/sh
@ -94,7 +94,7 @@ endif
.PHONY: install clean depend all check everything \ .PHONY: install clean depend all check everything \
installpythonmodule installpythonmodule updateversion
# validateminixml validateminiwget # validateminixml validateminiwget
all: $(LIBRARY) $(EXECUTABLES) all: $(LIBRARY) $(EXECUTABLES)

View File

@ -1,4 +1,4 @@
/* $Id: miniupnpc.c,v 1.96 2011/09/12 09:52:01 nanard Exp $ */ /* $Id: miniupnpc.c,v 1.98 2012/01/07 10:21:25 nanard Exp $ */
/* Project : miniupnp /* Project : miniupnp
* Author : Thomas BERNARD * Author : Thomas BERNARD
* copyright (c) 2005-2011 Thomas Bernard * copyright (c) 2005-2011 Thomas Bernard
@ -16,6 +16,10 @@
#endif #endif
#endif #endif
#if !defined(__OpenBSD__)
#define HAS_IP_MREQN
#endif
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -497,10 +501,28 @@ upnpDiscover(int delay, const char * multicastif,
} else { } else {
struct in_addr mc_if; struct in_addr mc_if;
mc_if.s_addr = inet_addr(multicastif); /* ex: 192.168.x.x */ mc_if.s_addr = inet_addr(multicastif); /* ex: 192.168.x.x */
((struct sockaddr_in *)&sockudp_r)->sin_addr.s_addr = mc_if.s_addr; if(mc_if.s_addr != INADDR_NONE)
if(setsockopt(sudp, IPPROTO_IP, IP_MULTICAST_IF, (const char *)&mc_if, sizeof(mc_if)) < 0)
{ {
PRINT_SOCKET_ERROR("setsockopt"); ((struct sockaddr_in *)&sockudp_r)->sin_addr.s_addr = mc_if.s_addr;
if(setsockopt(sudp, IPPROTO_IP, IP_MULTICAST_IF, (const char *)&mc_if, sizeof(mc_if)) < 0)
{
PRINT_SOCKET_ERROR("setsockopt");
}
} else {
#ifdef HAS_IP_MREQN
/* was not an ip address, try with an interface name */
struct ip_mreqn reqn; /* only defined with -D_BSD_SOURCE or -D_GNU_SOURCE */
memset(&reqn, 0, sizeof(struct ip_mreqn));
reqn.imr_ifindex = if_nametoindex(multicastif);
if(setsockopt(sudp, IPPROTO_IP, IP_MULTICAST_IF, (const char *)&reqn, sizeof(reqn)) < 0)
{
PRINT_SOCKET_ERROR("setsockopt");
}
#else
#ifdef DEBUG
printf("Setting of multicast interface not supported with interface name.\n");
#endif
#endif
} }
} }
} }

View File

@ -1,4 +1,4 @@
/* $Id: upnpc.c,v 1.88 2011/06/17 23:31:01 nanard Exp $ */ /* $Id: upnpc.c,v 1.90 2012/01/07 10:13:26 nanard Exp $ */
/* Project : miniupnp /* Project : miniupnp
* Author : Thomas Bernard * Author : Thomas Bernard
* Copyright (c) 2005-2011 Thomas Bernard * Copyright (c) 2005-2011 Thomas Bernard
@ -531,7 +531,7 @@ int main(int argc, char ** argv)
fprintf(stderr, "Options:\n"); fprintf(stderr, "Options:\n");
fprintf(stderr, " -6 : use ip v6 instead of ip v4.\n"); fprintf(stderr, " -6 : use ip v6 instead of ip v4.\n");
fprintf(stderr, " -u url : bypass discovery process by providing the XML root description url.\n"); fprintf(stderr, " -u url : bypass discovery process by providing the XML root description url.\n");
fprintf(stderr, " -m address/interface : provide ip address (ip v4) or interface name (ip v6) to use for sending SSDP multicast packets.\n"); fprintf(stderr, " -m address/interface : provide ip address (ip v4) or interface name (ip v4 or v6) to use for sending SSDP multicast packets.\n");
fprintf(stderr, " -p path : use this path for MiniSSDPd socket.\n"); fprintf(stderr, " -p path : use this path for MiniSSDPd socket.\n");
return 1; return 1;
} }