Skip to content

Commit 4b357e2

Browse files
committed
address linter issues
1 parent b773fee commit 4b357e2

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

dhcp/dhcp_windows.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ package dhcp
22

33
import (
44
"context"
5-
"golang.org/x/sys/windows"
65
"net"
76
"regexp"
87
"time"
98

109
"github.com/pkg/errors"
1110
"go.uber.org/zap"
11+
"golang.org/x/sys/windows"
1212
)
1313

1414
const (
@@ -21,7 +21,7 @@ const (
2121
)
2222

2323
var (
24-
dummyIPAddress = net.IPv4(169, 254, 128, 10)
24+
dummyIPAddress = net.IPv4(169, 254, 128, 10) // nolint
2525
// matches if the string fully consists of zero or more alphanumeric, dots, dashes, parentheses, spaces, or underscores
2626
allowedInput = regexp.MustCompile(`^[a-zA-Z0-9._\-\(\) ]*$`)
2727
)
@@ -41,7 +41,6 @@ func NewSocket(destAddr windows.SockaddrInet4) (*Socket, error) {
4141
if err != nil {
4242
return ret, errors.Wrap(err, "error creating socket")
4343
}
44-
defer windows.Closesocket(fd)
4544

4645
// Set IP_HDRINCL to indicate that we are including our own IP header
4746
err = windows.SetsockoptInt(fd, windows.IPPROTO_IP, windows.IP_HDRINCL, 1)
@@ -67,6 +66,7 @@ func (s *Socket) Write(packetBytes []byte) (int, error) {
6766
}
6867
return len(packetBytes), nil
6968
}
69+
7070
func (s *Socket) Read(p []byte) (n int, err error) {
7171
n, _, innerErr := windows.Recvfrom(s.fd, p, 0)
7272
if innerErr != nil {
@@ -81,7 +81,7 @@ func (s *Socket) Close() error {
8181
return nil
8282
}
8383
// Ensure the file descriptor is closed when done
84-
if err := windows.Close(s.fd); err != nil {
84+
if err := windows.Closesocket(s.fd); err != nil {
8585
return errors.Wrap(err, "error closing dhcp windows socket")
8686
}
8787
return nil
@@ -108,8 +108,8 @@ func (c *DHCP) DiscoverRequest(ctx context.Context, macAddress net.HardwareAddr,
108108
}
109109
// ensure we always remove the dummy ip we added from the interface
110110
defer func() {
111-
ret, err := c.execClient.ExecuteCommand(ctx, "netsh", "interface", "ipv4", "delete", "address", ifName, dummyIPAddressStr)
112-
if err != nil {
111+
ret, cleanupErr := c.execClient.ExecuteCommand(ctx, "netsh", "interface", "ipv4", "delete", "address", ifName, dummyIPAddressStr)
112+
if cleanupErr != nil {
113113
c.logger.Info("Could not remove dummy ip on leaving function", zap.String("output", ret), zap.Error(err))
114114
}
115115
}()
@@ -139,7 +139,7 @@ func (c *DHCP) DiscoverRequest(ctx context.Context, macAddress net.HardwareAddr,
139139

140140
destAddr := windows.SockaddrInet4{
141141
Addr: [4]byte{255, 255, 255, 255}, // Destination IP
142-
Port: 67, // Destination Port
142+
Port: dhcpServerPort, // Destination Port
143143
}
144144
// create new socket for writing and reading
145145
sock, err := NewSocket(destAddr)

0 commit comments

Comments
 (0)