mirror of
				https://github.com/yggdrasil-network/yggstack.git
				synced 2025-11-04 08:25:06 +03:00 
			
		
		
		
	use proper stdlib functions for splitting host and port
replace use of strings.Cut() with net.SplitHostPort() as it does not handle every case we need it to. e.g. "[1234::1%lan0]"
This commit is contained in:
		
							parent
							
								
									6e427fefec
								
							
						
					
					
						commit
						feaf5ca550
					
				
					 1 changed files with 6 additions and 4 deletions
				
			
		| 
						 | 
				
			
			@ -29,11 +29,13 @@ func NewNameResolver(stack *netstack.YggdrasilNetstack, nameserver string) *Name
 | 
			
		|||
			if nameserver == "" {
 | 
			
		||||
				return nil, fmt.Errorf("no nameserver configured")
 | 
			
		||||
			}
 | 
			
		||||
			address, port, found := strings.Cut(nameserver, ":")
 | 
			
		||||
			if !found {
 | 
			
		||||
				port = "53"
 | 
			
		||||
			host, port, err := net.SplitHostPort(nameserver)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				// default to dns service when no port given.
 | 
			
		||||
				port = "dns"
 | 
			
		||||
				host = nameserver
 | 
			
		||||
			}
 | 
			
		||||
			address = net.JoinHostPort(nameserver, port)
 | 
			
		||||
			address = net.JoinHostPort(host, port)
 | 
			
		||||
			return stack.DialContext(ctx, network, address)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue