Просмотр исходного кода

Merge pull request #1730 from calmh/bug-1721

Don't hang when attempting multicast discovery on non-multicast interfaces
Audrius Butkevicius 10 лет назад
Родитель
Сommit
a5e11c7489
1 измененных файлов с 9 добавлено и 2 удалено
  1. 9 2
      internal/upnp/upnp.go

+ 9 - 2
internal/upnp/upnp.go

@@ -100,7 +100,7 @@ func Discover(timeout time.Duration) []IGD {
 		return results
 	}
 
-	resultChan := make(chan IGD, 16)
+	resultChan := make(chan IGD)
 
 	// Aggregator
 	go func() {
@@ -129,6 +129,13 @@ func Discover(timeout time.Duration) []IGD {
 
 	wg := sync.NewWaitGroup()
 	for _, intf := range interfaces {
+		if intf.Flags&net.FlagUp == 0 {
+			continue
+		}
+		if intf.Flags&net.FlagMulticast == 0 {
+			continue
+		}
+
 		for _, deviceType := range []string{"urn:schemas-upnp-org:device:InternetGatewayDevice:1", "urn:schemas-upnp-org:device:InternetGatewayDevice:2"} {
 			wg.Add(1)
 			go func(intf net.Interface, deviceType string) {
@@ -195,7 +202,7 @@ Mx: %d
 
 	// Listen for responses until a timeout is reached
 	for {
-		resp := make([]byte, 1500)
+		resp := make([]byte, 65536)
 		n, _, err := socket.ReadFrom(resp)
 		if err != nil {
 			if e, ok := err.(net.Error); !ok || !e.Timeout() {