OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [net/] [sockoptip.go] - Blame information for rev 848

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// Copyright 2011 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
// +build darwin freebsd linux netbsd openbsd windows
6
 
7
// IP-level socket options
8
 
9
package net
10
 
11
import (
12
        "os"
13
        "syscall"
14
)
15
 
16
func ipv4TOS(fd *netFD) (int, error) {
17
        fd.incref()
18
        defer fd.decref()
19
        v, err := syscall.GetsockoptInt(fd.sysfd, syscall.IPPROTO_IP, syscall.IP_TOS)
20
        if err != nil {
21
                return -1, os.NewSyscallError("getsockopt", err)
22
        }
23
        return v, nil
24
}
25
 
26
func setIPv4TOS(fd *netFD, v int) error {
27
        fd.incref()
28
        defer fd.decref()
29
        err := syscall.SetsockoptInt(fd.sysfd, syscall.IPPROTO_IP, syscall.IP_TOS, v)
30
        if err != nil {
31
                return os.NewSyscallError("setsockopt", err)
32
        }
33
        return nil
34
}
35
 
36
func ipv4TTL(fd *netFD) (int, error) {
37
        fd.incref()
38
        defer fd.decref()
39
        v, err := syscall.GetsockoptInt(fd.sysfd, syscall.IPPROTO_IP, syscall.IP_TTL)
40
        if err != nil {
41
                return -1, os.NewSyscallError("getsockopt", err)
42
        }
43
        return v, nil
44
}
45
 
46
func setIPv4TTL(fd *netFD, v int) error {
47
        fd.incref()
48
        defer fd.decref()
49
        err := syscall.SetsockoptInt(fd.sysfd, syscall.IPPROTO_IP, syscall.IP_TTL, v)
50
        if err != nil {
51
                return os.NewSyscallError("setsockopt", err)
52
        }
53
        return nil
54
}
55
 
56
func joinIPv4Group(fd *netFD, ifi *Interface, ip IP) error {
57
        mreq := &syscall.IPMreq{Multiaddr: [4]byte{ip[0], ip[1], ip[2], ip[3]}}
58
        if err := setIPv4MreqToInterface(mreq, ifi); err != nil {
59
                return err
60
        }
61
        fd.incref()
62
        defer fd.decref()
63
        return os.NewSyscallError("setsockopt", syscall.SetsockoptIPMreq(fd.sysfd, syscall.IPPROTO_IP, syscall.IP_ADD_MEMBERSHIP, mreq))
64
}
65
 
66
func leaveIPv4Group(fd *netFD, ifi *Interface, ip IP) error {
67
        mreq := &syscall.IPMreq{Multiaddr: [4]byte{ip[0], ip[1], ip[2], ip[3]}}
68
        if err := setIPv4MreqToInterface(mreq, ifi); err != nil {
69
                return err
70
        }
71
        fd.incref()
72
        defer fd.decref()
73
        return os.NewSyscallError("setsockopt", syscall.SetsockoptIPMreq(fd.sysfd, syscall.IPPROTO_IP, syscall.IP_DROP_MEMBERSHIP, mreq))
74
}
75
 
76
func ipv6HopLimit(fd *netFD) (int, error) {
77
        fd.incref()
78
        defer fd.decref()
79
        v, err := syscall.GetsockoptInt(fd.sysfd, syscall.IPPROTO_IPV6, syscall.IPV6_UNICAST_HOPS)
80
        if err != nil {
81
                return -1, os.NewSyscallError("getsockopt", err)
82
        }
83
        return v, nil
84
}
85
 
86
func setIPv6HopLimit(fd *netFD, v int) error {
87
        fd.incref()
88
        defer fd.decref()
89
        err := syscall.SetsockoptInt(fd.sysfd, syscall.IPPROTO_IPV6, syscall.IPV6_UNICAST_HOPS, v)
90
        if err != nil {
91
                return os.NewSyscallError("setsockopt", err)
92
        }
93
        return nil
94
}
95
 
96
func ipv6MulticastInterface(fd *netFD) (*Interface, error) {
97
        fd.incref()
98
        defer fd.decref()
99
        v, err := syscall.GetsockoptInt(fd.sysfd, syscall.IPPROTO_IPV6, syscall.IPV6_MULTICAST_IF)
100
        if err != nil {
101
                return nil, os.NewSyscallError("getsockopt", err)
102
        }
103
        if v == 0 {
104
                return nil, nil
105
        }
106
        ifi, err := InterfaceByIndex(v)
107
        if err != nil {
108
                return nil, err
109
        }
110
        return ifi, nil
111
}
112
 
113
func setIPv6MulticastInterface(fd *netFD, ifi *Interface) error {
114
        var v int
115
        if ifi != nil {
116
                v = ifi.Index
117
        }
118
        fd.incref()
119
        defer fd.decref()
120
        err := syscall.SetsockoptInt(fd.sysfd, syscall.IPPROTO_IPV6, syscall.IPV6_MULTICAST_IF, v)
121
        if err != nil {
122
                return os.NewSyscallError("setsockopt", err)
123
        }
124
        return nil
125
}
126
 
127
func ipv6MulticastHopLimit(fd *netFD) (int, error) {
128
        fd.incref()
129
        defer fd.decref()
130
        v, err := syscall.GetsockoptInt(fd.sysfd, syscall.IPPROTO_IPV6, syscall.IPV6_MULTICAST_HOPS)
131
        if err != nil {
132
                return -1, os.NewSyscallError("getsockopt", err)
133
        }
134
        return v, nil
135
}
136
 
137
func setIPv6MulticastHopLimit(fd *netFD, v int) error {
138
        fd.incref()
139
        defer fd.decref()
140
        err := syscall.SetsockoptInt(fd.sysfd, syscall.IPPROTO_IPV6, syscall.IPV6_MULTICAST_HOPS, v)
141
        if err != nil {
142
                return os.NewSyscallError("setsockopt", err)
143
        }
144
        return nil
145
}
146
 
147
func ipv6MulticastLoopback(fd *netFD) (bool, error) {
148
        fd.incref()
149
        defer fd.decref()
150
        v, err := syscall.GetsockoptInt(fd.sysfd, syscall.IPPROTO_IPV6, syscall.IPV6_MULTICAST_LOOP)
151
        if err != nil {
152
                return false, os.NewSyscallError("getsockopt", err)
153
        }
154
        return v == 1, nil
155
}
156
 
157
func setIPv6MulticastLoopback(fd *netFD, v bool) error {
158
        fd.incref()
159
        defer fd.decref()
160
        err := syscall.SetsockoptInt(fd.sysfd, syscall.IPPROTO_IPV6, syscall.IPV6_MULTICAST_LOOP, boolint(v))
161
        if err != nil {
162
                return os.NewSyscallError("setsockopt", err)
163
        }
164
        return nil
165
}
166
 
167
func joinIPv6Group(fd *netFD, ifi *Interface, ip IP) error {
168
        mreq := &syscall.IPv6Mreq{}
169
        copy(mreq.Multiaddr[:], ip)
170
        if ifi != nil {
171
                mreq.Interface = uint32(ifi.Index)
172
        }
173
        fd.incref()
174
        defer fd.decref()
175
        return os.NewSyscallError("setsockopt", syscall.SetsockoptIPv6Mreq(fd.sysfd, syscall.IPPROTO_IPV6, syscall.IPV6_JOIN_GROUP, mreq))
176
}
177
 
178
func leaveIPv6Group(fd *netFD, ifi *Interface, ip IP) error {
179
        mreq := &syscall.IPv6Mreq{}
180
        copy(mreq.Multiaddr[:], ip)
181
        if ifi != nil {
182
                mreq.Interface = uint32(ifi.Index)
183
        }
184
        fd.incref()
185
        defer fd.decref()
186
        return os.NewSyscallError("setsockopt", syscall.SetsockoptIPv6Mreq(fd.sysfd, syscall.IPPROTO_IPV6, syscall.IPV6_LEAVE_GROUP, mreq))
187
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.