comparison gcc/ada/libgnat/g-socket.ads @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
comparison
equal deleted inserted replaced
111:04ced10e8804 131:84e7813d76e9
4 -- -- 4 -- --
5 -- G N A T . S O C K E T S -- 5 -- G N A T . S O C K E T S --
6 -- -- 6 -- --
7 -- S p e c -- 7 -- S p e c --
8 -- -- 8 -- --
9 -- Copyright (C) 2001-2017, AdaCore -- 9 -- Copyright (C) 2001-2018, AdaCore --
10 -- -- 10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under -- 11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- -- 12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- -- 13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- 14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
487 -- All ports 487 -- All ports
488 488
489 No_Port : constant Port_Type; 489 No_Port : constant Port_Type;
490 -- Uninitialized port number 490 -- Uninitialized port number
491 491
492 type Inet_Addr_Type (Family : Family_Type := Family_Inet) is private; 492 type Inet_Addr_Comp_Type is mod 2 ** 8;
493 -- Octet for Internet address
494
495 Inet_Addr_Bytes_Length : constant array (Family_Type) of Positive :=
496 (Family_Inet => 4, Family_Inet6 => 16);
497
498 type Inet_Addr_Bytes is array (Natural range <>) of Inet_Addr_Comp_Type;
499
500 subtype Inet_Addr_V4_Type is
501 Inet_Addr_Bytes (1 .. Inet_Addr_Bytes_Length (Family_Inet));
502 subtype Inet_Addr_V6_Type is
503 Inet_Addr_Bytes (1 .. Inet_Addr_Bytes_Length (Family_Inet6));
504
505 subtype Inet_Addr_VN_Type is Inet_Addr_Bytes;
506 -- For backwards compatibility
507
508 type Inet_Addr_Type (Family : Family_Type := Family_Inet) is record
509 case Family is
510 when Family_Inet =>
511 Sin_V4 : Inet_Addr_V4_Type := (others => 0);
512
513 when Family_Inet6 =>
514 Sin_V6 : Inet_Addr_V6_Type := (others => 0);
515 end case;
516 end record;
517
493 -- An Internet address depends on an address family (IPv4 contains 4 octets 518 -- An Internet address depends on an address family (IPv4 contains 4 octets
494 -- and IPv6 contains 16 octets). Any_Inet_Addr is a special value treated 519 -- and IPv6 contains 16 octets). Any_Inet_Addr is a special value treated
495 -- like a wildcard enabling all addresses. No_Inet_Addr provides a special 520 -- like a wildcard enabling all addresses. No_Inet_Addr provides a special
496 -- value to denote uninitialized inet addresses. 521 -- value to denote uninitialized inet addresses.
497 522
503 -- Useful constants for IPv4 multicast addresses 528 -- Useful constants for IPv4 multicast addresses
504 529
505 Unspecified_Group_Inet_Addr : constant Inet_Addr_Type; 530 Unspecified_Group_Inet_Addr : constant Inet_Addr_Type;
506 All_Hosts_Group_Inet_Addr : constant Inet_Addr_Type; 531 All_Hosts_Group_Inet_Addr : constant Inet_Addr_Type;
507 All_Routers_Group_Inet_Addr : constant Inet_Addr_Type; 532 All_Routers_Group_Inet_Addr : constant Inet_Addr_Type;
533
534 -- Functions to handle masks and prefixes
535
536 function Mask
537 (Family : Family_Type;
538 Length : Natural;
539 Host : Boolean := False) return Inet_Addr_Type;
540 -- Return an address mask of the given family with the given prefix length.
541 -- If Host is False, this is a network mask (i.e. network bits are 1,
542 -- and host bits are 0); if Host is True, this is a host mask (i.e.
543 -- network bits are 0, and host bits are 1).
544
545 function "and" (Addr, Mask : Inet_Addr_Type) return Inet_Addr_Type;
546 function "or" (Net, Host : Inet_Addr_Type) return Inet_Addr_Type;
547 function "not" (Mask : Inet_Addr_Type) return Inet_Addr_Type;
548 -- Bit-wise operations on inet addresses (both operands must have the
549 -- same address family).
508 550
509 type Sock_Addr_Type (Family : Family_Type := Family_Inet) is record 551 type Sock_Addr_Type (Family : Family_Type := Family_Inet) is record
510 Addr : Inet_Addr_Type (Family); 552 Addr : Inet_Addr_Type (Family);
511 Port : Port_Type; 553 Port : Port_Type;
512 end record; 554 end record;
1211 Set : aliased Fd_Set; 1253 Set : aliased Fd_Set;
1212 -- Underlying socket set. Note that the contents of this component is 1254 -- Underlying socket set. Note that the contents of this component is
1213 -- undefined if Last = No_Socket. 1255 -- undefined if Last = No_Socket.
1214 end record; 1256 end record;
1215 1257
1216 subtype Inet_Addr_Comp_Type is Natural range 0 .. 255;
1217 -- Octet for Internet address
1218
1219 type Inet_Addr_VN_Type is array (Natural range <>) of Inet_Addr_Comp_Type;
1220
1221 subtype Inet_Addr_V4_Type is Inet_Addr_VN_Type (1 .. 4);
1222 subtype Inet_Addr_V6_Type is Inet_Addr_VN_Type (1 .. 16);
1223
1224 type Inet_Addr_Type (Family : Family_Type := Family_Inet) is record
1225 case Family is
1226 when Family_Inet =>
1227 Sin_V4 : Inet_Addr_V4_Type := (others => 0);
1228
1229 when Family_Inet6 =>
1230 Sin_V6 : Inet_Addr_V6_Type := (others => 0);
1231 end case;
1232 end record;
1233
1234 Any_Port : constant Port_Type := 0; 1258 Any_Port : constant Port_Type := 0;
1235 No_Port : constant Port_Type := 0; 1259 No_Port : constant Port_Type := 0;
1236 1260
1237 Any_Inet_Addr : constant Inet_Addr_Type := 1261 Any_Inet_Addr : constant Inet_Addr_Type :=
1238 (Family_Inet, (others => 0)); 1262 (Family_Inet, (others => 0));