1 // Copyright 2015 CoreOS, Inc.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
21 // PacketConns returns a slice containing a net.PacketConn for each matching socket type
22 // passed to this process.
24 // The order of the file descriptors is preserved in the returned slice.
25 // Nil values are used to fill any gaps. For example if systemd were to return file descriptors
26 // corresponding with "udp, tcp, udp", then the slice would contain {net.PacketConn, nil, net.PacketConn}
27 func PacketConns(unsetEnv bool) ([]net.PacketConn, error) {
28 files := Files(unsetEnv)
29 conns := make([]net.PacketConn, len(files))
31 for i, f := range files {
32 if pc, err := net.FilePacketConn(f); err == nil {