OLD | NEW |
1 // Copyright 2012 The Go Authors. All rights reserved. | 1 // Copyright 2012 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package ipv4 | 5 package ipv4 |
6 | 6 |
7 import ( | 7 import ( |
8 "os" | 8 "os" |
9 "syscall" | 9 "syscall" |
10 "unsafe" | 10 "unsafe" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 for _, m := range cmsgs { | 82 for _, m := range cmsgs { |
83 if m.Header.Level != ianaProtocolIP { | 83 if m.Header.Level != ianaProtocolIP { |
84 continue | 84 continue |
85 } | 85 } |
86 switch m.Header.Type { | 86 switch m.Header.Type { |
87 case syscall.IP_TTL: | 87 case syscall.IP_TTL: |
88 cm.TTL = int(*(*byte)(unsafe.Pointer(&m.Data[:1][0]))) | 88 cm.TTL = int(*(*byte)(unsafe.Pointer(&m.Data[:1][0]))) |
89 case syscall.IP_PKTINFO: | 89 case syscall.IP_PKTINFO: |
90 pi := (*syscall.Inet4Pktinfo)(unsafe.Pointer(&m.Data[0])
) | 90 pi := (*syscall.Inet4Pktinfo)(unsafe.Pointer(&m.Data[0])
) |
91 cm.IfIndex = int(pi.Ifindex) | 91 cm.IfIndex = int(pi.Ifindex) |
| 92 cm.SpecDst = pi.Spec_dst[:] |
92 cm.Dst = pi.Addr[:] | 93 cm.Dst = pi.Addr[:] |
93 } | 94 } |
94 } | 95 } |
95 return cm, nil | 96 return cm, nil |
96 } | 97 } |
97 | 98 |
98 func marshalControlMessage(cm *ControlMessage) (oob []byte) { | 99 func marshalControlMessage(cm *ControlMessage) (oob []byte) { |
99 if cm == nil { | 100 if cm == nil { |
100 return | 101 return |
101 } | 102 } |
(...skipping 15 matching lines...) Expand all Loading... |
117 copy(pi.Addr[:], ip) | 118 copy(pi.Addr[:], ip) |
118 } | 119 } |
119 if cm.IfIndex != 0 { | 120 if cm.IfIndex != 0 { |
120 pi.Ifindex = int32(cm.IfIndex) | 121 pi.Ifindex = int32(cm.IfIndex) |
121 } | 122 } |
122 off += syscall.CmsgSpace(syscall.SizeofInet4Pktinfo) | 123 off += syscall.CmsgSpace(syscall.SizeofInet4Pktinfo) |
123 } | 124 } |
124 } | 125 } |
125 return | 126 return |
126 } | 127 } |
OLD | NEW |