forked from crystal-lang/crystal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement IPv6 scoped addresses (RFC4007)
In order to translate interface names in such scoped addresses the required `LibC` binding to `if_nametoindex()` has been added. This method obviously only works for interfaces (devices) that are actually present on the system. The binding for the reverse operation `if_indextoname()` has also been added, although its usage is a bit more cumbersome due to LibC::Char* buffer handling. The necessary buffer length has been placed into the constant `LibC::IF_NAMESIZE`, which appears to be `16u8` on unix-like systems and `257u16` on windows. This could potentially be reworked via a preprocessor block at compile-time as indicated by some folks over on discord, I currently do not know how to achieve that though. Scoped identifiers are only valid for link-local (`fe80::`) addresses, e.g. `fe80::1%eth0` References: - https://datatracker.ietf.org/doc/html/rfc4007 TODO (to be resolved during the PR discussion): - discuss the preprocessor option for retrieving the constant value `IF_NAMESIZE` (No clue how do that, haven't found any event of this constant ever changing in the past, might not be worth the trouble?) - clarify whether scope_id parsing should raise `ArgumentError` or `Socket::Error` - clarify whether `Socket::Address` spec `#scope_id` `looks up interface name by index` should remain in the `Socket::Address` spec, since it only calls the `LibC` binding I'm happy to adjust/rebase if needed based on feedback or other merges into `master` in the mean time.
- Loading branch information
Showing
20 changed files
with
242 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require "../netinet/in" | ||
require "../stdint" | ||
|
||
lib LibC | ||
IF_NAMESIZE = 16u8 | ||
|
||
fun if_nametoindex(ifname : Char*) : UInt | ||
fun if_indextoname(ifindex : UInt, ifname : LibC::Char*) : LibC::Char* | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require "../netinet/in" | ||
require "../stdint" | ||
|
||
lib LibC | ||
IF_NAMESIZE = 16u8 | ||
|
||
fun if_nametoindex(ifname : Char*) : UInt | ||
fun if_indextoname(ifindex : UInt, ifname : LibC::Char*) : LibC::Char* | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require "../netinet/in" | ||
require "../stdint" | ||
|
||
lib LibC | ||
IF_NAMESIZE = 16u8 | ||
|
||
fun if_nametoindex(ifname : Char*) : UInt | ||
fun if_indextoname(ifindex : UInt, ifname : LibC::Char*) : LibC::Char* | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require "../netinet/in" | ||
require "../stdint" | ||
|
||
lib LibC | ||
IF_NAMESIZE = 16u8 | ||
|
||
fun if_nametoindex(ifname : Char*) : UInt | ||
fun if_indextoname(ifindex : UInt, ifname : LibC::Char*) : LibC::Char* | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require "../netinet/in" | ||
require "../stdint" | ||
|
||
lib LibC | ||
IF_NAMESIZE = 16u8 | ||
|
||
fun if_nametoindex(ifname : Char*) : UInt | ||
fun if_indextoname(ifindex : UInt, ifname : LibC::Char*) : LibC::Char* | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require "../netinet/in" | ||
require "../stdint" | ||
|
||
lib LibC | ||
IF_NAMESIZE = 16u8 | ||
|
||
fun if_nametoindex(ifname : Char*) : UInt | ||
fun if_indextoname(ifindex : UInt, ifname : LibC::Char*) : LibC::Char* | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require "../netinet/in" | ||
require "../stdint" | ||
|
||
lib LibC | ||
IF_NAMESIZE = 16u8 | ||
|
||
fun if_nametoindex(ifname : Char*) : UInt | ||
fun if_indextoname(ifindex : UInt, ifname : LibC::Char*) : LibC::Char* | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require "../netinet/in" | ||
require "../stdint" | ||
|
||
lib LibC | ||
IF_NAMESIZE = 16u8 | ||
|
||
fun if_nametoindex(ifname : Char*) : UInt | ||
fun if_indextoname(ifindex : UInt, ifname : LibC::Char*) : LibC::Char* | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require "../netinet/in" | ||
require "../stdint" | ||
|
||
lib LibC | ||
IF_NAMESIZE = 16u8 | ||
|
||
fun if_nametoindex(ifname : Char*) : UInt | ||
fun if_indextoname(ifindex : UInt, ifname : LibC::Char*) : LibC::Char* | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require "../netinet/in" | ||
require "../stdint" | ||
|
||
lib LibC | ||
IF_NAMESIZE = 16u8 | ||
|
||
fun if_nametoindex(ifname : Char*) : UInt | ||
fun if_indextoname(ifindex : UInt, ifname : LibC::Char*) : LibC::Char* | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require "../netinet/in" | ||
require "../stdint" | ||
|
||
lib LibC | ||
IF_NAMESIZE = 16u8 | ||
|
||
fun if_nametoindex(ifname : Char*) : UInt | ||
fun if_indextoname(ifindex : UInt, ifname : LibC::Char*) : LibC::Char* | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require "../netinet/in" | ||
require "../stdint" | ||
|
||
lib LibC | ||
IF_NAMESIZE = 16u8 | ||
|
||
fun if_nametoindex(ifname : Char*) : UInt | ||
fun if_indextoname(ifindex : UInt, ifname : LibC::Char*) : LibC::Char* | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require "../netinet/in" | ||
require "../stdint" | ||
|
||
lib LibC | ||
IF_NAMESIZE = 16u8 | ||
|
||
fun if_nametoindex(ifname : Char*) : UInt | ||
fun if_indextoname(ifindex : UInt, ifname : LibC::Char*) : LibC::Char* | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require "../netinet/in" | ||
require "../stdint" | ||
|
||
lib LibC | ||
IF_NAMESIZE = 16u8 | ||
|
||
fun if_nametoindex(ifname : Char*) : UInt | ||
fun if_indextoname(ifindex : UInt, ifname : LibC::Char*) : LibC::Char* | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require "../netinet/in" | ||
require "../stdint" | ||
|
||
lib LibC | ||
IF_NAMESIZE = 16u8 | ||
|
||
fun if_nametoindex(ifname : Char*) : UInt | ||
fun if_indextoname(ifindex : UInt, ifname : LibC::Char*) : LibC::Char* | ||
end |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require "./in6addr" | ||
require "./inaddr" | ||
require "./stdint" | ||
|
||
@[Link("iphlpapi")] | ||
lib LibC | ||
NDIS_IF_MAX_STRING_SIZE = 256u16 | ||
IF_NAMESIZE = LibC::NDIS_IF_MAX_STRING_SIZE + 1 # need one more byte for terminating '\0' | ||
|
||
fun if_nametoindex(ifname : Char*) : UInt | ||
fun if_indextoname(ifindex : UInt, ifname : LibC::Char*) : LibC::Char* | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters