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

Moved getLocalIPv4Addresses() to agent_util.go in mitre/gocat to prev… #353

Merged
merged 2 commits into from
Mar 9, 2021
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
30 changes: 1 addition & 29 deletions gocat-extensions/proxy/proxy_receiver_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func sendResponseToClient(data []byte, headers map[string][]string, writer http.
// Port must be set for the HTTP receiver before calling this method.
func (h *HttpReceiver) getReachableUrls() ([]string, error) {
var urlList []string
ipAddrs, err := h.getLocalIPv4Addresses()
ipAddrs, err := GetLocalIPv4Addresses()
if err != nil {
return nil, err
}
Expand All @@ -319,34 +319,6 @@ func (h *HttpReceiver) getReachableUrls() ([]string, error) {
return urlList, nil
}

// Return list of local IPv4 addresses for this machine (exclude loopback and unspecified addresses)
func (h *HttpReceiver) getLocalIPv4Addresses() ([]string, error) {
var localIpList []string
interfaces, err := net.Interfaces()
if err != nil {
return nil, err
}
for _, iface := range interfaces {
addresses, err := iface.Addrs()
if err != nil {
return nil, err
}
for _, addr := range addresses {
var ipAddr net.IP
switch v:= addr.(type) {
case *net.IPNet:
ipAddr = v.IP
case *net.IPAddr:
ipAddr = v.IP
}
if ipAddr != nil && !ipAddr.IsLoopback() && !ipAddr.IsUnspecified() && (ipAddr.To4() != nil) {
localIpList = append(localIpList, ipAddr.String())
}
}
}
return localIpList, nil
}

// Helper method for initializing the receiver port.
func (h *HttpReceiver) initializeReceiverPort() error {
// Try 5 random ports before giving up.
Expand Down