1 // Copyright 2017 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.
16 // A Conn represents a raw connection.
22 // NewConn returns a new raw connection.
23 func NewConn(c net.Conn) (*Conn, error) {
26 switch c := c.(type) {
29 cc.c, err = c.SyscallConn()
32 cc.c, err = c.SyscallConn()
35 cc.c, err = c.SyscallConn()
37 return nil, errors.New("unknown connection type")
45 func (o *Option) get(c *Conn, b []byte) (int, error) {
48 fn := func(s uintptr) {
49 n, operr = getsockopt(s, o.Level, o.Name, b)
51 if err := c.c.Control(fn); err != nil {
54 return n, os.NewSyscallError("getsockopt", operr)
57 func (o *Option) set(c *Conn, b []byte) error {
59 fn := func(s uintptr) {
60 operr = setsockopt(s, o.Level, o.Name, b)
62 if err := c.c.Control(fn); err != nil {
65 return os.NewSyscallError("setsockopt", operr)