Skip to content

Commit

Permalink
Merge pull request #1495 from AkihiroSuda/fix-1488
Browse files Browse the repository at this point in the history
Use net.JoinHostPort
  • Loading branch information
AkihiroSuda authored Apr 15, 2023
2 parents aedd0c1 + 912c510 commit ac7f7d7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions pkg/hostagent/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"net"
"runtime"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -318,7 +319,7 @@ func (h *Handler) handleDefault(w dns.ResponseWriter, req *dns.Msg) {
logrus.Tracef("handleDefault for %v", req)
for _, client := range h.clients {
for _, srv := range h.clientConfig.Servers {
addr := fmt.Sprintf("%s:%s", srv, h.clientConfig.Port)
addr := net.JoinHostPort(srv, h.clientConfig.Port)
reply, _, err := client.Exchange(req, addr)
if err != nil {
logrus.WithError(err).Debugf("handleDefault failed to perform a synchronous query with upstream [%v]", addr)
Expand Down Expand Up @@ -378,9 +379,9 @@ func listenAndServe(network Network, opts ServerOptions) (*dns.Server, error) {
// always enable reply truncate for UDP
if network == UDP {
opts.HandlerOptions.TruncateReply = true
addr = fmt.Sprintf("%s:%d", opts.Address, opts.UDPPort)
addr = net.JoinHostPort(opts.Address, strconv.Itoa(opts.UDPPort))
} else {
addr = fmt.Sprintf("%s:%d", opts.Address, opts.TCPPort)
addr = net.JoinHostPort(opts.Address, strconv.Itoa(opts.TCPPort))
}
h, err := NewHandler(opts.HandlerOptions)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/networks/gvisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func StartGVisorNetstack(ctx context.Context, gVisorOpts *GVisorNetstackOpts) {
SlirpIPAddress: opts.MacAddress,
},
Forwards: map[string]string{
fmt.Sprintf("127.0.0.1:%d", opts.SSHLocalPort): fmt.Sprintf("%s:22", SlirpIPAddress),
fmt.Sprintf("127.0.0.1:%d", opts.SSHLocalPort): net.JoinHostPort(SlirpIPAddress, "22"),
},
DNS: []types.Zone{},
DNSSearchDomains: searchDomains(),
Expand Down
5 changes: 3 additions & 2 deletions pkg/osutil/dns_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package osutil

import (
"fmt"
"net"
"strings"

"github.com/lima-vm/lima/pkg/sysprof"
Expand Down Expand Up @@ -31,9 +32,9 @@ func proxyURL(proxy string, port interface{}) string {
proxy = "http://" + proxy
}
if portNumber, ok := port.(float64); ok && portNumber != 0 {
proxy = fmt.Sprintf("%s:%.0f", proxy, portNumber)
proxy = net.JoinHostPort(proxy, fmt.Sprintf("%.0f", portNumber))
} else if portString, ok := port.(string); ok && portString != "" {
proxy = fmt.Sprintf("%s:%s", proxy, portString)
proxy = net.JoinHostPort(proxy, portString)
}
return proxy
}
Expand Down

0 comments on commit ac7f7d7

Please sign in to comment.