Skip to content

Commit fc6e585

Browse files
author
Arnaud Bouchez
committed
net: allow to bind to any IPv6 address (::)
1 parent eefc216 commit fc6e585

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/mormot.commit.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
'2.3.9032'
1+
'2.3.9033'

src/net/mormot.net.sock.pas

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2320,18 +2320,24 @@ procedure NetAddrFlush(const hostname: RawUtf8);
23202320
function TNetAddr.SetFromIP4(const address: RawUtf8;
23212321
noNewSocketIP4Lookup: boolean): boolean;
23222322
begin
2323-
result := false;
2323+
// allow to bind to any IPv6 address
2324+
if address = c6AnyHost then // ::
2325+
begin
2326+
PSockAddrIn6(@Addr)^.sin6_family := AF_INET6; // keep all sin6_addr[] = 0
2327+
result := true;
2328+
exit;
2329+
end;
23242330
// caller did set addr4.sin_port and other fields to 0
2331+
result := false;
23252332
with PSockAddr(@Addr)^ do
23262333
if (address = cLocalhost) or
2327-
(address = c6Localhost) or
2334+
(address = c6Localhost) or // ::1
23282335
PropNameEquals(address, 'localhost') then
23292336
PCardinal(@sin_addr)^ := cLocalhost32 // 127.0.0.1
23302337
else if (address = cBroadcast) or
23312338
(address = c6Broadcast) then
23322339
PCardinal(@sin_addr)^ := cardinal(-1) // 255.255.255.255
2333-
else if (address = cAnyHost) or
2334-
(address = c6AnyHost) then
2340+
else if address = cAnyHost then
23352341
// keep 0.0.0.0 for bind - but connect would redirect to 127.0.0.1
23362342
else if NetIsIP4(pointer(address), @sin_addr) or
23372343
GetKnownHost(address, PCardinal(@sin_addr)^) or

0 commit comments

Comments
 (0)