This file is indexed.

/usr/share/ada/adainclude/anet/anet-sockets-unix.adb is in libanet0.3.1-dev 0.3.1-1ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
--
--  Copyright (C) 2012-2013 secunet Security Networks AG
--  Copyright (C) 2012-2014 Reto Buerki <reet@codelabs.ch>
--  Copyright (C) 2012-2014 Adrian-Ken Rueegsegger <ken@codelabs.ch>
--
--  This program 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; either version 2 of the License, or (at your
--  option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
--
--  This program 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.
--
--  As a special exception, if other files instantiate generics from this
--  unit,  or  you  link  this  unit  with  other  files  to  produce  an
--  executable   this  unit  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 Public License.
--

with Anet.OS;

package body Anet.Sockets.Unix is

   package C renames Interfaces.C;

   -------------------------------------------------------------------------

   procedure Accept_Connection
     (Socket     :     TCP_Socket_Type;
      New_Socket : out TCP_Socket_Type)
   is
      Res  : C.int;
      Sock : Thin.Unix.Sockaddr_Un_Type;
      Len  : aliased C.int := Sock'Size / 8;
   begin
      New_Socket.Sock_FD := -1;

      Res := Thin.C_Accept (S       => Socket.Sock_FD,
                            Name    => Sock'Address,
                            Namelen => Len'Access);

      case Check_Accept (Result => Res)
      is
         when Accept_Op_Aborted => return;
         when Accept_Op_Error =>
            raise Socket_Error with "Unable to accept connection on UNIX/TCP "
              & "socket - " & Get_Errno_String;
         when Accept_Op_Ok =>
            New_Socket.Sock_FD := Res;
            New_Socket.Path    := Socket.Path;
      end case;
   end Accept_Connection;

   -------------------------------------------------------------------------

   procedure Bind
     (Socket : in out Unix_Socket_Type;
      Path   :        Path_Type)
   is
      Res    : C.int;
      C_Path : constant C.char_array := C.To_C (String (Path));
      Value  : Thin.Unix.Sockaddr_Un_Type;
   begin
      OS.Delete_File (Filename => String (Path));

      Value.Pathname (1 .. C_Path'Length) := C_Path;

      Res := Thin.C_Bind (S       => Socket.Sock_FD,
                          Name    => Value'Address,
                          Namelen => Value'Size / 8);

      if Res = C_Failure then
         raise Socket_Error with "Unable to bind unix socket to path "
           & String (Path) & " - " & Get_Errno_String;
      end if;

      Socket.Path := Ada.Strings.Unbounded.To_Unbounded_String
        (String (Path));
   end Bind;

   -------------------------------------------------------------------------

   procedure Close (Socket : in out Unix_Socket_Type)
   is
   begin
      if Socket.Sock_FD /= -1 then
         OS.Delete_File (Filename => Ada.Strings.Unbounded.To_String
                         (Socket.Path));
         Socket_Type (Socket).Close;
      end if;
   end Close;

   -------------------------------------------------------------------------

   procedure Connect
     (Socket : in out Unix_Socket_Type;
      Path   :        Path_Type)
   is
      Res    : C.int;
      C_Path : constant C.char_array := C.To_C (String (Path));
      Value  : Thin.Unix.Sockaddr_Un_Type;
   begin
      Value.Pathname (1 .. C_Path'Length) := C_Path;

      Res := Thin.C_Connect (S       => Socket.Sock_FD,
                             Name    => Value'Address,
                             Namelen => Value'Size / 8);

      if Res = C_Failure then
         raise Socket_Error with "Unable to connect unix socket to path "
           & String (Path) & " - " & Get_Errno_String;
      end if;
   end Connect;

   -------------------------------------------------------------------------

   procedure Init (Socket : in out UDP_Socket_Type)
   is
   begin
      Init (Socket => Socket,
            Family => Socket_Families.Family_Unix,
            Mode   => Datagram_Socket);
   end Init;

   -------------------------------------------------------------------------

   procedure Init (Socket : in out TCP_Socket_Type)
   is
   begin
      Init (Socket => Socket,
            Family => Socket_Families.Family_Unix,
            Mode   => Stream_Socket);
   end Init;

   -------------------------------------------------------------------------

   function Is_Valid (Path : String) return Boolean
   is
   begin
      return Path'Length in Path_Range;
   end Is_Valid;

   -------------------------------------------------------------------------

   procedure Receive
     (Socket :     UDP_Socket_Type;
      Src    : out Full_Path_Type;
      Item   : out Ada.Streams.Stream_Element_Array;
      Last   : out Ada.Streams.Stream_Element_Offset)
   is
      Path : constant String := Ada.Strings.Unbounded.To_String (Socket.Path);
   begin
      Socket_Type (Socket).Receive (Item => Item,
                                    Last => Last);
      Src (Src'First .. Path'Length) := Path_Type (Path);
   end Receive;

end Anet.Sockets.Unix;