mirror of
				https://github.com/yggdrasil-network/yggstack.git
				synced 2025-11-04 00:15: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
						fc585b07b0
					
				
					 1 changed files with 6 additions and 4 deletions
				
			
		| 
						 | 
					@ -29,11 +29,13 @@ func NewNameResolver(stack *netstack.YggdrasilNetstack, nameserver string) *Name
 | 
				
			||||||
			if nameserver == "" {
 | 
								if nameserver == "" {
 | 
				
			||||||
				return nil, fmt.Errorf("no nameserver configured")
 | 
									return nil, fmt.Errorf("no nameserver configured")
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			address, port, found := strings.Cut(nameserver, ":")
 | 
								host, port, err := net.SplitHostPort(nameserver)
 | 
				
			||||||
			if !found {
 | 
								if err != nil {
 | 
				
			||||||
				port = "53"
 | 
									// 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)
 | 
								return stack.DialContext(ctx, network, address)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue