LEFT | RIGHT |
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 // Package ipv4 implements IP-level socket options for the Internet | 5 // Package ipv4 implements IP-level socket options for the Internet |
6 // Protocol version 4. | 6 // Protocol version 4. |
7 // | 7 // |
8 // The package provides IP-level socket options that allow manipulaton | 8 // The package provides IP-level socket options that allow |
9 // of IPv4 facilities. The IPv4 and basic host requirements for IPv4 | 9 // manipulation of IPv4 facilities. The IPv4 and basic host |
10 // are defined in RFC 791, 1112 and 1122. A series of RFCs 2474, | 10 // requirements for IPv4 are defined in RFC 791, 1112 and 1122. A |
11 // 2475, 2597, 2598 and 3168 describe how to use the type-of-service | 11 // series of RFCs 2474, 2475, 2597, 2598 and 3168 describe how to use |
12 // field on the DiffServ, differentiated services environment. | 12 // the type-of-service field in a DiffServ, differentiated services |
| 13 // environment. |
13 // | 14 // |
14 // | 15 // |
15 // Unicasting | 16 // Unicasting |
16 // | 17 // |
17 // The options for unicasting are available for net.TCPConn, | 18 // The options for unicasting are available for net.TCPConn, |
18 // net.UDPConn and net.IPConn which are created as network connections | 19 // net.UDPConn and net.IPConn which are created as network connections |
19 // that use the IPv4 transport. When a single TCP connection carrying | 20 // that use the IPv4 transport. When a single TCP connection carrying |
20 // a data flow of multiple packets needs to indicate the flow is | 21 // a data flow of multiple packets needs to indicate the flow is |
21 // important, ipv4.Conn is used to set the type-of-service field on | 22 // important, ipv4.Conn is used to set the type-of-service field on |
22 // the IPv4 header for each packet. | 23 // the IPv4 header for each packet. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 // | 73 // |
73 // c, err := net.ListenPacket("udp4", "0.0.0.0:1024") | 74 // c, err := net.ListenPacket("udp4", "0.0.0.0:1024") |
74 // if err != nil { | 75 // if err != nil { |
75 // // error handling | 76 // // error handling |
76 // } | 77 // } |
77 // defer c.Close() | 78 // defer c.Close() |
78 // | 79 // |
79 // Second, the application joins groups, starts listening to the | 80 // Second, the application joins groups, starts listening to the |
80 // group addresses on the specified network interfaces. Note that | 81 // group addresses on the specified network interfaces. Note that |
81 // the service port for transport layer protocol does not matter with | 82 // the service port for transport layer protocol does not matter with |
82 // this operation because joining groups affects only network and link | 83 // this operation as joining groups affects only network and link |
83 // layer protocols, such as IPv4 and Ethernet. | 84 // layer protocols, such as IPv4 and Ethernet. |
84 // | 85 // |
85 // p := ipv4.NewPacketConn(c) | 86 // p := ipv4.NewPacketConn(c) |
86 // err = p.JoinGroup(en0, &net.UDPAddr{IP: group}) | 87 // err = p.JoinGroup(en0, &net.UDPAddr{IP: group}) |
87 // if err != nil { | 88 // if err != nil { |
88 // // error handling | 89 // // error handling |
89 // } | 90 // } |
90 // err = p.JoinGroup(en1, &net.UDPAddr{IP: group}) | 91 // err = p.JoinGroup(en1, &net.UDPAddr{IP: group}) |
91 // if err != nil { | 92 // if err != nil { |
92 // // error handling | 93 // // error handling |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 // // error handling | 143 // // error handling |
143 // } | 144 // } |
144 // } | 145 // } |
145 // } | 146 // } |
146 // | 147 // |
147 // | 148 // |
148 // More multicasting | 149 // More multicasting |
149 // | 150 // |
150 // An application that uses PacketConn or RawConn might join the | 151 // An application that uses PacketConn or RawConn might join the |
151 // multiple group addresses. For example, a UDP listener with port | 152 // multiple group addresses. For example, a UDP listener with port |
152 // 1024 might join two diffrent groups across over two different | 153 // 1024 might join two different groups across over two different |
153 // network interfaces by using: | 154 // network interfaces by using: |
154 // | 155 // |
155 // c, err := net.ListenPacket("udp4", "0.0.0.0:1024") | 156 // c, err := net.ListenPacket("udp4", "0.0.0.0:1024") |
156 // if err != nil { | 157 // if err != nil { |
157 // // error handling | 158 // // error handling |
158 // } | 159 // } |
159 // defer c.Close() | 160 // defer c.Close() |
160 // p := ipv4.NewPacketConn(c) | 161 // p := ipv4.NewPacketConn(c) |
161 // err = p.JoinGroup(en0, &net.UDPAddr{IP: net.IPv4(224, 0, 0, 248)}) | 162 // err = p.JoinGroup(en0, &net.UDPAddr{IP: net.IPv4(224, 0, 0, 248)}) |
162 // if err != nil { | 163 // if err != nil { |
163 // // error handling | 164 // // error handling |
164 // } | 165 // } |
165 // err = p.JoinGroup(en0, &net.UDPAddr{IP: net.IPv4(224, 0, 0, 249)}) | 166 // err = p.JoinGroup(en0, &net.UDPAddr{IP: net.IPv4(224, 0, 0, 249)}) |
166 // if err != nil { | 167 // if err != nil { |
167 // // error handling | 168 // // error handling |
168 // } | 169 // } |
169 // err = p.JoinGroup(en1, &net.UDPAddr{IP: net.IPv4(224, 0, 0, 249)}) | 170 // err = p.JoinGroup(en1, &net.UDPAddr{IP: net.IPv4(224, 0, 0, 249)}) |
170 // if err != nil { | 171 // if err != nil { |
171 // // error handling | 172 // // error handling |
172 // } | 173 // } |
173 // | 174 // |
174 // It is possible for multiple UDP listeners that listen to the same | 175 // It is possible for multiple UDP listeners that listen on the same |
175 // UDP port to join the same group address. The net package will | 176 // UDP port to join the same group address. The net package will |
176 // provide a socket that listens to a wildcard address with resuable | 177 // provide a socket that listens to a wildcard address with reusable |
177 // UDP port when an appropriate multicast address prefix is passed to | 178 // UDP port when an appropriate multicast address prefix is passed to |
178 // the net.ListenPacket or net.ListenUDP. | 179 // the net.ListenPacket or net.ListenUDP. |
179 // | 180 // |
180 // c1, err := net.ListenPacket("udp4", "224.0.0.0:1024") | 181 // c1, err := net.ListenPacket("udp4", "224.0.0.0:1024") |
181 // if err != nil { | 182 // if err != nil { |
182 // // error handling | 183 // // error handling |
183 // } | 184 // } |
184 // defer c1.Close() | 185 // defer c1.Close() |
185 // c2, err := net.ListenPacket("udp4", "224.0.0.0:1024") | 186 // c2, err := net.ListenPacket("udp4", "224.0.0.0:1024") |
186 // if err != nil { | 187 // if err != nil { |
(...skipping 16 matching lines...) Expand all Loading... |
203 // | 204 // |
204 // err = p.LeaveGroup(en0, &net.UDPAddr{IP: net.IPv4(224, 0, 0, 248)}) | 205 // err = p.LeaveGroup(en0, &net.UDPAddr{IP: net.IPv4(224, 0, 0, 248)}) |
205 // if err != nil { | 206 // if err != nil { |
206 // // error handling | 207 // // error handling |
207 // } | 208 // } |
208 // err = p.JoinGroup(en0, &net.UDPAddr{IP: net.IPv4(224, 0, 0, 250)}) | 209 // err = p.JoinGroup(en0, &net.UDPAddr{IP: net.IPv4(224, 0, 0, 250)}) |
209 // if err != nil { | 210 // if err != nil { |
210 // // error handling | 211 // // error handling |
211 // } | 212 // } |
212 package ipv4 | 213 package ipv4 |
LEFT | RIGHT |