+2010-06-14 Thomas Quinot <quinot@adacore.com>
+
+ * socket.c: Fix wrong condition in #ifdef
+ * g-socket.adb, g-sothco.ads: Functions imported from socket.c that
+ take or return char* values can't use Interfaces.C.Strings.chars_ptr,
+ because on VMS this type is a 32-bit pointer which is not compatible
+ with the default for C pointers for code compiled with gcc on that
+ platform.
+
2010-06-14 Ed Schonberg <schonberg@adacore.com>
* sem_util (Is_VMS_Operator): New predicate to determine whether an
function To_Service_Entry (E : Servent_Access) return Service_Entry_Type;
-- Conversion function
+ function Value (S : System.Address) return String;
+ -- Same as Interfaces.C.Strings.Value but taking a System.Address (on VMS,
+ -- chars_ptr is a 32-bit pointer, and here we need a 64-bit version).
+
function To_Timeval (Val : Timeval_Duration) return Timeval;
-- Separate Val in seconds and microseconds
use Interfaces.C.Strings;
Img : aliased char_array := To_C (Image);
- Cp : constant chars_ptr := To_Chars_Ptr (Img'Unchecked_Access);
Addr : aliased C.int;
Res : C.int;
Result : Inet_Addr_Type;
Raise_Socket_Error (SOSC.EINVAL);
end if;
- Res := Inet_Pton (SOSC.AF_INET, Cp, Addr'Address);
+ Res := Inet_Pton (SOSC.AF_INET, Img'Address, Addr'Address);
if Res < 0 then
Raise_Socket_Error (Socket_Errno);
begin
Aliases_Count := 0;
- while Hostent_H_Alias (E, C.int (Aliases_Count)) /= Null_Ptr loop
+ while Hostent_H_Alias (E, C.int (Aliases_Count)) /= Null_Address loop
Aliases_Count := Aliases_Count + 1;
end loop;
Addresses_Count := 0;
- while Hostent_H_Addr (E, C.int (Addresses_Count)) /= Null_Ptr loop
+ while Hostent_H_Addr (E, C.int (Addresses_Count)) /= Null_Address loop
Addresses_Count := Addresses_Count + 1;
end loop;
for J in Result.Addresses'Range loop
declare
Addr : In_Addr;
- function To_Address is
- new Ada.Unchecked_Conversion (chars_ptr, System.Address);
for Addr'Address use
- To_Address (Hostent_H_Addr
- (E, C.int (J - Result.Addresses'First)));
+ Hostent_H_Addr (E, C.int (J - Result.Addresses'First));
pragma Import (Ada, Addr);
begin
To_Inet_Addr (Addr, Result.Addresses (J));
begin
Aliases_Count := 0;
- while Servent_S_Alias (E, C.int (Aliases_Count)) /= Null_Ptr loop
+ while Servent_S_Alias (E, C.int (Aliases_Count)) /= Null_Address loop
Aliases_Count := Aliases_Count + 1;
end loop;
end To_Timeval;
-----------
+ -- Value --
+ -----------
+
+ function Value (S : System.Address) return String is
+ Str : String (1 .. Positive'Last);
+ for Str'Address use S;
+ pragma Import (Ada, Str);
+
+ Terminator : Positive := Str'First;
+
+ begin
+ while Str (Terminator) /= ASCII.NUL loop
+ Terminator := Terminator + 1;
+ end loop;
+
+ return Str (1 .. Terminator - 1);
+ end Value;
+
+ -----------
-- Write --
-----------
with Interfaces.C;
with Interfaces.C.Pointers;
-with Interfaces.C.Strings;
package GNAT.Sockets.Thin_Common is
pragma Convention (C, Hostent_Access);
-- Access to host entry
+ -- Note: the hostent and servent accessors that return char*
+ -- values are compiled with GCC, and on VMS they always return
+ -- 64-bit pointers, so we can't use C.Strings.chars_ptr, which
+ -- on VMS is 32 bits.
+
function Hostent_H_Name
- (E : Hostent_Access) return C.Strings.chars_ptr;
+ (E : Hostent_Access) return System.Address;
function Hostent_H_Alias
- (E : Hostent_Access; I : C.int) return C.Strings.chars_ptr;
+ (E : Hostent_Access; I : C.int) return System.Address;
function Hostent_H_Addrtype
(E : Hostent_Access) return C.int;
(E : Hostent_Access) return C.int;
function Hostent_H_Addr
- (E : Hostent_Access; Index : C.int) return C.Strings.chars_ptr;
+ (E : Hostent_Access; Index : C.int) return System.Address;
---------------------
-- Service entries --
-- Access to service entry
function Servent_S_Name
- (E : Servent_Access) return C.Strings.chars_ptr;
+ (E : Servent_Access) return System.Address;
function Servent_S_Alias
- (E : Servent_Access; Index : C.int) return C.Strings.chars_ptr;
+ (E : Servent_Access; Index : C.int) return System.Address;
function Servent_S_Port
(E : Servent_Access) return C.unsigned_short;
function Servent_S_Proto
- (E : Servent_Access) return C.Strings.chars_ptr;
+ (E : Servent_Access) return System.Address;
------------------
-- NetDB access --
function Inet_Pton
(Af : C.int;
- Cp : C.Strings.chars_ptr;
+ Cp : System.Address;
Inp : System.Address) return C.int;
function C_Ioctl
*/
typedef char *__netdb_char_ptr __attribute__ (( mode (SI) ));
typedef __netdb_char_ptr *__netdb_char_ptr_ptr __attribute__ (( mode (SI) ));
-# define NEED_STRUCT_xxxENT
-#elif defined (__vxworks)
-/*
- * For VxWorks we emulate getXXXbyYYY using the proprietary VxWorks API.
- */
-typedef char *__netdb_char_ptr;
-typedef __netdb_char_ptr *__netdb_char_ptr_ptr;
-# define NEED_STRUCT_xxxENT
-
-#else
-# undef NEED_STRUCT_xxxENT
-#endif
-
-#ifdef NEED_STRUCT_xxxENT
struct hostent {
__netdb_char_ptr h_name;
__netdb_char_ptr_ptr h_aliases;
extern int __gnat_hostent_h_length (struct hostent *);
extern char * __gnat_hostent_h_addr (struct hostent *, int);
-#if defined (__vxworks) || defined (_WIN32)
+#ifndef HAVE_INET_PTON
extern int __gnat_inet_pton (int, const char *, void *);
#endif
\f