Skip to content

Commit b0de4d5

Browse files
TurboGittonunaks
authored andcommitted
Bind/Connect: Fallback to IPv4 if IPv6 is not available.
When the family is not specificed we first try an IPv6 address but in this case we don't want to fail if IPv6 is not supported/activated on the interface. We want to gracefully fallback to IPv4. eng/toolchain/aws#50
1 parent 0e670cb commit b0de4d5

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

config/src/aws-net-std__gnat.adb

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,16 @@ package body AWS.Net.Std is
152152

153153
exception
154154
when E : Sockets.Socket_Error | Sockets.Host_Error =>
155-
if Socket.S.FD /= Sockets.No_Socket then
156-
Sockets.Close_Socket (Socket.S.FD);
157-
Socket.S.FD := Sockets.No_Socket;
155+
-- We don't want to fail if Family_Unspec is specified and
156+
-- we try to bind to an IPv6 address. In this case we want
157+
-- to fallback to IPv4 is possible.
158+
if Family /= Family_Unspec
159+
or else Addr_Info.Addr.Family /= Sockets.Family_Inet6
160+
then
161+
if Socket.S.FD /= Sockets.No_Socket then
162+
Sockets.Close_Socket (Socket.S.FD);
163+
Socket.S.FD := Sockets.No_Socket;
164+
end if;
158165
end if;
159166

160167
Exceptions.Save_Occurrence (Keep_Excp, E);
@@ -289,9 +296,16 @@ package body AWS.Net.Std is
289296

290297
exception
291298
when E : Sockets.Socket_Error | Sockets.Host_Error =>
292-
if Close_On_Exception then
293-
Sockets.Close_Socket (Socket.S.FD);
294-
Close_On_Exception := False;
299+
-- We don't want to fail if Family_Unspec is specified and
300+
-- we try to bind to an IPv6 address. In this case we want
301+
-- to fallback to IPv4 is possible.
302+
if Family /= Family_Unspec
303+
or else Addr_Info.Addr.Family /= Sockets.Family_Inet6
304+
then
305+
if Close_On_Exception then
306+
Sockets.Close_Socket (Socket.S.FD);
307+
Close_On_Exception := False;
308+
end if;
295309
end if;
296310

297311
Save_Occurrence (Keep_Excp, E);

0 commit comments

Comments
 (0)