PATCH - Replace inet_addr with inet_aton
Guillaume Foliard <[email protected]> Sat, 27 Jan 2007 22:35:30 +0100
| Newsgroups | gmane.comp.lang.ada.sockets |
|---|---|
| Organization | _ |
| Message-ID | <[email protected]> |
--Boundary-00=_iW8uFS8KbRKJeU4
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Hello,
Here is a patch which replaces the call to inet_addr with a call to inet_aton.
According to the inet_addr man page, this function is obsoleted by inet_aton.
Reviews and comments are welcome.
Guillaume
--Boundary-00=_iW8uFS8KbRKJeU4
Content-Type: text/x-diff; charset="us-ascii";
name="adasockets-1.8.4.7-naming-value.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="adasockets-1.8.4.7-naming-value.diff"
diff -ru adasockets-1.8.4.7p1/src/sockets-naming.adb adasockets-1.8.4.7p2/src/sockets-naming.adb
--- adasockets-1.8.4.7p1/src/sockets-naming.adb 2004-08-10 15:30:49.000000000 +0200
+++ adasockets-1.8.4.7p2/src/sockets-naming.adb 2006-08-22 10:29:33.000000000 +0200
@@ -521,21 +521,19 @@
-----------
function Value (Add : String) return Address is
+ C_Add : chars_ptr := New_String (Add);
+ -- Converted : constant In_Addr := C_Inet_Addr (C_Add);
+ Converted : aliased In_Addr;
begin
- if not Is_IP_Address (Add) then
- Ada.Exceptions.Raise_Exception (Naming_Error'Identity,
- Add & " is not an IP address");
+ if C_Inet_Aton (C_Add, Converted'Unchecked_Access) = 0 then
+ Ada.Exceptions.Raise_Exception (Naming_Error'Identity,
+ Add & " is not an IP address");
end if;
- declare
- C_Add : chars_ptr := New_String (Add);
- Converted : constant In_Addr := C_Inet_Addr (C_Add);
- begin
- Free (C_Add);
- return (H1 => Address_Component (Converted.S_B1),
- H2 => Address_Component (Converted.S_B2),
- H3 => Address_Component (Converted.S_B3),
- H4 => Address_Component (Converted.S_B4));
- end;
+ Free (C_Add);
+ return (H1 => Address_Component (Converted.S_B1),
+ H2 => Address_Component (Converted.S_B2),
+ H3 => Address_Component (Converted.S_B3),
+ H4 => Address_Component (Converted.S_B4));
end Value;
end Sockets.Naming;
diff -ru adasockets-1.8.4.7p1/src/sockets-thin.ads.unix adasockets-1.8.4.7p2/src/sockets-thin.ads.unix
--- adasockets-1.8.4.7p1/src/sockets-thin.ads.unix 2004-08-10 15:34:03.000000000 +0200
+++ adasockets-1.8.4.7p2/src/sockets-thin.ads.unix 2006-11-01 13:51:41.000000000 +0100
@@ -258,6 +258,11 @@
function C_Inet_Ntoa (I : In_Addr) return Strings.chars_ptr;
+ function C_Inet_Aton
+ (Cp : Strings.chars_ptr;
+ I : In_Addr_Access)
+ return C.int;
+
function C_Kill (Pid : pid_t; Sig : C.int) return C.int;
function C_Listen (S, Backlog : C.int) return C.int;
@@ -412,6 +417,7 @@
pragma Import (C, C_Inet_Lnaof, "inet_lnaof");
pragma Import (C, C_Inet_Netof, "inet_netof");
pragma Import (C, C_Inet_Ntoa, "inet_ntoa");
+ pragma Import (C, C_Inet_Aton, "inet_aton");
pragma Import (C, C_Kill, "kill");
pragma Import (C, C_Listen, "listen");
pragma Import (C, C_Msgget, "msgget");
--Boundary-00=_iW8uFS8KbRKJeU4
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
AdaSockets mailing list
[email protected]
http://lists.rfc1149.net/mailman/listinfo/adasockets
--Boundary-00=_iW8uFS8KbRKJeU4--