----------------------------------------------------------------------------- -- -- Onions Network Streams Library -- -- O N I O N S . T H I N -- -- S p e c -- -- Copyright (C) 1997-1998 Regents of the University of California -- -- Onions is free software; you can redistribute it and/or modify it under -- the terms of the GNU General Public License as published by the Free -- Software Foundation, with or without the single exception listed below; -- either version 2, or (at your option) any later version. Onions is -- distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; -- without even the implied warranty of MERCHANTABILITY or FITNESS FOR A -- PARTICULAR PURPOSE. See the GNU General Public License for more details. -- You should have received a copy of the GNU General Public License -- distributed with Onions; see the file COPYING. If not, write to the -- Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- 02111-1307, USA. -- -- As a special exception, if other files instantiate generics from this -- library, or you link this library with other files to produce an -- executable, this library does not by itself cause the resulting -- executable to be covered by the GNU General Public License. This -- exception does not however invalidate any other reasons why the -- executable file might be covered by the GNU General Public License. -- -- Portions of this unit have been derived from version 1.02 of the Garlic -- library of GLADE, the Ada95 Distributed Systems Annex for GNAT. GLADE -- is maintained by ACT Europe (see ). -- -- GLADE is Copyright (C) 1996,1997 Free Software Foundation, Inc. -- All source code that is shared by both GLADE version 1.02 and -- this unit remains under the FSF copyright. -- -- Rewritten for Onions in 1997 by Roy T. Fielding and Yuzo Kanomata ----------------------------------------------------------------------------- with System.Storage_Elements; with Interfaces.C.Strings; with Onions.Constants; with Onions.Pointers; with Unchecked_Conversion; with Unchecked_Deallocation; package Onions.Thin is use type C.int; Success : constant C.int := 0; Failure : constant C.int := -1; type Int_Access is access all C.int; pragma Convention (C, Int_Access); -- Access to C integers. type Int_Flags is mod 2 ** C.int'Size; pragma Convention (C, Int_Flags); subtype Descriptor is C.int; subtype off_t is C.long; type pid_t is new C.int; pragma Convention (C, pid_t); type mode_t is new C.int; pragma Convention (C, mode_t); type Chars_Ptr_Array is array (C.size_t range <>) of aliased C.Strings.chars_ptr; package Chars_Ptr_Pointers is new Pointers (C.size_t, C.Strings.chars_ptr, Chars_Ptr_Array, C.Strings.Null_Ptr); -- Arrays of C (char *). type In_Addr is record S_B1, S_B2, S_B3, S_B4 : C.Unsigned_Char; end record; pragma Convention (C, In_Addr); -- Internet address. type In_Addr_Access is access all In_Addr; pragma Convention (C, In_Addr_Access); -- Access to internet address. Inaddr_Any : aliased constant In_Addr := (others => 0); -- Any internet address (all the interfaces). type In_Addr_Access_Array is array (Positive range <>) of aliased In_Addr_Access; pragma Convention (C, In_Addr_Access_Array); package In_Addr_Access_Pointers is new Pointers (Positive, In_Addr_Access, In_Addr_Access_Array, null); -- Array of internet addresses. type Sockaddr is record Sa_Family : C.Unsigned_Short; Sa_Data : C.Char_Array (1 .. 14); end record; pragma Convention (C, Sockaddr); -- Socket address. type Sockaddr_Access is access all Sockaddr; pragma Convention (C, Sockaddr_Access); -- Access to socket address. type Sockaddr_In is record Sin_Family : C.Short; Sin_Port : C.Unsigned_Short := 0; Sin_Addr : In_Addr := Inaddr_Any; Sin_Zero : C.Char_Array (1 .. 8) := (others => C.Char'Val (0)); end record; pragma Convention (C, Sockaddr_In); -- Internet socket address. type Sockaddr_In_Access is access all Sockaddr_In; pragma Convention (C, Sockaddr_In_Access); -- Access to internet socket address. function To_Sockaddr_Access is new Unchecked_Conversion (Sockaddr_In_Access, Sockaddr_Access); procedure Free is new Unchecked_Deallocation (Sockaddr_In, Sockaddr_In_Access); type Hostent is record H_Name : C.Strings.chars_ptr; H_Aliases : Chars_Ptr_Pointers.Pointer; H_Addrtype : C.int; H_Length : C.int; H_Addr_List : In_Addr_Access_Pointers.Pointer; end record; pragma Convention (C, Hostent); -- Host entry. type Hostent_Access is access all Hostent; pragma Convention (C, Hostent_Access); -- Access to host entry. type Iovec is record Iov_Base : System.Address; -- (void *) Iov_Len : System.Storage_Elements.Storage_Count; -- C.size_t end record; pragma Convention (C, Iovec); -- Iovec C type. type Iovec_Access is access all Iovec; pragma Convention (C, Iovec_Access); -- Access to Iovec structure. type Iov_Array is array (C.int range <>) of aliased Iovec; pragma Convention (C, Iov_Array); type Msghdr is record Msg_Name : System.Address; Msg_Namelen : C.int; Msg_Iov : Iovec_Access; Msg_Iovlen : C.int; Msg_Accrights : System.Address; Msg_Accrightslen : C.int; end record; pragma Convention (C, Msghdr); -- Message header. type Msghdr_Access is access all Msghdr; pragma Convention (C, Msghdr_Access); -- Access to message header. type Two_Descriptor is array (0 .. 1) of Descriptor; pragma Convention (C, Two_Descriptor); -- Used with pipe(). type Pollfd is record Fd : Descriptor; Events : C.Short; Revents : C.Short; end record; pragma Convention (C, Pollfd); type Pollfd_Array is array (Positive range <>) of Pollfd; pragma Convention (C, Pollfd_Array); -------------------------------------------------- -- Fast memory manipulation Library Functions -- -------------------------------------------------- function C_malloc (Size : System.Storage_Elements.Storage_Count) return System.Address; function C_realloc (Base : System.Address; Size : System.Storage_Elements.Storage_Count) return System.Address; procedure C_free (Base : System.Address); function C_memchr (Src : System.Address; What : C.int; Len : System.Storage_Elements.Storage_Count) return System.Address; function C_memcpy (Dest : System.Address; Src : System.Address; Len : System.Storage_Elements.Storage_Count) return System.Address; function C_memmove (Dest : System.Address; Src : System.Address; Len : System.Storage_Elements.Storage_Count) return System.Address; ------------------------------------------ -- File descriptor I/O system library -- ------------------------------------------ function C_open (Path : C.Strings.chars_ptr; Oflag : Int_Flags; Mode : mode_t := 0) return Descriptor; function C_close (Fildes : Descriptor) return C.int; function C_lseek (Fildes : Descriptor; Offset : off_t; Whence : C.int) return off_t; function C_read (Fildes : Descriptor; Buf : System.Address; Nbyte : System.Storage_Elements.Storage_Count) return System.Storage_Elements.Storage_Offset; function C_readv (Fildes : Descriptor; Iov : Iovec_Access; Iovcnt : C.int) return System.Storage_Elements.Storage_Offset; function C_write (Fildes : Descriptor; Buf : System.Address; Nbyte : System.Storage_Elements.Storage_Count) return System.Storage_Elements.Storage_Offset; function C_writev (Fildes : Descriptor; Iov : Iovec_Access; Iovcnt : C.int) return System.Storage_Elements.Storage_Offset; function C_dup (Fildes : Descriptor) return Descriptor; function C_dup2 (Fildes, Fildes2 : Descriptor) return Descriptor; function C_fcntl (Fildes : Descriptor; Cmd : C.int; Arg : C.int := 0) return C.int; function C_poll (Fds : System.Address; Nfds : C.unsigned_long; Timeout : C.int) return C.int; ---------------------------------------------------------- -- Directory entry library includes data structures -- -- and functions defined in the dirent.h C library. -- -- Since the DIR and dirent structures are extremely -- -- system-dependent, we can only use them by reference -- -- and readdir using the abstraction in os-depend.c. -- ---------------------------------------------------------- subtype DIR_Address is System.Address; function C_opendir (Path : in C.Strings.chars_ptr) return DIR_Address; procedure C_rewinddir (Dir_Ptr : DIR_Address); function C_closedir (Dir_Ptr : DIR_Address) return C.int; -------------------------------- -- Socket Library Functions -- -------------------------------- function C_accept (S : Descriptor; Addr : Sockaddr_Access; Addrlen : Int_Access) return C.int; function C_bind (S : Descriptor; Name : Sockaddr_Access; Namelen : C.int) return C.int; function C_connect (S : Descriptor; Name : Sockaddr_Access; Namelen : C.int) return C.int; function C_gethostbyaddr (Addr : C.Strings.chars_ptr; Length : C.int; Typ : C.int) return Hostent_Access; function C_gethostbyname (Name : C.Strings.chars_ptr) return Hostent_Access; function C_gethostname (Name : C.Strings.chars_ptr; Namelen : C.int) return C.int; function C_getpeername (S : Descriptor; Name : Sockaddr_Access; Namelen : Int_Access) return C.int; function C_getsockname (S : Descriptor; Name : Sockaddr_Access; Namelen : Int_Access) return C.int; function C_getsockopt (S : Descriptor; Level : C.int; Optname : C.int; Optval : C.Strings.chars_ptr; Optlen : Int_Access) return C.int; function C_inet_addr (Cp : C.Strings.chars_ptr) return C.Unsigned_Long; function C_inet_network (Cp : C.Strings.chars_ptr) return C.Unsigned_Long; function C_inet_makeaddr (Net : C.int; Lna : C.int) return In_Addr; function C_inet_lnaof (I : In_Addr) return C.int; function C_inet_netof (I : In_Addr) return C.int; function C_inet_ntoa (I : In_Addr) return C.Strings.chars_ptr; function C_listen (S : Descriptor; Backlog : C.int) return C.int; function C_pipe (Filedes : access Two_Descriptor) return C.int; function C_recv (S : Descriptor; Buf : C.Strings.chars_ptr; Len : C.int; Flags : C.int) return C.int; function C_recvfrom (S : Descriptor; Buf : C.Strings.chars_ptr; Len : C.int; Flags : C.int; From : Sockaddr_Access; Fromlen : Int_Access) return C.int; function C_recvmsg (S : Descriptor; Msg : Msghdr_Access; Flags : C.int) return C.int; function C_send (S : Descriptor; Msg : C.Strings.chars_ptr; Len : C.int; Flags : C.int) return C.int; function C_sendmsg (S : Descriptor; Msg : Msghdr_Access; Flags : C.int) return C.int; function C_sendto (S : Descriptor; Msg : C.Strings.chars_ptr; Len : C.int; Flags : C.int; To : Sockaddr_Access; Tolen : C.int) return C.int; function C_setsockopt (S : Descriptor; Level : C.int; Optname : C.int; Optval : C.Strings.chars_ptr; Optlen : C.int) return C.int; function C_shutdown (S : Descriptor; How : C.int) return C.int; function C_socket (Domain, Typ, Protocol : C.int) return Descriptor; -------------------------------- -- Process Control Funtions -- -------------------------------- function C_getenv (Name : C.Strings.chars_ptr) return C.Strings.chars_ptr; function C_getpid return pid_t; function C_kill (Pid : pid_t; Sig : C.int) return C.int; function C_setsid return pid_t; function C_strerror (Errnum : C.int) return C.Strings.chars_ptr; private pragma Import (C, C_malloc, "malloc"); pragma Import (C, C_realloc, "realloc"); pragma Import (C, C_free, "free"); pragma Import (C, C_memchr, "memchr"); pragma Import (C, C_memcpy, "memcpy"); pragma Import (C, C_memmove, "memmove"); pragma Import (C, C_open, "open"); pragma Import (C, C_close, "close"); pragma Import (C, C_lseek, "lseek"); pragma Import (C, C_read, "read"); pragma Import (C, C_readv, "readv"); pragma Import (C, C_write, "write"); pragma Import (C, C_writev, "writev"); pragma Import (C, C_dup, "dup"); pragma Import (C, C_dup2, "dup2"); pragma Import (C, C_fcntl, "fcntl"); pragma Import (C, C_poll, "poll"); pragma Import (C, C_opendir, "opendir"); pragma Import (C, C_rewinddir, "rewinddir"); pragma Import (C, C_closedir, "closedir"); pragma Import (C, C_accept, "accept"); pragma Import (C, C_bind, "bind"); pragma Import (C, C_connect, "connect"); pragma Import (C, C_gethostbyaddr, "gethostbyaddr"); pragma Import (C, C_gethostbyname, "gethostbyname"); pragma Import (C, C_gethostname, "gethostname"); pragma Import (C, C_getpeername, "getpeername"); pragma Import (C, C_getsockname, "getsockname"); pragma Import (C, C_getsockopt, "getsockopt"); pragma Import (C, C_inet_addr, "inet_addr"); pragma Import (C, C_inet_network, "inet_network"); pragma Import (C, C_inet_makeaddr, "inet_makeaddr"); 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_listen, "listen"); pragma Import (C, C_pipe, "pipe"); pragma Import (C, C_recv, "recv"); pragma Import (C, C_recvfrom, "recvfrom"); pragma Import (C, C_recvmsg, "recvmsg"); pragma Import (C, C_send, "send"); pragma Import (C, C_sendmsg, "sendmsg"); pragma Import (C, C_sendto, "sendto"); pragma Import (C, C_setsockopt, "setsockopt"); pragma Import (C, C_shutdown, "shutdown"); pragma Import (C, C_socket, "socket"); pragma Import (C, C_getenv, "getenv"); pragma Import (C, C_getpid, "getpid"); pragma Import (C, C_kill, "kill"); pragma Import (C, C_setsid, "setsid"); pragma Import (C, C_strerror, "strerror"); end Onions.Thin;