aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/g-socket.adb
diff options
context:
space:
mode:
authorArnaud Charlet <charlet@gcc.gnu.org>2016-06-20 14:25:44 +0200
committerArnaud Charlet <charlet@gcc.gnu.org>2016-06-20 14:25:44 +0200
commit2f8d7dfe21740d1066912f2f99b83096ebf2962b (patch)
treeb5fde2e52c699b7ea7fe5aefa2230ad7902ef393 /gcc/ada/g-socket.adb
parent61f17a5c5a8565c5ebfcdbe78f16b56c52b285dd (diff)
downloadgcc-2f8d7dfe21740d1066912f2f99b83096ebf2962b.zip
gcc-2f8d7dfe21740d1066912f2f99b83096ebf2962b.tar.gz
gcc-2f8d7dfe21740d1066912f2f99b83096ebf2962b.tar.bz2
[multiple changes]
2016-06-20 Hristian Kirtchev <kirtchev@adacore.com> * s-regpat.adb, sem_prag.adb, pprint.adb, sem_ch13.adb: Minor reformatting. 2016-06-20 Tristan Gingold <gingold@adacore.com> * make.adb (Check_Standard_Library): Consider system.ads if s-stalib.adb is not available. * gnatbind.adb (Add_Artificial_ALI_File): New procedure extracted from gnatbind. 2016-06-20 Thomas Quinot <quinot@adacore.com> * g-socket.adb (Is_IP_Address): A string consisting in digits only is not a dotted quad. 2016-06-20 Arnaud Charlet <charlet@adacore.com> * exp_ch7.adb (Build_Invariant_Procedure_Body): decorate invariant procedure body with typical properties of procedure entityes. 2016-06-20 Arnaud Charlet <charlet@adacore.com> * a-exetim-darwin.adb: New file. From-SVN: r237598
Diffstat (limited to 'gcc/ada/g-socket.adb')
-rw-r--r--gcc/ada/g-socket.adb34
1 files changed, 28 insertions, 6 deletions
diff --git a/gcc/ada/g-socket.adb b/gcc/ada/g-socket.adb
index 6a61a81..a4a7d4f 100644
--- a/gcc/ada/g-socket.adb
+++ b/gcc/ada/g-socket.adb
@@ -150,7 +150,7 @@ package body GNAT.Sockets is
-- Output an array of inet address components in hex or decimal mode
function Is_IP_Address (Name : String) return Boolean;
- -- Return true when Name is an IP address in standard dot notation
+ -- Return true when Name is an IPv4 address in dotted quad notation
procedure Netdb_Lock;
pragma Inline (Netdb_Lock);
@@ -996,7 +996,8 @@ package body GNAT.Sockets is
function Get_Host_By_Name (Name : String) return Host_Entry_Type is
begin
- -- Detect IP address name and redirect to Inet_Addr
+ -- If the given name actually is the string representation of
+ -- an IP address, use Get_Host_By_Address instead.
if Is_IP_Address (Name) then
return Get_Host_By_Address (Inet_Addr (Name));
@@ -1503,16 +1504,37 @@ package body GNAT.Sockets is
-------------------
function Is_IP_Address (Name : String) return Boolean is
+ Dots : Natural := 0;
begin
+ -- Perform a cursory check for a dotted quad: we must have 1 to 3
+ -- dots, and there must be at least one digit around each.
+
for J in Name'Range loop
- if Name (J) /= '.'
- and then Name (J) not in '0' .. '9'
- then
+ if Name (J) = '.' then
+
+ -- Check that the dot is not in first or last position, and
+ -- that it is followed by a digit. Note that we already know
+ -- that it is preceded by a digit, or we would have returned
+ -- earlier on.
+
+ if J in Name'First + 1 .. Name'Last - 1
+ and then Name (J + 1) in '0' .. '9'
+ then
+ Dots := Dots + 1;
+
+ else
+
+ -- Definitely not a proper dotted quad
+
+ return False;
+ end if;
+
+ elsif Name (J) not in '0' .. '9' then
return False;
end if;
end loop;
- return True;
+ return Dots in 1 .. 3;
end Is_IP_Address;
-------------