Skip to content
Merged
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 @@ -101,8 +101,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 @@ -157,13 +160,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 @@ -271,12 +274,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
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