Commit b38392a4 authored by Mikio Hara's avatar Mikio Hara

go.net/ipv4: simplify, drop unnecessary parentheses and slice indices

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/7300102
parent ea127e88
......@@ -95,7 +95,7 @@ func marshalControlMessage(cm *ControlMessage) (oob []byte) {
pi := &syscall.Inet4Pktinfo{}
pion := false
if ip := cm.Src.To4(); ip != nil {
copy(pi.Spec_dst[:], ip[0:net.IPv4len])
copy(pi.Spec_dst[:], ip[:net.IPv4len])
pion = true
}
if cm.IfIndex != 0 {
......@@ -109,7 +109,7 @@ func marshalControlMessage(cm *ControlMessage) (oob []byte) {
cmsg.Type = syscall.IP_PKTINFO
cmsg.SetLen(syscall.CmsgLen(syscall.SizeofInet4Pktinfo))
data := b[syscall.CmsgLen(0):]
copy(data[0:syscall.SizeofInet4Pktinfo], (*[syscall.SizeofInet4Pktinfo]byte)(unsafe.Pointer(pi))[:syscall.SizeofInet4Pktinfo])
copy(data[:syscall.SizeofInet4Pktinfo], (*[syscall.SizeofInet4Pktinfo]byte)(unsafe.Pointer(pi))[:syscall.SizeofInet4Pktinfo])
oob = append(oob, b...)
}
return
......
......@@ -146,10 +146,10 @@ func (h *Header) Marshal() ([]byte, error) {
b[posProtocol] = byte(h.Protocol)
b[posChecksum], b[posChecksum+1] = byte(h.Checksum>>8), byte(h.Checksum)
if ip := h.Src.To4(); ip != nil {
copy(b[posSrc:posSrc+net.IPv4len], ip[0:net.IPv4len])
copy(b[posSrc:posSrc+net.IPv4len], ip[:net.IPv4len])
}
if ip := h.Dst.To4(); ip != nil {
copy(b[posDst:posDst+net.IPv4len], ip[0:net.IPv4len])
copy(b[posDst:posDst+net.IPv4len], ip[:net.IPv4len])
} else {
return nil, errMissingAddress
}
......@@ -164,7 +164,7 @@ func ParseHeader(b []byte) (*Header, error) {
if len(b) < HeaderLen {
return nil, errHeaderTooShort
}
hdrlen := (int(b[0]) & 0x0f) << 2
hdrlen := int(b[0]&0x0f) << 2
if hdrlen > len(b) {
return nil, errBufferTooShort
}
......
......@@ -49,7 +49,7 @@ func slicePacket(b []byte) (h, p []byte, err error) {
if len(b) < HeaderLen {
return nil, nil, errHeaderTooShort
}
hdrlen := (int(b[0]) & 0x0f) << 2
hdrlen := int(b[0]&0x0f) << 2
return b[:hdrlen], b[hdrlen:], nil
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment