Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(windows-agent): Check that IPs are convertible to ipv4 #1006

Merged
merged 2 commits into from
Dec 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func NewHostIPConfigMock(state MockIPAdaptersState) MockIPConfig {
}

// prefer not to listen on public interfaces if possible.
localIP := getLocalPrivateIP()
localIP := getLocalPrivateIPv4()
if localIP == nil {
localIP = net.IPv4(0, 0, 0, 0)
}
Expand Down Expand Up @@ -137,14 +137,14 @@ func fillBufferFromTemplate(adaptersAddresses *IPAdapterAddresses, sizePointer *
return nil
}

// getLocalPrivateIP returns one non loopback local private IP of the host.
func getLocalPrivateIP() net.IP {
// getLocalPrivateIPv4 returns one non loopback local private IPv4 of the host.
func getLocalPrivateIPv4() net.IP {
addrs, err := net.InterfaceAddrs()
if err != nil {
return nil
}
for _, addr := range addrs {
if ipnet, ok := addr.(*net.IPNet); ok && !ipnet.IP.IsLoopback() && ipnet.IP.IsPrivate() {
if ipnet, ok := addr.(*net.IPNet); ok && !ipnet.IP.IsLoopback() && ipnet.IP.IsPrivate() && ipnet.IP.To4() != nil {
CarlosNihelton marked this conversation as resolved.
Show resolved Hide resolved
return ipnet.IP
}
}
Expand Down
Loading