File: test_database.adb

package info (click to toggle)
libflorist 2025.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 4,084 kB
  • sloc: ada: 33,302; ansic: 7,240; makefile: 671; sh: 93
file content (148 lines) | stat: -rw-r--r-- 4,626 bytes parent folder | download
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
with POSIX; use POSIX;
with POSIX.IO; use POSIX.IO;
with POSIX.Files; use POSIX.Files;
with POSIX.Sockets; use POSIX.Sockets;
with POSIX.Sockets.Internet; use POSIX.Sockets.Internet;
with test_pkg; use test_pkg;
with Gnat.IO; use Gnat.IO;
with Ada.Streams; use Ada.Streams;
with Text_IO;
with Ada.Text_IO;

Procedure Test_Database is

   Procedure Display_Network_Info (Net_Info: Network_Information) is
      Temp: String (1 .. 5);
      package Net_IO is new Text_IO.Integer_IO (Network_Number);
   begin
      declare
         Name: constant POSIX_String := Get_Name (Net_Info);
         Sname: constant String := To_String(Name);
      begin
         Comment ("...Network Name: " & Sname);
      end;
--      case Get_Address_Family (Net_Info) is
--         when Internet_Domain =>
--            Comment ("...Address Family: Internet_Domain");
--         when Others =>
--            Comment ("...Address Family: Unknown_Domain");
--      end case;
      Net_IO.Put (Temp, Get_Network_Number (Net_Info));
      Comment ("...Network Number: " & Temp);
      declare
         procedure Print_Alias
           (Name: in     POSIX_String;
            Quit: in out Boolean) is
         begin
            if Verbose then
               Put (To_String(Name) & " ");
            end if;
         end Print_Alias;
         procedure Print_Every_Alias is new
                      For_Every_Network_Alias(Print_Alias);
      begin
         if Verbose then
            Put ("  ...Network Aliases: ");
         end if;
         Print_Every_Alias (Net_Info);
         if Verbose then
            New_Line;
         end if;
      end;
   end Display_Network_Info;

   Procedure Display_Protocol_Info (Pro_Info: Protocol_Information) is
      Temp: String (1 .. 5);
      package Pro_IO is new Ada.Text_IO.Integer_IO (Protocol_Number);
   begin
      declare
         Name: constant POSIX_String := Get_Name (Pro_Info);
         Sname: constant String := To_String(Name);
      begin
         Comment ("...Protocol Name: " & Sname);
      end;
      Pro_IO.Put (Temp, Get_Protocol_Number (Pro_Info));
      Comment ("...Protocol Number: " & Temp);
      declare
         procedure Print_Alias
           (Name: in     POSIX_String;
            Quit: in out Boolean) is
         begin
            if Verbose then
               Put (To_String(Name) & " ");
            end if;
         end Print_Alias;
         procedure Print_Every_Alias is new For_Every_Protocol_Alias(Print_Alias);
      begin
         if Verbose then
            Put ("  ...Protocol Aliases: ");
         end if;
         Print_Every_Alias (Pro_Info);
         if Verbose then
            New_Line;
         end if;
      end;
   end Display_Protocol_Info;

   Net_Info: Network_Information;
   Pro_Info: Protocol_Information;

   Storage : POSIX.Sockets.Internet.Database_Array_Pointer :=
                       new POSIX.Sockets.Internet.Database_Array (0 .. 1023);
begin

   -----------------------
   -- Network Database  --
   -----------------------

   Test ("Network Database");

   Comment ("Open Network Database");
   Open_Network_Database_Connection (True);

   Comment ("Get Network Information by Name");
   Net_Info := Get_Network_Information_By_Name ("loopback", Storage);
   Display_Network_Info (Net_Info);

   Comment ("Get Network Information by Address");
   Net_Info := Get_Network_Information_By_Address
                          (127, Internet_Protocol, Storage);
   Display_Network_Info (Net_Info);

   Comment ("Try a non-existent network");
   Net_Info := Get_Network_Information_By_Name ("garbage", Storage);
   Display_Network_Info (Net_Info);

   Comment ("Close Network Database");
   Close_Network_Database_Connection;

   ------------------------
   -- Protocol Database  --
   ------------------------
   Test ("Protocol Database");

   Comment ("Open Protocol Database");
   Open_Protocol_Database_Connection (True);

   Comment ("Get Protocol Information by Name");
   Pro_Info := Get_Protocol_Information_By_Name ("tcp", Storage);
   Display_Protocol_Info (Pro_Info);
   Pro_Info := Get_Protocol_Information_By_Name ("udp", Storage);
   Display_Protocol_Info (Pro_Info);

   Comment ("Get Protocol Information by Number");
   Pro_Info := Get_Protocol_Information_By_Number (1, Storage);
   Display_Protocol_Info (Pro_Info);

   Comment ("Try a non-existent protocol");
   Pro_Info := Get_Protocol_Information_By_Name ("garbage", Storage);
   Display_Protocol_Info (Pro_Info);

   Comment ("Close Protocol Database");
   Close_Protocol_Database_Connection;

   Done;

   exception when E : others => Fail (E);

end Test_Database;