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

LGTM=iant
R=iant
CC=golang-codereviews
https://golang.org/cl/171810043
This commit is contained in:
Mikio Hara
2014-11-06 11:45:53 +09:00
parent 3a0acf563f
commit 75d3d53ceb
2 changed files with 3 additions and 3 deletions

View File

@@ -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)
}
}

View File

@@ -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)
}
}