Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(703)

Delta Between Two Patch Sets: ipv4/mocktransponder_test.go

Issue 6482044: code review 6482044: go.net/ipv4: new package (Closed)
Left Patch Set: diff -r 2513e9008213 https://code.google.com/p/go.net Created 11 years, 6 months ago
Right Patch Set: diff -r 2513e9008213 https://code.google.com/p/go.net Created 11 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « ipv4/mockicmp_test.go ('k') | ipv4/multicast_test.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 // +build darwin freebsd linux netbsd openbsd 5 // +build darwin freebsd linux netbsd openbsd
6 6
7 package ipv4_test 7 package ipv4_test
8 8
9 import ( 9 import (
10 "code.google.com/p/go.net/ipv4" 10 "code.google.com/p/go.net/ipv4"
11 "net" 11 "net"
12 "testing" 12 "testing"
13 "time" 13 "time"
14 ) 14 )
15 15
16 // runPayloadTransponder transmits IPv4 datagram payloads to the 16 // runPayloadTransponder transmits IPv4 datagram payloads to the
17 // loopback address or interface and captures the loopback'd packet 17 // loopback address or interface and captures the loopback'd datagram
18 // payloads. 18 // payloads.
19 func runPayloadTransponder(t *testing.T, c *ipv4.PacketConn, wb []byte, dst net. Addr) { 19 func runPayloadTransponder(t *testing.T, c *ipv4.PacketConn, wb []byte, dst net. Addr) {
20 cf := ipv4.FlagTTL | ipv4.FlagDst | ipv4.FlagInterface 20 cf := ipv4.FlagTTL | ipv4.FlagDst | ipv4.FlagInterface
21 rb := make([]byte, 1500) 21 rb := make([]byte, 1500)
22 for i, toggle := range []bool{true, false, true} { 22 for i, toggle := range []bool{true, false, true} {
23 if err := c.SetControlMessage(cf, toggle); err != nil { 23 if err := c.SetControlMessage(cf, toggle); err != nil {
24 t.Fatalf("ipv4.PacketConn.SetControlMessage failed: %v", err) 24 t.Fatalf("ipv4.PacketConn.SetControlMessage failed: %v", err)
25 } 25 }
26 c.SetTOS(i + 1) 26 c.SetTOS(i + 1)
27 var ip net.IP 27 var ip net.IP
(...skipping 13 matching lines...) Expand all
41 t.Fatalf("ipv4.PacketConn.Write failed: %v", err) 41 t.Fatalf("ipv4.PacketConn.Write failed: %v", err)
42 } 42 }
43 _, cm, _, err := c.Read(rb) 43 _, cm, _, err := c.Read(rb)
44 if err != nil { 44 if err != nil {
45 t.Fatalf("ipv4.PacketConn.Read failed: %v", err) 45 t.Fatalf("ipv4.PacketConn.Read failed: %v", err)
46 } 46 }
47 t.Logf("rcvd cmsg: %v", cm) 47 t.Logf("rcvd cmsg: %v", cm)
48 } 48 }
49 } 49 }
50 50
51 // runDatagramTransponder transmits IPv4 datagrams to the loopback 51 // runDatagramTransponder transmits ICMP for IPv4 datagrams to the
52 // address or interface and captures the response packets from the 52 // loopback address or interface and captures the response datagrams
53 // protocol stack within the kernel. 53 // from the protocol stack within the kernel.
54 func runDatagramTransponder(t *testing.T, c *ipv4.RawConn, wb []byte, src, dst n et.Addr) { 54 func runDatagramTransponder(t *testing.T, c *ipv4.RawConn, wb []byte, src, dst n et.Addr) {
55 cf := ipv4.FlagTTL | ipv4.FlagDst | ipv4.FlagInterface 55 cf := ipv4.FlagTTL | ipv4.FlagDst | ipv4.FlagInterface
56 rb := make([]byte, ipv4.HeaderLen+len(wb)) 56 rb := make([]byte, ipv4.HeaderLen+len(wb))
57 for i, toggle := range []bool{true, false, true} { 57 for i, toggle := range []bool{true, false, true} {
58 if err := c.SetControlMessage(cf, toggle); err != nil { 58 if err := c.SetControlMessage(cf, toggle); err != nil {
59 t.Fatalf("ipv4.RawConn.SetControlMessage failed: %v", er r) 59 t.Fatalf("ipv4.RawConn.SetControlMessage failed: %v", er r)
60 } 60 }
61 wh := &ipv4.Header{} 61 wh := &ipv4.Header{}
62 wh.Version = ipv4.Version
62 wh.Len = ipv4.HeaderLen 63 wh.Len = ipv4.HeaderLen
63 wh.TOS = i + 1 64 wh.TOS = i + 1
64 wh.TotalLen = ipv4.HeaderLen + len(wb) 65 wh.TotalLen = ipv4.HeaderLen + len(wb)
65 wh.TTL = i + 1 66 wh.TTL = i + 1
66 wh.Protocol = 1 67 wh.Protocol = 1
67 if src != nil { 68 if src != nil {
68 wh.Src = src.(*net.IPAddr).IP 69 wh.Src = src.(*net.IPAddr).IP
69 } 70 }
70 if dst != nil { 71 if dst != nil {
71 wh.Dst = dst.(*net.IPAddr).IP 72 wh.Dst = dst.(*net.IPAddr).IP
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 ip = nil 124 ip = nil
124 continue 125 continue
125 } 126 }
126 break 127 break
127 } 128 }
128 if ip == nil { 129 if ip == nil {
129 return nil, false 130 return nil, false
130 } 131 }
131 return ip, true 132 return ip, true
132 } 133 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b