Skip to content

Commit

Permalink
force resolve host to use piv4 (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
arriven authored Mar 9, 2022
1 parent 565374e commit 905be7d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/packetgen/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,16 @@ func LocalIP() string {

// ResolveHost function gets a string and returns the ip address
func ResolveHost(host string) (string, error) {
addrs, err := net.LookupHost(host)
addrs, err := net.LookupIP(host)
if err != nil {
return "", err
}

// I assume net.LookupHost already handles that but just to be sure
if len(addrs) == 0 {
return "", fmt.Errorf("no addrs found for host %v", host)
for _, addr := range addrs {
if addr.To4() != nil {
return addr.String(), nil
}
}

return addrs[0], nil
return "", fmt.Errorf("no addrs found for host %v", host)
}
4 changes: 2 additions & 2 deletions testconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
{
"type": "packetgen",
"args": {
"host": "{{ resolve_host \"google.com\" }}",
"host": "{{ resolve_host \"localhost\" }}",
"port": "{{ random_port }}",
"packet": {
"payload": "test:blah",
Expand All @@ -70,7 +70,7 @@
},
"ip": {
"src_ip": "{{ local_ip }}",
"dst_ip": "{{ resolve_host \"google.com\" }}"
"dst_ip": "{{ resolve_host \"localhost\" }}"
},
"tcp": {
"src_port": "{{ random_port }}",
Expand Down

0 comments on commit 905be7d

Please sign in to comment.