Ian Lance Taylor | 22b955c | 2016-07-22 18:15:38 +0000 | [diff] [blame] | 1 | // Copyright 2015 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
Ian Lance Taylor | c5b21c3 | 2021-07-30 14:28:58 -0700 | [diff] [blame] | 5 | //go:build !js && !plan9 && !windows |
Ian Lance Taylor | 5a8ea16 | 2020-01-02 15:05:27 -0800 | [diff] [blame] | 6 | // +build !js,!plan9,!windows |
Ian Lance Taylor | 22b955c | 2016-07-22 18:15:38 +0000 | [diff] [blame] | 7 | |
| 8 | package net |
| 9 | |
| 10 | // forceGoDNS forces the resolver configuration to use the pure Go resolver |
| 11 | // and returns a fixup function to restore the old settings. |
| 12 | func forceGoDNS() func() { |
| 13 | c := systemConf() |
| 14 | oldGo := c.netGo |
| 15 | oldCgo := c.netCgo |
| 16 | fixup := func() { |
| 17 | c.netGo = oldGo |
| 18 | c.netCgo = oldCgo |
| 19 | } |
| 20 | c.netGo = true |
| 21 | c.netCgo = false |
| 22 | return fixup |
| 23 | } |
| 24 | |
| 25 | // forceCgoDNS forces the resolver configuration to use the cgo resolver |
| 26 | // and returns a fixup function to restore the old settings. |
| 27 | // (On non-Unix systems forceCgoDNS returns nil.) |
| 28 | func forceCgoDNS() func() { |
| 29 | c := systemConf() |
| 30 | oldGo := c.netGo |
| 31 | oldCgo := c.netCgo |
| 32 | fixup := func() { |
| 33 | c.netGo = oldGo |
| 34 | c.netCgo = oldCgo |
| 35 | } |
| 36 | c.netGo = false |
| 37 | c.netCgo = true |
| 38 | return fixup |
| 39 | } |