Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 533888
Collapse All | Expand All

(-)/etc/init.d/minissdpd.old (-30 / +36 lines)
Lines 3-32 Link Here
3
MINISSDPD="/usr/sbin/minissdpd"
3
MINISSDPD="/usr/sbin/minissdpd"
4
PIDFILE="/var/run/minissdpd.pid"
4
PIDFILE="/var/run/minissdpd.pid"
5
ROUTE="/bin/route"
6
IFCONFIG="/bin/ifconfig"
7
8
depend() {
5
depend() {
9
	need net
6
	need net
10
	before miniupnpd
7
	before miniupnpd
11
}
8
}
9
interfaceup() {
10
	# interface exists?
11
	if [ ! -f /sys/class/net/$1/flags ]; then return 1; fi
12
	let "IFUP = `cat /sys/class/net/$1/flags` & 1"
13
	# interface has UP flag?
14
	if [ $IFUP -eq 0 ]; then return 1; fi
15
	return 0
16
}
17
18
# awk script: scans the /proc routing table for local subnets
19
# 1. filter list for entries with a gateway (column 3) of 0.0.0.0 (ie interface-local)
20
# 2. read column 2 for network-order hex encoded subnet address
21
# 3. match against a 10.x.x.x, 172.(16-31).x.x, or 192.168.x.x address
22
# 4. print out any interface (column 1) that matches
23
privateinterfaces() {
24
	awk -f - /proc/net/route <<'FindPrivateNetworks'
25
function p(m,n) { return(and(IP,m) == n); }
26
$3=="00000000" { IP=strtonum("0x"$2); if (p(0xff,0x0a) || p(0x1fff,0x10ac) || p(0xffff,0xa8c0)) print $1; }
27
FindPrivateNetworks
28
}
29
12
checkconfig() {
30
checkconfig() {
13
	if [ "x$MINISSDPD_IFACE" != "x" ]; then
31
	# no-op
14
		interfaces=$($IFCONFIG | grep "Link encap" | awk '{ print $1 }')
15
		for interface in $MINISSDPD_IFACE; do
16
			hit=0
17
			for available in $interfaces; do
18
				if [ "$interface" = "$available" ]; then
19
					hit=1
20
				fi
21
			done
22
			if [ $hit = 0 ]; then
23
				ewarn "Interface $interface not available"
24
				return 1
25
			fi
26
		done
27
	fi
28
	return 0
32
	return 0
29
}
33
}
Lines 34-55 Link Here
34
	ebegin "Starting minissdpd"
38
	ebegin "Starting minissdpd"
35
	checkconfig || return 1
39
	checkconfig || return 1
40
	ARGS=""
36
	if [ "x$MINISSDPD_IFACE" = "x" ]; then
41
	if [ "x$MINISSDPD_IFACE" = "x" ]; then
37
		# We assume that the default interface has an IP address
42
		ewarn "No interfaces provided, using interfaces on private networks"
38
		interface=$($ROUTE | grep default | awk -- '{ print $8 }')
43
		IFLIST=$(privateinterfaces)
39
		IP="$($IFCONFIG $interface | grep 'inet' | sed 's/^.*inet \([0-9.]\+\).\+/\1/')"
40
		ARGS="-i $IP "
41
	else
44
	else
42
		ARGS=""
45
		IFLIST="$MINISSDPD_IFACE"
43
		for interface in $MINISSDPD_IFACE; do
44
			# An interface may not have an IP address, so don't listen if it doesn't
45
			IP="$($IFCONFIG $interface | grep 'inet' | sed 's/^.*inet \([0-9.]\+\).\+/\1/')"
46
			if [ "x$IP" != "x" ]; then
47
				ARGS+="-i $IP "
48
			fi
49
		done
50
	fi
46
	fi
47
	eindent
48
	for IF in $IFLIST; do
49
		if interfaceup $IF; then
50
			einfo Adding interface $IF
51
			ARGS+="-i $IF "
52
		else
53
			ewarn "Interface $IF is not up"
54
		fi
55
	done
56
	eoutdent
51
	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $MINISSDPD -- $ARGS
57
	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $MINISSDPD -- $ARGS
52
	eend $?
58
	eend $?
53
}
59
}

Return to bug 533888