package net
import (
)
var onceReadProtocols sync.Once
func () {
, := open("/etc/protocols")
if != nil {
return
}
defer .close()
for , := .readLine(); ; , = .readLine() {
if := bytealg.IndexByteString(, '#'); >= 0 {
= [0:]
}
:= getFields()
if len() < 2 {
continue
}
if , , := dtoi([1]); {
if , := protocols[[0]]; ! {
protocols[[0]] =
}
for , := range [2:] {
if , := protocols[]; ! {
protocols[] =
}
}
}
}
}
func ( context.Context, string) (int, error) {
onceReadProtocols.Do(readProtocols)
return lookupProtocolMap()
}
func ( *Resolver) ( context.Context, , string) (Conn, error) {
var Conn
var error
if != nil && .Dial != nil {
, = .Dial(, , )
} else {
var Dialer
, = .DialContext(, , )
}
if != nil {
return nil, mapErr()
}
return , nil
}
func ( *Resolver) ( context.Context, string) ( []string, error) {
:= systemConf().hostLookupOrder(, )
if !.preferGo() && == hostLookupCgo {
if , , := cgoLookupHost(, ); {
return ,
}
= hostLookupFilesDNS
}
return .goLookupHostOrder(, , )
}
func ( *Resolver) ( context.Context, , string) ( []IPAddr, error) {
if .preferGo() {
return .goLookupIP(, )
}
:= systemConf().hostLookupOrder(, )
if == hostLookupCgo {
if , , := cgoLookupIP(, , ); {
return ,
}
= hostLookupFilesDNS
}
, , := .goLookupIPCNAMEOrder(, , )
return ,
}
func ( *Resolver) ( context.Context, , string) (int, error) {
if !.preferGo() && systemConf().canUseCgo() {
if , , := cgoLookupPort(, , ); {
if != nil {
if , := goLookupPort(, ); == nil {
return , nil
}
}
return ,
}
}
return goLookupPort(, )
}
func ( *Resolver) ( context.Context, string) (string, error) {
if !.preferGo() && systemConf().canUseCgo() {
if , , := cgoLookupCNAME(, ); {
return ,
}
}
return .goLookupCNAME(, )
}
func ( *Resolver) ( context.Context, , , string) (string, []*SRV, error) {
var string
if == "" && == "" {
=
} else {
= "_" + + "._" + + "." +
}
, , := .lookup(, , dnsmessage.TypeSRV)
if != nil {
return "", nil,
}
var []*SRV
var dnsmessage.Name
for {
, := .AnswerHeader()
if == dnsmessage.ErrSectionDone {
break
}
if != nil {
return "", nil, &DNSError{
Err: "cannot unmarshal DNS message",
Name: ,
Server: ,
}
}
if .Type != dnsmessage.TypeSRV {
if := .SkipAnswer(); != nil {
return "", nil, &DNSError{
Err: "cannot unmarshal DNS message",
Name: ,
Server: ,
}
}
continue
}
if .Length == 0 && .Name.Length != 0 {
= .Name
}
, := .SRVResource()
if != nil {
return "", nil, &DNSError{
Err: "cannot unmarshal DNS message",
Name: ,
Server: ,
}
}
= append(, &SRV{Target: .Target.String(), Port: .Port, Priority: .Priority, Weight: .Weight})
}
byPriorityWeight().sort()
return .String(), , nil
}
func ( *Resolver) ( context.Context, string) ([]*MX, error) {
, , := .lookup(, , dnsmessage.TypeMX)
if != nil {
return nil,
}
var []*MX
for {
, := .AnswerHeader()
if == dnsmessage.ErrSectionDone {
break
}
if != nil {
return nil, &DNSError{
Err: "cannot unmarshal DNS message",
Name: ,
Server: ,
}
}
if .Type != dnsmessage.TypeMX {
if := .SkipAnswer(); != nil {
return nil, &DNSError{
Err: "cannot unmarshal DNS message",
Name: ,
Server: ,
}
}
continue
}
, := .MXResource()
if != nil {
return nil, &DNSError{
Err: "cannot unmarshal DNS message",
Name: ,
Server: ,
}
}
= append(, &MX{Host: .MX.String(), Pref: .Pref})
}
byPref().sort()
return , nil
}
func ( *Resolver) ( context.Context, string) ([]*NS, error) {
, , := .lookup(, , dnsmessage.TypeNS)
if != nil {
return nil,
}
var []*NS
for {
, := .AnswerHeader()
if == dnsmessage.ErrSectionDone {
break
}
if != nil {
return nil, &DNSError{
Err: "cannot unmarshal DNS message",
Name: ,
Server: ,
}
}
if .Type != dnsmessage.TypeNS {
if := .SkipAnswer(); != nil {
return nil, &DNSError{
Err: "cannot unmarshal DNS message",
Name: ,
Server: ,
}
}
continue
}
, := .NSResource()
if != nil {
return nil, &DNSError{
Err: "cannot unmarshal DNS message",
Name: ,
Server: ,
}
}
= append(, &NS{Host: .NS.String()})
}
return , nil
}
func ( *Resolver) ( context.Context, string) ([]string, error) {
, , := .lookup(, , dnsmessage.TypeTXT)
if != nil {
return nil,
}
var []string
for {
, := .AnswerHeader()
if == dnsmessage.ErrSectionDone {
break
}
if != nil {
return nil, &DNSError{
Err: "cannot unmarshal DNS message",
Name: ,
Server: ,
}
}
if .Type != dnsmessage.TypeTXT {
if := .SkipAnswer(); != nil {
return nil, &DNSError{
Err: "cannot unmarshal DNS message",
Name: ,
Server: ,
}
}
continue
}
, := .TXTResource()
if != nil {
return nil, &DNSError{
Err: "cannot unmarshal DNS message",
Name: ,
Server: ,
}
}
:= 0
for , := range .TXT {
+= len()
}
:= make([]byte, 0, )
for , := range .TXT {
= append(, ...)
}
if len() == 0 {
= make([]string, 0, 1)
}
= append(, string())
}
return , nil
}
func ( *Resolver) ( context.Context, string) ([]string, error) {
if !.preferGo() && systemConf().canUseCgo() {
if , , := cgoLookupPTR(, ); {
return ,
}
}
return .goLookupPTR(, )
}
func () int {
var syscall.Rlimit
if := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &); != nil {
return 500
}
:= int(.Cur)
if > 500 {
= 500
} else if > 30 {
-= 30
}
return
}