-- --
-- S p e c --
-- --
--- Copyright (C) 2008, AdaCore --
+-- Copyright (C) 2008-2010, AdaCore --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
with Interfaces.C;
with Interfaces.C.Pointers;
-with Interfaces.C.Strings;
package GNAT.Sockets.Thin_Common is
pragma Inline (Set_Address);
-- Set Sin.Sin_Addr to Address
+ ------------------
+ -- Host entries --
+ ------------------
+
+ type Hostent is new
+ System.Storage_Elements.Storage_Array (1 .. SOSC.SIZEOF_struct_hostent);
+ for Hostent'Alignment use 8;
+ -- Host entry. This is an opaque type used only via the following
+ -- accessor functions, because 'struct hostent' has different layouts on
+ -- different platforms.
+
+ type Hostent_Access is access all Hostent;
+ 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 System.Address;
+
+ function Hostent_H_Alias
+ (E : Hostent_Access; I : C.int) return System.Address;
+
+ function Hostent_H_Addrtype
+ (E : Hostent_Access) return C.int;
+
+ function Hostent_H_Length
+ (E : Hostent_Access) return C.int;
+
+ function Hostent_H_Addr
+ (E : Hostent_Access; Index : C.int) return System.Address;
+
---------------------
-- Service entries --
---------------------
- type Chars_Ptr_Array is array (C.size_t range <>) of
- aliased C.Strings.chars_ptr;
-
- package Chars_Ptr_Pointers is
- new C.Pointers (C.size_t, C.Strings.chars_ptr, Chars_Ptr_Array,
- C.Strings.Null_Ptr);
- -- Arrays of C (char *)
-
- type Servent is record
- S_Name : C.Strings.chars_ptr;
- S_Aliases : Chars_Ptr_Pointers.Pointer;
- S_Port : C.int;
- S_Proto : C.Strings.chars_ptr;
- end record;
- pragma Convention (C, Servent);
- -- Service entry
+ type Servent is new
+ System.Storage_Elements.Storage_Array (1 .. SOSC.SIZEOF_struct_servent);
+ for Servent'Alignment use 8;
+ -- Service entry. This is an opaque type used only via the following
+ -- accessor functions, because 'struct servent' has different layouts on
+ -- different platforms.
type Servent_Access is access all Servent;
pragma Convention (C, Servent_Access);
-- Access to service entry
+ function Servent_S_Name
+ (E : Servent_Access) return System.Address;
+
+ function Servent_S_Alias
+ (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 System.Address;
+
------------------
- -- Host entries --
+ -- NetDB access --
------------------
- type Hostent is record
- H_Name : C.Strings.chars_ptr;
- H_Aliases : Chars_Ptr_Pointers.Pointer;
- H_Addrtype : SOSC.H_Addrtype_T;
- H_Length : SOSC.H_Length_T;
- H_Addr_List : In_Addr_Access_Pointers.Pointer;
+ -- There are three possible situations for the following NetDB access
+ -- functions:
+ -- - inherently thread safe (case of data returned in a thread specific
+ -- buffer);
+ -- - thread safe using user-provided buffer;
+ -- - thread unsafe.
+ --
+ -- In the first and third cases, the Buf and Buflen are ignored. In the
+ -- second case, the caller must provide a buffer large enough to accomodate
+ -- the returned data. In the third case, the caller must ensure that these
+ -- functions are called within a critical section.
+
+ function C_Gethostbyname
+ (Name : C.char_array;
+ Ret : not null access Hostent;
+ Buf : System.Address;
+ Buflen : C.int;
+ H_Errnop : not null access C.int) return C.int;
+
+ function C_Gethostbyaddr
+ (Addr : System.Address;
+ Addr_Len : C.int;
+ Addr_Type : C.int;
+ Ret : not null access Hostent;
+ Buf : System.Address;
+ Buflen : C.int;
+ H_Errnop : not null access C.int) return C.int;
+
+ function C_Getservbyname
+ (Name : C.char_array;
+ Proto : C.char_array;
+ Ret : not null access Servent;
+ Buf : System.Address;
+ Buflen : C.int) return C.int;
+
+ function C_Getservbyport
+ (Port : C.int;
+ Proto : C.char_array;
+ Ret : not null access Servent;
+ Buf : System.Address;
+ Buflen : C.int) return C.int;
+
+ ------------------------------------
+ -- Scatter/gather vector handling --
+ ------------------------------------
+
+ type Msghdr is record
+ Msg_Name : System.Address;
+ Msg_Namelen : C.unsigned;
+ Msg_Iov : System.Address;
+ Msg_Iovlen : SOSC.Msg_Iovlen_T;
+ Msg_Control : System.Address;
+ Msg_Controllen : C.size_t;
+ Msg_Flags : C.int;
end record;
- pragma Convention (C, Hostent);
- -- Host entry
-
- type Hostent_Access is access all Hostent;
- pragma Convention (C, Hostent_Access);
- -- Access to host entry
+ pragma Convention (C, Msghdr);
----------------------------
-- Socket sets management --
Read_End : constant := 0;
Write_End : constant := 1;
- -- Indices into an Fd_Pair value providing access to each of the connected
+ -- Indexes into an Fd_Pair value providing access to each of the connected
-- file descriptors.
function Inet_Pton
(Af : C.int;
- Cp : C.Strings.chars_ptr;
+ Cp : System.Address;
Inp : System.Address) return C.int;
+ function C_Ioctl
+ (Fd : C.int;
+ Req : C.int;
+ Arg : access C.int) return C.int;
+
private
pragma Import (C, Get_Socket_From_Set, "__gnat_get_socket_from_set");
pragma Import (C, Is_Socket_In_Set, "__gnat_is_socket_in_set");
pragma Import (C, Insert_Socket_In_Set, "__gnat_insert_socket_in_set");
pragma Import (C, Remove_Socket_From_Set, "__gnat_remove_socket_from_set");
pragma Import (C, Reset_Socket_Set, "__gnat_reset_socket_set");
+ pragma Import (C, C_Ioctl, "__gnat_socket_ioctl");
pragma Import (C, Inet_Pton, SOSC.Inet_Pton_Linkname);
+
+ pragma Import (C, C_Gethostbyname, "__gnat_gethostbyname");
+ pragma Import (C, C_Gethostbyaddr, "__gnat_gethostbyaddr");
+ pragma Import (C, C_Getservbyname, "__gnat_getservbyname");
+ pragma Import (C, C_Getservbyport, "__gnat_getservbyport");
+
+ pragma Import (C, Servent_S_Name, "__gnat_servent_s_name");
+ pragma Import (C, Servent_S_Alias, "__gnat_servent_s_alias");
+ pragma Import (C, Servent_S_Port, "__gnat_servent_s_port");
+ pragma Import (C, Servent_S_Proto, "__gnat_servent_s_proto");
+
+ pragma Import (C, Hostent_H_Name, "__gnat_hostent_h_name");
+ pragma Import (C, Hostent_H_Alias, "__gnat_hostent_h_alias");
+ pragma Import (C, Hostent_H_Addrtype, "__gnat_hostent_h_addrtype");
+ pragma Import (C, Hostent_H_Length, "__gnat_hostent_h_length");
+ pragma Import (C, Hostent_H_Addr, "__gnat_hostent_h_addr");
+
end GNAT.Sockets.Thin_Common;