mirror of
https://github.com/tinygo-org/net.git
synced 2026-09-10 14:39:27 +00:00
interface: add stubs for wasm builds
This commit is contained in:
committed by
Ron Evans
parent
902c8d1203
commit
e75c5f0526
+36
-10
@@ -37,18 +37,20 @@ type Interface struct {
|
|||||||
|
|
||||||
// Addrs returns a list of unicast interface addresses for a specific
|
// Addrs returns a list of unicast interface addresses for a specific
|
||||||
// interface.
|
// interface.
|
||||||
//
|
|
||||||
// TINYGO: not implemented; netdev exposes no per-interface address list.
|
|
||||||
func (ifi *Interface) Addrs() ([]Addr, error) {
|
func (ifi *Interface) Addrs() ([]Addr, error) {
|
||||||
return nil, errors.New("Interface.Addrs not implemented")
|
if ifi == nil {
|
||||||
|
return nil, errInvalidInterface
|
||||||
|
}
|
||||||
|
return interfaceAddrTable(ifi)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MulticastAddrs returns a list of multicast, joined group addresses
|
// MulticastAddrs returns a list of multicast, joined group addresses
|
||||||
// for a specific interface.
|
// for a specific interface.
|
||||||
//
|
|
||||||
// TINYGO: not implemented; netdev exposes no per-interface address list.
|
|
||||||
func (ifi *Interface) MulticastAddrs() ([]Addr, error) {
|
func (ifi *Interface) MulticastAddrs() ([]Addr, error) {
|
||||||
return nil, errors.New("Interface.MulticastAddrs not implemented")
|
if ifi == nil {
|
||||||
|
return nil, errInvalidInterface
|
||||||
|
}
|
||||||
|
return interfaceMulticastAddrTable(ifi)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Flags uint
|
type Flags uint
|
||||||
@@ -89,7 +91,7 @@ func (f Flags) String() string {
|
|||||||
|
|
||||||
// Interfaces returns a list of the system's network interfaces.
|
// Interfaces returns a list of the system's network interfaces.
|
||||||
func Interfaces() ([]Interface, error) {
|
func Interfaces() ([]Interface, error) {
|
||||||
return nil, errors.New("Interfaces not implemented")
|
return interfaceTable(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// InterfaceAddrs returns a list of the system's unicast interface
|
// InterfaceAddrs returns a list of the system's unicast interface
|
||||||
@@ -98,7 +100,7 @@ func Interfaces() ([]Interface, error) {
|
|||||||
// The returned list does not identify the associated interface; use
|
// The returned list does not identify the associated interface; use
|
||||||
// Interfaces and [Interface.Addrs] for more detail.
|
// Interfaces and [Interface.Addrs] for more detail.
|
||||||
func InterfaceAddrs() ([]Addr, error) {
|
func InterfaceAddrs() ([]Addr, error) {
|
||||||
return nil, errors.New("InterfaceAddrs not implemented")
|
return interfaceAddrTable(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// InterfaceByIndex returns the interface specified by index.
|
// InterfaceByIndex returns the interface specified by index.
|
||||||
@@ -107,10 +109,34 @@ func InterfaceAddrs() ([]Addr, error) {
|
|||||||
// sharing the logical data link; for more precision use
|
// sharing the logical data link; for more precision use
|
||||||
// [InterfaceByName].
|
// [InterfaceByName].
|
||||||
func InterfaceByIndex(index int) (*Interface, error) {
|
func InterfaceByIndex(index int) (*Interface, error) {
|
||||||
return nil, errors.New("InterfaceByIndex not implemented")
|
if index <= 0 {
|
||||||
|
return nil, errInvalidInterfaceIndex
|
||||||
|
}
|
||||||
|
ift, err := interfaceTable(index)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for i := range ift {
|
||||||
|
if index == ift[i].Index {
|
||||||
|
return &ift[i], nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, errNoSuchInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
// InterfaceByName returns the interface specified by name.
|
// InterfaceByName returns the interface specified by name.
|
||||||
func InterfaceByName(name string) (*Interface, error) {
|
func InterfaceByName(name string) (*Interface, error) {
|
||||||
return nil, errors.New("InterfaceByName not implemented")
|
if name == "" {
|
||||||
|
return nil, errInvalidInterfaceName
|
||||||
|
}
|
||||||
|
ift, err := interfaceTable(0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for i := range ift {
|
||||||
|
if name == ift[i].Name {
|
||||||
|
return &ift[i], nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, errNoSuchInterface
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
// TINYGO: The following is copied and modified from Go 1.26.2 official implementation.
|
||||||
|
|
||||||
|
// Copyright 2011 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
//go:build !(js || wasip1)
|
||||||
|
|
||||||
|
package net
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TINYGO: not implemented; netdev exposes neither an interface table nor a
|
||||||
|
// per-interface address list.
|
||||||
|
|
||||||
|
func interfaceTable(ifindex int) ([]Interface, error) {
|
||||||
|
return nil, errors.New("Interfaces not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func interfaceAddrTable(ifi *Interface) ([]Addr, error) {
|
||||||
|
return nil, errors.New("InterfaceAddrs not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func interfaceMulticastAddrTable(ifi *Interface) ([]Addr, error) {
|
||||||
|
return nil, errors.New("Interface.MulticastAddrs not implemented")
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
// TINYGO: The following is copied and modified from Go 1.26.2 official implementation.
|
||||||
|
|
||||||
|
// Copyright 2011 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
//go:build js || wasip1
|
||||||
|
|
||||||
|
package net
|
||||||
|
|
||||||
|
// TINYGO: mirrors upstream net/interface_stub.go. These platforms have no
|
||||||
|
// interface table at all, so enumeration yields an empty list and no error,
|
||||||
|
// rather than failing. Callers that merely enumerate then see zero interfaces
|
||||||
|
// instead of a hard error; InterfaceByIndex/InterfaceByName still report
|
||||||
|
// errNoSuchInterface, since an empty table contains nothing.
|
||||||
|
|
||||||
|
func interfaceTable(ifindex int) ([]Interface, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func interfaceAddrTable(ifi *Interface) ([]Addr, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func interfaceMulticastAddrTable(ifi *Interface) ([]Addr, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user