Browse Source

go.net/ipv4: don't set ifindex to negative integers

LGTM=iant
R=iant
CC=golang-codereviews
https://golang.org/cl/171810043
Mikio Hara 11 years ago
parent
commit
75d3d53ceb
2 changed files with 3 additions and 3 deletions
  1. 1 1
      ipv4/control_pktinfo.go
  2. 2 2
      ipv4/control_unix.go

+ 1 - 1
ipv4/control_pktinfo.go

@@ -23,7 +23,7 @@ func marshalPacketInfo(b []byte, cm *ControlMessage) []byte {
 		if ip := cm.Src.To4(); ip != nil {
 			copy(pi.Spec_dst[:], ip)
 		}
-		if cm.IfIndex != 0 {
+		if cm.IfIndex > 0 {
 			pi.setIfindex(cm.IfIndex)
 		}
 	}

+ 2 - 2
ipv4/control_unix.go

@@ -137,7 +137,7 @@ func marshalControlMessage(cm *ControlMessage) (oob []byte) {
 	}
 	var l int
 	if ctlOpts[ctlPacketInfo].name > 0 {
-		if cm.Src.To4() != nil || cm.IfIndex != 0 {
+		if cm.Src.To4() != nil || cm.IfIndex > 0 {
 			l += syscall.CmsgSpace(ctlOpts[ctlPacketInfo].length)
 		}
 	}
@@ -145,7 +145,7 @@ func marshalControlMessage(cm *ControlMessage) (oob []byte) {
 		oob = make([]byte, l)
 		b := oob
 		if ctlOpts[ctlPacketInfo].name > 0 {
-			if cm.Src.To4() != nil || cm.IfIndex != 0 {
+			if cm.Src.To4() != nil || cm.IfIndex > 0 {
 				b = ctlOpts[ctlPacketInfo].marshal(b, cm)
 			}
 		}