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

Unified Diff: ipv4/control.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
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ipv4/control_bsd.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ipv4/control.go
===================================================================
new file mode 100644
--- /dev/null
+++ b/ipv4/control.go
@@ -0,0 +1,47 @@
+// Copyright 2012 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package ipv4
+
+import (
+ "fmt"
+ "net"
+ "sync"
+)
+
+type rawOpt struct {
+ mu sync.Mutex
+ cflags ControlFlags
+}
+
+func (o *rawOpt) lock() { o.mu.Lock() }
+func (o *rawOpt) unlock() { o.mu.Unlock() }
+func (o *rawOpt) set(f ControlFlags) { o.cflags |= f }
+func (o *rawOpt) clear(f ControlFlags) { o.cflags ^= f }
+func (o *rawOpt) isset(f ControlFlags) bool { return o.cflags&f != 0 }
+
+type ControlFlags uint
+
+const (
+ FlagTTL ControlFlags = 1 << iota // pass the TTL on the received packet
+ FlagSrc // pass the source address on the received packet
+ FlagDst // pass the destination address on the received packet
+ FlagInterface // pass the interface index on the received packet or outgoing packet
+)
+
+// A ControlMessage represents control information that contains per
+// packet IP-level option data.
+type ControlMessage struct {
+ TTL int // time-to-live
+ Src net.IP // source address
+ Dst net.IP // destination address
+ IfIndex int // interface index
+}
+
+func (cm *ControlMessage) String() string {
+ if cm == nil {
+ return "<nil>"
+ }
+ return fmt.Sprintf("ttl: %v, src: %v, dst: %v, ifindex: %v", cm.TTL, cm.Src, cm.Dst, cm.IfIndex)
+}
« no previous file with comments | « no previous file | ipv4/control_bsd.go » ('j') | no next file with comments »

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