-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for ipv4 peers (#121)
- Loading branch information
1 parent
8c4de1a
commit e4b10f7
Showing
2 changed files
with
23 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const std = @import("std"); | ||
|
||
pub fn convertIPv4ToIPv6(address: std.net.Address) std.net.Address { | ||
// Convert IPv4 to IPv6-mapped IPv4 address | ||
const ipv4_address = address.in; | ||
|
||
var ipv6_mapped: [16]u8 = [_]u8{0} ** 16; | ||
|
||
// Set bytes 10 and 11 to 0xff | ||
ipv6_mapped[10] = 0xff; | ||
ipv6_mapped[11] = 0xff; | ||
|
||
// Copy the IPv4 address into the last 4 bytes of the IPv6-mapped address | ||
const ipv4_bytes = std.mem.asBytes(&ipv4_address.sa.addr); | ||
@memcpy(ipv6_mapped[12..16], ipv4_bytes[0..4]); | ||
|
||
return std.net.Address.initIp6(ipv6_mapped, ipv4_address.getPort(), 0, 0); | ||
} |
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