本文整理匯總了Golang中syscall.CmsgLen函數的典型用法代碼示例。如果您正苦於以下問題:Golang CmsgLen函數的具體用法?Golang CmsgLen怎麽用?Golang CmsgLen使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CmsgLen函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: newControlMessage
func newControlMessage(opt *rawOpt) (oob []byte) {
opt.Lock()
defer opt.Unlock()
l, off := 0, 0
if opt.isset(FlagHopLimit) {
l += syscall.CmsgSpace(4)
}
if opt.isset(pktinfo) {
l += syscall.CmsgSpace(sysSizeofPacketInfo)
}
if l > 0 {
oob = make([]byte, l)
if opt.isset(FlagHopLimit) {
m := (*syscall.Cmsghdr)(unsafe.Pointer(&oob[off]))
m.Level = ianaProtocolIPv6
m.Type = sysSockopt2292HopLimit
m.SetLen(syscall.CmsgLen(4))
off += syscall.CmsgSpace(4)
}
if opt.isset(pktinfo) {
m := (*syscall.Cmsghdr)(unsafe.Pointer(&oob[off]))
m.Level = ianaProtocolIPv6
m.Type = sysSockopt2292PacketInfo
m.SetLen(syscall.CmsgLen(sysSizeofPacketInfo))
off += syscall.CmsgSpace(sysSizeofPacketInfo)
}
}
return
}
示例2: newControlMessage
func newControlMessage(opt *rawOpt) (oob []byte) {
opt.Lock()
defer opt.Unlock()
l, off := 0, 0
if opt.isset(FlagTTL) {
l += syscall.CmsgSpace(1)
}
if opt.isset(pktinfo) {
l += syscall.CmsgSpace(syscall.SizeofInet4Pktinfo)
}
if l > 0 {
oob = make([]byte, l)
if opt.isset(FlagTTL) {
m := (*syscall.Cmsghdr)(unsafe.Pointer(&oob[off]))
m.Level = ianaProtocolIP
m.Type = syscall.IP_RECVTTL
m.SetLen(syscall.CmsgLen(1))
off += syscall.CmsgSpace(1)
}
if opt.isset(pktinfo) {
m := (*syscall.Cmsghdr)(unsafe.Pointer(&oob[off]))
m.Level = ianaProtocolIP
m.Type = syscall.IP_PKTINFO
m.SetLen(syscall.CmsgLen(syscall.SizeofInet4Pktinfo))
off += syscall.CmsgSpace(syscall.SizeofInet4Pktinfo)
}
}
return
}
示例3: marshalControlMessage
func marshalControlMessage(cm *ControlMessage) (oob []byte) {
if cm == nil {
return
}
l, off := 0, 0
pion := false
if cm.Src.To4() != nil || cm.IfIndex != 0 {
pion = true
l += syscall.CmsgSpace(syscall.SizeofInet4Pktinfo)
}
if l > 0 {
oob = make([]byte, l)
if pion {
m := (*syscall.Cmsghdr)(unsafe.Pointer(&oob[off]))
m.Level = ianaProtocolIP
m.Type = syscall.IP_PKTINFO
m.SetLen(syscall.CmsgLen(syscall.SizeofInet4Pktinfo))
pi := (*syscall.Inet4Pktinfo)(unsafe.Pointer(&oob[off+syscall.CmsgLen(0)]))
if ip := cm.Src.To4(); ip != nil {
copy(pi.Addr[:], ip)
}
if cm.IfIndex != 0 {
pi.Ifindex = int32(cm.IfIndex)
}
off += syscall.CmsgSpace(syscall.SizeofInet4Pktinfo)
}
}
return
}
示例4: newControlMessage
func newControlMessage(opt *rawOpt) (oob []byte) {
opt.lock()
defer opt.unlock()
if opt.isset(FlagTTL) {
b := make([]byte, syscall.CmsgSpace(1))
cmsg := (*syscall.Cmsghdr)(unsafe.Pointer(&b[0]))
cmsg.Level = ianaProtocolIP
cmsg.Type = syscall.IP_RECVTTL
cmsg.SetLen(syscall.CmsgLen(1))
oob = append(oob, b...)
}
if opt.isset(FlagDst) {
b := make([]byte, syscall.CmsgSpace(net.IPv4len))
cmsg := (*syscall.Cmsghdr)(unsafe.Pointer(&b[0]))
cmsg.Level = ianaProtocolIP
cmsg.Type = syscall.IP_RECVDSTADDR
cmsg.SetLen(syscall.CmsgLen(net.IPv4len))
oob = append(oob, b...)
}
if opt.isset(FlagInterface) {
b := make([]byte, syscall.CmsgSpace(syscall.SizeofSockaddrDatalink))
cmsg := (*syscall.Cmsghdr)(unsafe.Pointer(&b[0]))
cmsg.Level = ianaProtocolIP
cmsg.Type = syscall.IP_RECVIF
cmsg.SetLen(syscall.CmsgLen(syscall.SizeofSockaddrDatalink))
oob = append(oob, b...)
}
return
}
示例5: marshalControlMessage
func marshalControlMessage(cm *ControlMessage) (oob []byte) {
if cm == nil {
return
}
pi := &syscall.Inet4Pktinfo{}
pion := false
if ip := cm.Src.To4(); ip != nil {
copy(pi.Spec_dst[:], ip[:net.IPv4len])
pion = true
}
if cm.IfIndex != 0 {
pi.Ifindex = int32(cm.IfIndex)
pion = true
}
if pion {
b := make([]byte, syscall.CmsgSpace(syscall.SizeofInet4Pktinfo))
cmsg := (*syscall.Cmsghdr)(unsafe.Pointer(&b[0]))
cmsg.Level = ianaProtocolIP
cmsg.Type = syscall.IP_PKTINFO
cmsg.SetLen(syscall.CmsgLen(syscall.SizeofInet4Pktinfo))
data := b[syscall.CmsgLen(0):]
copy(data[:syscall.SizeofInet4Pktinfo], (*[syscall.SizeofInet4Pktinfo]byte)(unsafe.Pointer(pi))[:syscall.SizeofInet4Pktinfo])
oob = append(oob, b...)
}
return
}
示例6: marshalHopLimit
func marshalHopLimit(b []byte, cm *ControlMessage) []byte {
m := (*syscall.Cmsghdr)(unsafe.Pointer(&b[0]))
m.Level = iana.ProtocolIPv6
m.Type = sysIPV6_HOPLIMIT
m.SetLen(syscall.CmsgLen(4))
if cm != nil {
data := b[syscall.CmsgLen(0):]
nativeEndian.PutUint32(data[:4], uint32(cm.HopLimit))
}
return b[syscall.CmsgSpace(4):]
}
示例7: marshalNextHop
func marshalNextHop(b []byte, cm *ControlMessage) []byte {
m := (*syscall.Cmsghdr)(unsafe.Pointer(&b[0]))
m.Level = iana.ProtocolIPv6
m.Type = sysIPV6_NEXTHOP
m.SetLen(syscall.CmsgLen(sysSizeofSockaddrInet6))
if cm != nil {
sa := (*sysSockaddrInet6)(unsafe.Pointer(&b[syscall.CmsgLen(0)]))
sa.setSockaddr(cm.NextHop, cm.IfIndex)
}
return b[syscall.CmsgSpace(sysSizeofSockaddrInet6):]
}
示例8: marshal2292HopLimit
func marshal2292HopLimit(b []byte, cm *ControlMessage) []byte {
m := (*syscall.Cmsghdr)(unsafe.Pointer(&b[0]))
m.Level = ianaProtocolIPv6
m.Type = sysIPV6_2292HOPLIMIT
m.SetLen(syscall.CmsgLen(4))
if cm != nil {
data := b[syscall.CmsgLen(0):]
*(*int32)(unsafe.Pointer(&data[:4][0])) = int32(cm.HopLimit)
}
return b[syscall.CmsgSpace(4):]
}
示例9: marshalHopLimit
func marshalHopLimit(b []byte, cm *ControlMessage) []byte {
m := (*syscall.Cmsghdr)(unsafe.Pointer(&b[0]))
m.Level = iana.ProtocolIPv6
m.Type = sysIPV6_HOPLIMIT
m.SetLen(syscall.CmsgLen(4))
if cm != nil {
data := b[syscall.CmsgLen(0):]
// TODO(mikio): fix potential misaligned memory access
*(*int32)(unsafe.Pointer(&data[:4][0])) = int32(cm.HopLimit)
}
return b[syscall.CmsgSpace(4):]
}
示例10: newControlMessage
func newControlMessage(opt *rawOpt) (oob []byte) {
opt.Lock()
defer opt.Unlock()
l, off := 0, 0
if opt.isset(FlagTrafficClass) {
l += syscall.CmsgSpace(4)
}
if opt.isset(FlagHopLimit) {
l += syscall.CmsgSpace(4)
}
if opt.isset(pktinfo) {
l += syscall.CmsgSpace(syscall.SizeofInet6Pktinfo)
}
if opt.isset(FlagPathMTU) {
l += syscall.CmsgSpace(syscall.SizeofIPv6MTUInfo)
}
if l > 0 {
oob = make([]byte, l)
if opt.isset(FlagTrafficClass) {
m := (*syscall.Cmsghdr)(unsafe.Pointer(&oob[off]))
m.Level = ianaProtocolIPv6
m.Type = syscall.IPV6_RECVTCLASS
m.SetLen(syscall.CmsgLen(4))
off += syscall.CmsgSpace(4)
}
if opt.isset(FlagHopLimit) {
m := (*syscall.Cmsghdr)(unsafe.Pointer(&oob[off]))
m.Level = ianaProtocolIPv6
m.Type = syscall.IPV6_RECVHOPLIMIT
m.SetLen(syscall.CmsgLen(4))
off += syscall.CmsgSpace(4)
}
if opt.isset(pktinfo) {
m := (*syscall.Cmsghdr)(unsafe.Pointer(&oob[off]))
m.Level = ianaProtocolIPv6
m.Type = syscall.IPV6_RECVPKTINFO
m.SetLen(syscall.CmsgLen(syscall.SizeofInet6Pktinfo))
off += syscall.CmsgSpace(syscall.SizeofInet6Pktinfo)
}
if opt.isset(FlagPathMTU) {
m := (*syscall.Cmsghdr)(unsafe.Pointer(&oob[off]))
m.Level = ianaProtocolIPv6
m.Type = syscall.IPV6_RECVPATHMTU
m.SetLen(syscall.CmsgLen(syscall.SizeofIPv6MTUInfo))
off += syscall.CmsgSpace(syscall.SizeofIPv6MTUInfo)
}
}
return
}
示例11: marshalTTL
func marshalTTL(b []byte, cm *ControlMessage) []byte {
m := (*syscall.Cmsghdr)(unsafe.Pointer(&b[0]))
m.Level = iana.ProtocolIP
m.Type = sysIP_RECVTTL
m.SetLen(syscall.CmsgLen(1))
return b[syscall.CmsgSpace(1):]
}
示例12: marshal2292PacketInfo
func marshal2292PacketInfo(b []byte, cm *ControlMessage) []byte {
m := (*syscall.Cmsghdr)(unsafe.Pointer(&b[0]))
m.Level = iana.ProtocolIPv6
m.Type = sysIPV6_2292PKTINFO
m.SetLen(syscall.CmsgLen(sizeofInet6Pktinfo))
if cm != nil {
pi := (*inet6Pktinfo)(unsafe.Pointer(&b[syscall.CmsgLen(0)]))
if ip := cm.Src.To16(); ip != nil && ip.To4() == nil {
copy(pi.Addr[:], ip)
}
if cm.IfIndex > 0 {
pi.setIfindex(cm.IfIndex)
}
}
return b[syscall.CmsgSpace(sizeofInet6Pktinfo):]
}
示例13: marshalPacketInfo
func marshalPacketInfo(b []byte, cm *ControlMessage) []byte {
m := (*syscall.Cmsghdr)(unsafe.Pointer(&b[0]))
m.Level = iana.ProtocolIP
m.Type = sysIP_PKTINFO
m.SetLen(syscall.CmsgLen(sysSizeofInetPktinfo))
if cm != nil {
pi := (*sysInetPktinfo)(unsafe.Pointer(&b[syscall.CmsgLen(0)]))
if ip := cm.Src.To4(); ip != nil {
copy(pi.Spec_dst[:], ip)
}
if cm.IfIndex > 0 {
pi.setIfindex(cm.IfIndex)
}
}
return b[syscall.CmsgSpace(sysSizeofInetPktinfo):]
}
示例14: marshalInterface
func marshalInterface(b []byte, cm *ControlMessage) []byte {
m := (*syscall.Cmsghdr)(unsafe.Pointer(&b[0]))
m.Level = iana.ProtocolIP
m.Type = sysIP_RECVIF
m.SetLen(syscall.CmsgLen(syscall.SizeofSockaddrDatalink))
return b[syscall.CmsgSpace(syscall.SizeofSockaddrDatalink):]
}
示例15: marshalDst
func marshalDst(b []byte, cm *ControlMessage) []byte {
m := (*syscall.Cmsghdr)(unsafe.Pointer(&b[0]))
m.Level = iana.ProtocolIP
m.Type = sysIP_RECVDSTADDR
m.SetLen(syscall.CmsgLen(net.IPv4len))
return b[syscall.CmsgSpace(net.IPv4len):]
}