.net 3.5 Full Package

1 view
Skip to first unread message

Gigí Ruais

unread,
Aug 3, 2024, 5:02:01 PM8/3/24
to golffectoucon

Although the package provides access to low-level networkingprimitives, most clients will need only the basic interface providedby the Dial, Listen, and Accept functions and the associatedConn and Listener interfaces. The crypto/tls package usesthe same interfaces and similar Dial and Listen functions.

On Unix systems, the resolver has two options for resolving names.It can use a pure Go resolver that sends DNS requests directly to the serverslisted in /etc/resolv.conf, or it can use a cgo-based resolver that calls Clibrary routines such as getaddrinfo and getnameinfo.

By default the pure Go resolver is used, because a blocked DNS request consumesonly a goroutine, while a blocked C call consumes an operating system thread.When cgo is available, the cgo-based resolver is used instead under a variety ofconditions: on systems that do not let programs make direct DNS requests (OS X),when the LOCALDOMAIN environment variable is present (even if empty),when the RES_OPTIONS or HOSTALIASES environment variable is non-empty,when the ASR_CONFIG environment variable is non-empty (OpenBSD only),when /etc/resolv.conf or /etc/nsswitch.conf specify the use of features that theGo resolver does not implement, and when the name being looked up ends in .localor is an mDNS name.

A numeric netdns setting, as in GODEBUG=netdns=1, causes the resolverto print debugging information about its decisions.To force a particular resolver while also printing debugging information,join the two settings by a plus sign, as in GODEBUG=netdns=go+1.

The Go resolver will send an EDNS0 additional header with a DNS request,to signal a willingness to accept a larger DNS packet size.This can reportedly cause sporadic failures with the DNS server runby some modems and routers. Setting GODEBUG=netedns0=0 will disablesending the additional header.

ErrClosed is the error returned by an I/O call on a networkconnection that has already been closed, or that is closed byanother goroutine before the I/O is completed. This may be wrappedin another error, and should normally be tested usingerrors.Is(err, net.ErrClosed).

The returned names are validated to be properly formatted presentation-formatdomain names. If the response contains invalid names, those records are filteredout and an error will be returned alongside the remaining results, if any.

LookupCNAME returns the canonical name for the given host.Callers that do not care about the canonical name can callLookupHost or LookupIP directly; both take care of resolvingthe canonical name as part of the lookup.

A canonical name is the final name after following zeroor more CNAME records.LookupCNAME does not return an error if host does notcontain DNS "CNAME" records, as long as host resolves toaddress records.

Pipe creates a synchronous, in-memory, full duplexnetwork connection; both ends implement the Conn interface.Reads on one end are matched with writes on the other,copying data directly between the two; there is no internalbuffering.

For TCP and UDP networks, the address has the form "host:port".The host must be a literal IP address, or a host name that can beresolved to IP addresses.The port must be a literal port number or a service name.If the host is a literal IPv6 address it must be enclosed in squarebrackets, as in "[2001:db8::1]:80" or "[fe80::1%zone]:80".The zone specifies the scope of the literal IPv6 address as definedin RFC 4007.The functions JoinHostPort and SplitHostPort manipulate a pair ofhost and port in this form.When using TCP, and the host resolves to multiple IP addresses,Dial will try each IP address in order until one succeeds.

For IP networks, the network must be "ip", "ip4" or "ip6" followedby a colon and a literal protocol number or a protocol name, andthe address has the form "host". The host must be a literal IPaddress or a literal IPv6 address with zone.It depends on each operating system how the operating systembehaves with a non-well known protocol number such as "0" or "255".

The timeout includes name resolution, if required.When using TCP, and the host in the address parameter resolves tomultiple IP addresses, the timeout is spread over each consecutivedial, such that each is given an appropriate fraction of the timeto connect.

FileConn returns a copy of the network connection corresponding tothe open file f.It is the caller's responsibility to close f when finished.Closing c does not affect f, and closing f does not affect c.

The provided Context must be non-nil. If the context expires beforethe connection is complete, an error is returned. Once successfullyconnected, any expiration of the context will not affect theconnection.

When using TCP, and the host in the address parameter resolves to multiplenetwork addresses, any dial timeout (from d.Timeout or ctx) is spreadover each consecutive dial, such that each is given an appropriatefraction of the time to connect.For example, if a host has 4 IP addresses and the timeout is 1 minute,the connect to each single address will be given 15 seconds to completebefore trying the next one.

Note that in this documentation, referring to anIP address as an IPv4 address or an IPv6 addressis a semantic property of the address, not just thelength of the byte slice: a 16-byte slice can stillbe an IPv4 address.

The identification of global unicast addresses uses address typeidentification as defined in RFC 1122, RFC 4632 and RFC 4291 withthe exception of IPv4 directed broadcast addresses.It returns true even if ip is in IPv4 private address space orlocal IPv6 unicast address space.

If the host in the address parameter is not a literal IP address,ResolveIPAddr resolves the address to an address of IP end point.Otherwise, it parses the address as a literal IP address.The address parameter can use a host name, but this is notrecommended, because it will return at most one of the host name'sIP addresses.

ReadMsgIP reads a message from c, copying the payload into b andthe associated out-of-band data into oob. It returns the number ofbytes copied into b, the number of bytes copied into oob, the flagsthat were set on the message and the source address of the message.

FileListener returns a copy of the network listener correspondingto the open file f.It is the caller's responsibility to close ln when finished.Closing ln does not affect f, and closing f does not affect ln.

For TCP networks, if the host in the address parameter is empty ora literal unspecified IP address, Listen listens on all availableunicast and anycast IP addresses of the local system.To only use IPv4, use network "tcp4".The address can use a host name, but this is not recommended,because it will create a listener for at most one of the host's IPaddresses.If the port in the address parameter is empty or "0", as in"127.0.0.1:" or "[::1]:0", a port number is automatically chosen.The Addr method of Listener can be used to discover the chosenport.

The returned mail server names are validated to be properlyformatted presentation-format domain names. If the response containsinvalid names, those records are filtered out and an errorwill be returned alongside the remaining results, if any.

The returned name server names are validated to be properlyformatted presentation-format domain names. If the response containsinvalid names, those records are filtered out and an errorwill be returned alongside the remaining results, if any.

FilePacketConn returns a copy of the packet network connectioncorresponding to the open file f.It is the caller's responsibility to close f when finished.Closing c does not affect f, and closing f does not affect c.

For UDP and IP networks, if the host in the address parameter isempty or a literal unspecified IP address, ListenPacket listens onall available IP addresses of the local system except multicast IPaddresses.To only use IPv4, use network "udp4" or "ip4:proto".The address can use a host name, but this is not recommended,because it will create a listener for at most one of the host's IPaddresses.If the port in the address parameter is empty or "0", as in"127.0.0.1:" or "[::1]:0", a port number is automatically chosen.The LocalAddr method of PacketConn can be used to discover thechosen port.

LookupSRV tries to resolve an SRV query of the given service,protocol, and domain name. The proto is "tcp" or "udp".The returned records are sorted by priority and randomizedby weight within a priority.

LookupSRV constructs the DNS name to look up following RFC 2782.That is, it looks up _service._proto.name. To accommodate servicespublishing SRV records under non-standard names, if both serviceand proto are empty strings, LookupSRV looks up name directly.

The returned service names are validated to be properlyformatted presentation-format domain names. If the response containsinvalid names, those records are filtered out and an errorwill be returned alongside the remaining results, if any.

c80f0f1006
Reply all
Reply to author
Forward
0 new messages