mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 08:08:50 +00:00
Coalesce more.
This commit is contained in:
@@ -1,3 +1,12 @@
|
|||||||
|
package net
|
||||||
|
/*
|
||||||
|
Package net implements cross-platform Berkeley Sockets, DNS resolution and associated procedures.
|
||||||
|
For other protocols and their features, see subdirectories of this package.
|
||||||
|
|
||||||
|
This file collects structs, enums and settings applicable to the entire package in one handy place.
|
||||||
|
Platform-specific ones can be found in their respective `*_windows.odin` and similar files.
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Copyright 2022 Tetralux <tetraluxonpc@gmail.com>
|
Copyright 2022 Tetralux <tetraluxonpc@gmail.com>
|
||||||
Copyright 2022 Colin Davidson <colrdavidson@gmail.com>
|
Copyright 2022 Colin Davidson <colrdavidson@gmail.com>
|
||||||
@@ -10,15 +19,6 @@
|
|||||||
Jeroen van Rijn: Cross platform unification, code style, documentation
|
Jeroen van Rijn: Cross platform unification, code style, documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
Package net implements cross-platform Berkeley Sockets, DNS resolution and associated procedures.
|
|
||||||
For other protocols and their features, see subdirectories of this package.
|
|
||||||
|
|
||||||
This file collects structs, enums and settings applicable to the entire package in one handy place.
|
|
||||||
Platform-specific ones can be found in their respective `*_windows.odin` and similar files.
|
|
||||||
*/
|
|
||||||
package net
|
|
||||||
|
|
||||||
import "core:runtime"
|
import "core:runtime"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
|
package net
|
||||||
// +build darwin
|
// +build darwin
|
||||||
|
|
||||||
|
/*
|
||||||
|
Package net implements cross-platform Berkeley Sockets, DNS resolution and associated procedures.
|
||||||
|
For other protocols and their features, see subdirectories of this package.
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Copyright 2022 Tetralux <tetraluxonpc@gmail.com>
|
Copyright 2022 Tetralux <tetraluxonpc@gmail.com>
|
||||||
Copyright 2022 Colin Davidson <colrdavidson@gmail.com>
|
Copyright 2022 Colin Davidson <colrdavidson@gmail.com>
|
||||||
@@ -11,12 +18,6 @@
|
|||||||
Jeroen van Rijn: Cross platform unification, code style, documentation
|
Jeroen van Rijn: Cross platform unification, code style, documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
Package net implements cross-platform Berkeley Sockets, DNS resolution and associated procedures.
|
|
||||||
For other protocols and their features, see subdirectories of this package.
|
|
||||||
*/
|
|
||||||
package net
|
|
||||||
|
|
||||||
import "core:c"
|
import "core:c"
|
||||||
import "core:os"
|
import "core:os"
|
||||||
|
|
||||||
@@ -179,4 +180,4 @@ Socket_Option_Error :: enum c.int {
|
|||||||
Invalid_Option_For_Socket = c.int(os.ENOPROTOOPT),
|
Invalid_Option_For_Socket = c.int(os.ENOPROTOOPT),
|
||||||
Reset_When_Keepalive_Set = c.int(os.ENOTCONN),
|
Reset_When_Keepalive_Set = c.int(os.ENOTCONN),
|
||||||
Not_Socket = c.int(os.ENOTSOCK),
|
Not_Socket = c.int(os.ENOTSOCK),
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,11 @@
|
|||||||
|
package net
|
||||||
// +build linux
|
// +build linux
|
||||||
|
|
||||||
|
/*
|
||||||
|
Package net implements cross-platform Berkeley Sockets, DNS resolution and associated procedures.
|
||||||
|
For other protocols and their features, see subdirectories of this package.
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Copyright 2022 Tetralux <tetraluxonpc@gmail.com>
|
Copyright 2022 Tetralux <tetraluxonpc@gmail.com>
|
||||||
Copyright 2022 Colin Davidson <colrdavidson@gmail.com>
|
Copyright 2022 Colin Davidson <colrdavidson@gmail.com>
|
||||||
@@ -11,12 +18,6 @@
|
|||||||
Jeroen van Rijn: Cross platform unification, code style, documentation
|
Jeroen van Rijn: Cross platform unification, code style, documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
Package net implements cross-platform Berkeley Sockets, DNS resolution and associated procedures.
|
|
||||||
For other protocols and their features, see subdirectories of this package.
|
|
||||||
*/
|
|
||||||
package net
|
|
||||||
|
|
||||||
import "core:c"
|
import "core:c"
|
||||||
import "core:os"
|
import "core:os"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
|
package net
|
||||||
// +build windows
|
// +build windows
|
||||||
|
|
||||||
|
/*
|
||||||
|
Package net implements cross-platform Berkeley Sockets, DNS resolution and associated procedures.
|
||||||
|
For other protocols and their features, see subdirectories of this package.
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Copyright 2022 Tetralux <tetraluxonpc@gmail.com>
|
Copyright 2022 Tetralux <tetraluxonpc@gmail.com>
|
||||||
Copyright 2022 Colin Davidson <colrdavidson@gmail.com>
|
Copyright 2022 Colin Davidson <colrdavidson@gmail.com>
|
||||||
@@ -11,12 +18,6 @@
|
|||||||
Jeroen van Rijn: Cross platform unification, code style, documentation
|
Jeroen van Rijn: Cross platform unification, code style, documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
Package net implements cross-platform Berkeley Sockets, DNS resolution and associated procedures.
|
|
||||||
For other protocols and their features, see subdirectories of this package.
|
|
||||||
*/
|
|
||||||
package net
|
|
||||||
|
|
||||||
import "core:c"
|
import "core:c"
|
||||||
import win "core:sys/windows"
|
import win "core:sys/windows"
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,15 @@ package net
|
|||||||
|
|
||||||
import "core:strings"
|
import "core:strings"
|
||||||
|
|
||||||
|
MAX_INTERFACE_ENUMERATION_TRIES :: 3
|
||||||
|
|
||||||
|
/*
|
||||||
|
`enumerate_interfaces` retrieves a list of network interfaces with their associated properties.
|
||||||
|
*/
|
||||||
|
enumerate_interfaces :: proc(allocator := context.allocator) -> (interfaces: []Network_Interface, err: Network_Error) {
|
||||||
|
return _enumerate_interfaces(allocator)
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
`destroy_interfaces` cleans up a list of network interfaces retrieved by e.g. `enumerate_interfaces`.
|
`destroy_interfaces` cleans up a list of network interfaces retrieved by e.g. `enumerate_interfaces`.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -17,7 +17,16 @@ package net
|
|||||||
Colin Davidson: Linux platform code, OSX platform code, Odin-native DNS resolver
|
Colin Davidson: Linux platform code, OSX platform code, Odin-native DNS resolver
|
||||||
Jeroen van Rijn: Cross platform unification, code style, documentation
|
Jeroen van Rijn: Cross platform unification, code style, documentation
|
||||||
|
|
||||||
|
|
||||||
TODO: Implement. Can probably use the (current) Linux implementation,
|
|
||||||
which will itself be switched over to talking to the kernel via NETLINK protocol once we have raw sockets.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@(private)
|
||||||
|
_enumerate_interfaces :: proc(allocator := context.allocator) -> (interfaces: []Network_Interface, err: Network_Error) {
|
||||||
|
context.allocator = allocator
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: Implement. Can probably use the (current) Linux implementation,
|
||||||
|
// which will itself be switched over to talking to the kernel via NETLINK protocol
|
||||||
|
// once we have raw sockets.
|
||||||
|
|
||||||
|
unimplemented()
|
||||||
|
}
|
||||||
@@ -24,10 +24,8 @@ package net
|
|||||||
import "core:os"
|
import "core:os"
|
||||||
import "core:strings"
|
import "core:strings"
|
||||||
|
|
||||||
/*
|
@(private)
|
||||||
`enumerate_interfaces` retrieves a list of network interfaces with their associated properties.
|
_enumerate_interfaces :: proc(allocator := context.allocator) -> (interfaces: []Network_Interface, err: Network_Error) {
|
||||||
*/
|
|
||||||
enumerate_interfaces :: proc(allocator := context.allocator) -> (interfaces: []Network_Interface, err: Network_Error) {
|
|
||||||
context.allocator = allocator
|
context.allocator = allocator
|
||||||
|
|
||||||
head: ^os.ifaddrs
|
head: ^os.ifaddrs
|
||||||
@@ -40,7 +38,6 @@ enumerate_interfaces :: proc(allocator := context.allocator) -> (interfaces: []N
|
|||||||
Unlike Windows, *nix regrettably doesn't return all it knows about an interface in one big struct.
|
Unlike Windows, *nix regrettably doesn't return all it knows about an interface in one big struct.
|
||||||
We're going to have to iterate over a list and coalesce information as we go.
|
We're going to have to iterate over a list and coalesce information as we go.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ifaces: map[string]^Network_Interface
|
ifaces: map[string]^Network_Interface
|
||||||
defer delete(ifaces)
|
defer delete(ifaces)
|
||||||
|
|
||||||
@@ -67,7 +64,7 @@ enumerate_interfaces :: proc(allocator := context.allocator) -> (interfaces: []N
|
|||||||
|
|
||||||
case os.AF_PACKET:
|
case os.AF_PACKET:
|
||||||
/*
|
/*
|
||||||
For some obscure reason the 64-bit `getifaddrs` calls returns a pointer to a
|
For some obscure reason the 64-bit `getifaddrs` call returns a pointer to a
|
||||||
32-bit `RTNL_LINK_STATS` structure, which of course means that tx/rx byte count
|
32-bit `RTNL_LINK_STATS` structure, which of course means that tx/rx byte count
|
||||||
is truncated beyond usefulness.
|
is truncated beyond usefulness.
|
||||||
|
|
||||||
@@ -123,7 +120,6 @@ enumerate_interfaces :: proc(allocator := context.allocator) -> (interfaces: []N
|
|||||||
if .LOOPBACK in ifaddr.flags {
|
if .LOOPBACK in ifaddr.flags {
|
||||||
state |= {.Loopback}
|
state |= {.Loopback}
|
||||||
}
|
}
|
||||||
|
|
||||||
iface.link.state = state
|
iface.link.state = state
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,6 +136,5 @@ enumerate_interfaces :: proc(allocator := context.allocator) -> (interfaces: []N
|
|||||||
append(&_interfaces, iface^)
|
append(&_interfaces, iface^)
|
||||||
free(iface)
|
free(iface)
|
||||||
}
|
}
|
||||||
|
|
||||||
return _interfaces[:], {}
|
return _interfaces[:], {}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,11 @@
|
|||||||
|
package net
|
||||||
//+build windows
|
//+build windows
|
||||||
|
|
||||||
|
/*
|
||||||
|
Package net implements cross-platform Berkeley Sockets, DNS resolution and associated procedures.
|
||||||
|
For other protocols and their features, see subdirectories of this package.
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Copyright 2022 Tetralux <tetraluxonpc@gmail.com>
|
Copyright 2022 Tetralux <tetraluxonpc@gmail.com>
|
||||||
Copyright 2022 Colin Davidson <colrdavidson@gmail.com>
|
Copyright 2022 Colin Davidson <colrdavidson@gmail.com>
|
||||||
@@ -11,28 +18,17 @@
|
|||||||
Jeroen van Rijn: Cross platform unification, code style, documentation
|
Jeroen van Rijn: Cross platform unification, code style, documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
Package net implements cross-platform Berkeley Sockets, DNS resolution and associated procedures.
|
|
||||||
For other protocols and their features, see subdirectories of this package.
|
|
||||||
*/
|
|
||||||
package net
|
|
||||||
|
|
||||||
import sys "core:sys/windows"
|
import sys "core:sys/windows"
|
||||||
import strings "core:strings"
|
import strings "core:strings"
|
||||||
|
|
||||||
MAX_INTERFACE_ENUMERATION_TRIES :: 3
|
_enumerate_interfaces :: proc(allocator := context.allocator) -> (interfaces: []Network_Interface, err: Network_Error) {
|
||||||
|
|
||||||
/*
|
|
||||||
`enumerate_interfaces` retrieves a list of network interfaces with their associated properties.
|
|
||||||
*/
|
|
||||||
enumerate_interfaces :: proc(allocator := context.allocator) -> (interfaces: []Network_Interface, err: Network_Error) {
|
|
||||||
context.allocator = allocator
|
context.allocator = allocator
|
||||||
|
|
||||||
buf: []u8
|
buf: []u8
|
||||||
defer delete(buf)
|
defer delete(buf)
|
||||||
buf_size: u32
|
|
||||||
|
|
||||||
res: u32
|
buf_size: u32
|
||||||
|
res: u32
|
||||||
|
|
||||||
gaa: for _ in 1..=MAX_INTERFACE_ENUMERATION_TRIES {
|
gaa: for _ in 1..=MAX_INTERFACE_ENUMERATION_TRIES {
|
||||||
res = sys.get_adapters_addresses(
|
res = sys.get_adapters_addresses(
|
||||||
@@ -178,4 +174,4 @@ parse_socket_address :: proc(addr_in: sys.SOCKET_ADDRESS) -> (addr: Endpoint) {
|
|||||||
case: return // Empty or invalid address type
|
case: return // Empty or invalid address type
|
||||||
}
|
}
|
||||||
unreachable()
|
unreachable()
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user