1 | ----------------------------------------------------------------------------- |
---|
2 | -- -- |
---|
3 | -- ADASOCKETS COMPONENTS -- |
---|
4 | -- -- |
---|
5 | -- S O C K E T S . U T I L S -- |
---|
6 | -- -- |
---|
7 | -- B o d y -- |
---|
8 | -- -- |
---|
9 | -- $ReleaseVersion: 0.1.3 $ -- |
---|
10 | -- -- |
---|
11 | -- Copyright (C) 1998 Ãcole Nationale Supérieure des Télécommunications -- |
---|
12 | -- -- |
---|
13 | -- AdaSockets is free software; you can redistribute it and/or modify -- |
---|
14 | -- it under terms of the GNU General Public License as published by -- |
---|
15 | -- the Free Software Foundation; either version 2, or (at your option) -- |
---|
16 | -- any later version. AdaSockets is distributed in the hope that it -- |
---|
17 | -- will be useful, but WITHOUT ANY WARRANTY; without even the implied -- |
---|
18 | -- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -- |
---|
19 | -- See the GNU General Public License for more details. You should -- |
---|
20 | -- have received a copy of the GNU General Public License distributed -- |
---|
21 | -- with AdaSockets; see file COPYING. If not, write to the Free -- |
---|
22 | -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- |
---|
23 | -- 02111-1307, USA. -- |
---|
24 | -- -- |
---|
25 | -- As a special exception, if other files instantiate generics from -- |
---|
26 | -- this unit, or you link this unit with other files to produce an -- |
---|
27 | -- executable, this unit does not by itself cause the resulting -- |
---|
28 | -- executable to be covered by the GNU General Public License. This -- |
---|
29 | -- exception does not however invalidate any other reasons why the -- |
---|
30 | -- executable file might be covered by the GNU Public License. -- |
---|
31 | -- -- |
---|
32 | -- The main repository for this software is located at: -- |
---|
33 | -- http://www-inf.enst.fr/ANC/ -- |
---|
34 | -- -- |
---|
35 | ----------------------------------------------------------------------------- |
---|
36 | |
---|
37 | with Ada.Exceptions; use Ada.Exceptions; |
---|
38 | with GNAT.OS_Lib; use GNAT.OS_Lib; |
---|
39 | with System; use System; |
---|
40 | |
---|
41 | package body Sockets.Utils is |
---|
42 | |
---|
43 | use Interfaces.C; |
---|
44 | |
---|
45 | --------------------- |
---|
46 | -- Port_To_Network -- |
---|
47 | --------------------- |
---|
48 | |
---|
49 | function Port_To_Network (Port : unsigned_short) |
---|
50 | return unsigned_short |
---|
51 | is |
---|
52 | begin |
---|
53 | if Default_Bit_Order = High_Order_First then |
---|
54 | return Port; |
---|
55 | else |
---|
56 | return (Port / 256) + (Port mod 256) * 256; |
---|
57 | end if; |
---|
58 | end Port_To_Network; |
---|
59 | |
---|
60 | ------------------------ |
---|
61 | -- Raise_With_Message -- |
---|
62 | ------------------------ |
---|
63 | |
---|
64 | procedure Raise_With_Message (Message : in String; |
---|
65 | With_Errno : in Boolean := True) |
---|
66 | is |
---|
67 | begin |
---|
68 | if With_Errno then |
---|
69 | Raise_Exception (Constraint_Error'Identity, |
---|
70 | Message & " (errno is" & Integer'Image (Errno) & |
---|
71 | ")"); |
---|
72 | else |
---|
73 | Raise_Exception (Constraint_Error'Identity, Message); |
---|
74 | end if; |
---|
75 | |
---|
76 | -- The following line works around a bug in GNAT that does not |
---|
77 | -- recognize Ada.Exceptions.Raise_Exception as raising an exception, |
---|
78 | -- even if it can compute statically that the occurrence cannot |
---|
79 | -- be Null_Occurrence ??? |
---|
80 | |
---|
81 | raise Program_Error; |
---|
82 | end Raise_With_Message; |
---|
83 | |
---|
84 | end Sockets.Utils; |
---|