diff options
Diffstat (limited to 'dhcpv4/nclient4')
-rw-r--r-- | dhcpv4/nclient4/client_test.go | 2 | ||||
-rw-r--r-- | dhcpv4/nclient4/conn_linux.go | 38 |
2 files changed, 1 insertions, 39 deletions
diff --git a/dhcpv4/nclient4/client_test.go b/dhcpv4/nclient4/client_test.go index c299697..df851ab 100644 --- a/dhcpv4/nclient4/client_test.go +++ b/dhcpv4/nclient4/client_test.go @@ -61,7 +61,7 @@ func serveAndClient(ctx context.Context, responses [][]*dhcpv4.DHCPv4, opts ...C } h := &handler{responses: responses} - s, err := server4.NewServer(nil, h.handle, server4.WithConn(serverConn)) + s, err := server4.NewServer("", nil, h.handle, server4.WithConn(serverConn)) if err != nil { panic(err) } diff --git a/dhcpv4/nclient4/conn_linux.go b/dhcpv4/nclient4/conn_linux.go index af6485f..064e6ca 100644 --- a/dhcpv4/nclient4/conn_linux.go +++ b/dhcpv4/nclient4/conn_linux.go @@ -10,13 +10,10 @@ import ( "fmt" "io" "net" - "os" - "github.com/insomniacslk/dhcp/dhcpv4" "github.com/mdlayher/ethernet" "github.com/mdlayher/raw" "github.com/u-root/u-root/pkg/uio" - "golang.org/x/sys/unix" ) var ( @@ -26,41 +23,6 @@ var ( BroadcastMac = net.HardwareAddr([]byte{255, 255, 255, 255, 255, 255}) ) -// NewIPv4UDPConn returns a UDP connection bound to both the interface and port -// given based on a IPv4 DGRAM socket. The UDP connection allows broadcasting. -// -// The interface must already be configured. -func NewIPv4UDPConn(iface string, port int) (net.PacketConn, error) { - fd, err := unix.Socket(unix.AF_INET, unix.SOCK_DGRAM, unix.IPPROTO_UDP) - if err != nil { - return nil, fmt.Errorf("cannot get a UDP socket: %v", err) - } - f := os.NewFile(uintptr(fd), "") - // net.FilePacketConn dups the FD, so we have to close this in any case. - defer f.Close() - - // Allow broadcasting. - if err := unix.SetsockoptInt(fd, unix.SOL_SOCKET, unix.SO_BROADCAST, 1); err != nil { - return nil, fmt.Errorf("cannot set broadcasting on socket: %v", err) - } - // Allow reusing the addr to aid debugging. - if err := unix.SetsockoptInt(fd, unix.SOL_SOCKET, unix.SO_REUSEADDR, 1); err != nil { - return nil, fmt.Errorf("cannot set reuseaddr on socket: %v", err) - } - if len(iface) != 0 { - // Bind directly to the interface. - if err := dhcpv4.BindToInterface(fd, iface); err != nil { - return nil, fmt.Errorf("cannot bind to interface %s: %v", iface, err) - } - } - // Bind to the port. - if err := unix.Bind(fd, &unix.SockaddrInet4{Port: port}); err != nil { - return nil, fmt.Errorf("cannot bind to port %d: %v", port, err) - } - - return net.FilePacketConn(f) -} - // NewRawUDPConn returns a UDP connection bound to the interface and port // given based on a raw packet socket. All packets are broadcasted. // |