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

Side by Side Diff: ipv4/mockicmp_test.go

Issue 6482044: code review 6482044: go.net/ipv4: new package (Closed)
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:
View unified diff | Download patch
« no previous file with comments | « ipv4/helper_windows.go ('k') | ipv4/mocktransponder_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2012 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package ipv4_test
6
7 import (
8 "bytes"
9 "flag"
10 )
11
12 var testExternal = flag.Bool("external", true, "allow use of external networks d uring long test")
13
14 func newICMPEchoRequest(id, seqnum, msglen int, filler []byte) []byte {
15 b := newICMPInfoMessage(id, seqnum, msglen, filler)
16 b[0] = 8
17 // calculate ICMP checksum
18 cklen := len(b)
19 s := uint32(0)
20 for i := 0; i < cklen-1; i += 2 {
21 s += uint32(b[i+1])<<8 | uint32(b[i])
22 }
23 if cklen&1 == 1 {
24 s += uint32(b[cklen-1])
25 }
26 s = (s >> 16) + (s & 0xffff)
27 s = s + (s >> 16)
28 // place checksum back in header; using ^= avoids the
29 // assumption the checksum bytes are zero
30 b[2] ^= byte(^s & 0xff)
31 b[3] ^= byte(^s >> 8)
32 return b
33 }
34
35 func newICMPInfoMessage(id, seqnum, msglen int, filler []byte) []byte {
36 b := make([]byte, msglen)
37 copy(b[8:], bytes.Repeat(filler, (msglen-8)/len(filler)+1))
38 b[0] = 0 // type
39 b[1] = 0 // code
40 b[2] = 0 // checksum
41 b[3] = 0 // checksum
42 b[4] = byte(id >> 8) // identifier
43 b[5] = byte(id & 0xff) // identifier
44 b[6] = byte(seqnum >> 8) // sequence number
45 b[7] = byte(seqnum & 0xff) // sequence number
46 return b
47 }
OLDNEW
« no previous file with comments | « ipv4/helper_windows.go ('k') | ipv4/mocktransponder_test.go » ('j') | no next file with comments »

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