Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ type Dialer struct {
// See Go "net" package Dial() for more information.
//
// Note: Tinygo Dial supports a subset of networks supported by Go Dial,
// specifically: "tcp", "tcp4", "udp", and "udp4". IP and unix networks are
// not supported.
// specifically: "tcp", "tcp4", "tcp6", "udp", "udp4", and "udp6". IP and unix
// networks are not supported. IPv6 addresses are supported, but when dialing a
// host name the resolver prefers an IPv4 (A) address and only falls back to
// IPv6 (AAAA), so the "4"/"6" suffix does not force the address family for name
// resolution.
func Dial(network, address string) (Conn, error) {
var d Dialer
return d.Dial(network, address)
Expand Down Expand Up @@ -150,13 +153,13 @@ func (d *Dialer) DialContext(ctx context.Context, network, address string) (Conn
// TINYGO: Ignoring context

switch network {
case "tcp", "tcp4":
case "tcp", "tcp4", "tcp6":
raddr, err := ResolveTCPAddr(network, address)
if err != nil {
return nil, err
}
return DialTCP(network, nil, raddr)
case "udp", "udp4":
case "udp", "udp4", "udp6":
raddr, err := ResolveUDPAddr(network, address)
if err != nil {
return nil, err
Expand Down Expand Up @@ -264,12 +267,12 @@ func parseNetwork(ctx context.Context, network string, needsProto bool) (afnet s
// See Go "net" package Listen() for more information.
//
// Note: Tinygo Listen supports a subset of networks supported by Go Listen,
// specifically: "tcp", "tcp4". "tcp6" and unix networks are not supported.
// specifically: "tcp", "tcp4", and "tcp6". unix networks are not supported.
func Listen(network, address string) (Listener, error) {

// println("Listen", address)
switch network {
case "tcp", "tcp4":
case "tcp", "tcp4", "tcp6":
default:
return nil, fmt.Errorf("Network %s not supported", network)
}
Expand Down
39 changes: 39 additions & 0 deletions lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,42 @@ import (
func LookupPort(network, service string) (port int, err error) {
return 0, errors.New("net:LookupPort not implemented")
}

// DNSError represents a DNS lookup error.
//
// TINYGO: Trimmed copy of the standard library's net.DNSError so that name
// resolution errors keep a familiar, type-assertable shape.
type DNSError struct {
UnwrapErr error // error returned by the [DNSError.Unwrap] method, might be nil
Err string // description of the error
Name string // name looked for
Server string // server used
IsTimeout bool // if true, timed out; not all timeouts set this
IsTemporary bool // if true, error is temporary; not all errors set this

// IsNotFound is set to true when the requested name does not
// contain any records of the requested type (data not found),
// or the name itself was not found (NXDOMAIN).
IsNotFound bool
}

// Unwrap returns e.UnwrapErr.
func (e *DNSError) Unwrap() error { return e.UnwrapErr }

func (e *DNSError) Error() string {
if e == nil {
return "<nil>"
}
s := "lookup " + e.Name
if e.Server != "" {
s += " on " + e.Server
}
s += ": " + e.Err
return s
}

// Timeout reports whether the DNS lookup is known to have timed out.
func (e *DNSError) Timeout() bool { return e.IsTimeout }

// Temporary reports whether the DNS error is known to be temporary.
func (e *DNSError) Temporary() bool { return e.IsTimeout || e.IsTemporary }
11 changes: 11 additions & 0 deletions netdev.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

const (
_AF_INET = 0x2
_AF_INET6 = 0xa
_SOCK_STREAM = 0x1
_SOCK_DGRAM = 0x2
_SOL_SOCKET = 0x1
Expand All @@ -36,6 +37,16 @@ func useNetdev(dev netdever) {
netdev = dev
}

// socketFamily returns the address family (_AF_INET or _AF_INET6) to use for a
// socket targeting ip. A nil/zero-length IP (e.g. a wildcard listen address)
// defaults to IPv4.
func socketFamily(ip IP) int {
if len(ip) == 16 && ip.To4() == nil {
return _AF_INET6
}
return _AF_INET
}

// netdever is TinyGo's OSI L3/L4 network/transport layer interface. Network
// drivers implement the netdever interface, providing a common network L3/L4
// interface to TinyGo's "net" package. net.Conn implementations (TCPConn,
Expand Down
Loading