- DE0CEC9CED66F9D083E9C7DD1F2E02586E36481701F3B8C988F500F521454DC8CA51797961E1E773EDFFB7A96AD6D9B4F277B47AAB056B7E313C23B8677BAFF3+ 84814D47643F564F51FE5A03835B373812EE8902FA209175522DE3B447C11916C8457B747FEE05B87F05BD9C2C172000717B1621A22999E457E7BC5C4250A1B4udp/libudp/udp.adb(18 . 9)(18 . 29)
44 ------------------------------------------------------------------------------
45
46 package body UDP is
47
48 -- Bit-level compare of 2 payloads, returns number of different bits
49 function Bit_Compare(A: in Payload; B: in Payload) return Natural is
50 V : Unsigned_8;
51 Count : Natural := 0;
52 begin
53 for I in Payload'Range loop
54 -- obtain bits that are different
55 V := A(I) xor B(I);
56 -- count the bits that are 1, if any
57 Counting_Loop:
58 while V /= 0 loop
59 Count := Count + Natural((V and Unsigned_8(1)));
60 V := Shift_Right(V, 1);
61 end loop Counting_Loop;
62 end loop;
63
64 return Count;
65 end Bit_Compare;
66
67 -- Generate a human representation of a (local-endian) IP Address
68 function IP_To_String(IP : in IP_Address) return IP_Address_Text is
69 function IP_To_String(IP : in IP_Address)
70 return IP_Address_Text is
71 Text : IP_Address_Text := (others => ' ');
72 begin
73 Unix_UDP_IP_To_String(IP, Text'Address, Text'Length);
(94 . 10)(114 . 10)
75 Close_Socket(S);
76 raise UDP_Failed_Transmit;
77 when others =>
78 -- No eggog, but must check if sent all bytes:
79 if (Result /= Payload'Length) then
80 Close_Socket(S);
81 raise UDP_Truncated_Send;
82 if Result /= Payload'Length then
83 -- fail as message was truncated/not sent in full
84 Close_Socket(S);
85 raise UDP_Truncated_Send;
86 end if;
87 end case;
88 end Transmit;
(107 . 7)(127 . 7)
90 procedure Receive(S : in out Socket;
91 Origin : out Endpoint;
92 Payload_Buf : out Payload;
93 Valid : out Boolean) is
94 Recv_Len : out Unsigned_32) is
95
96 -- Scratch pad (if not successful, the call has no outputs)
97 Incoming_Payload : aliased Payload := (others => 0);
(121 . 7)(141 . 8)
99 Payload_Buf => Incoming_Payload'Address,
100 Payload_Len => Payload'Length);
101 begin
102 Valid := False;
103 -- Valid := False;
104 Recv_Len := 0;
105 case Result is
106 when -1 =>
107 Close_Socket(S);
(133 . 9)(154 . 10)
109 Payload_Buf := Incoming_Payload;
110
111 -- Was a full-length payload?
112 if (Result = Payload'Length) then
113 Valid := True;
114 end if;
115 --if (Result = Payload'Length) then
116 -- Valid := True;
117 --end if;
118 Recv_Len := Unsigned_32( Result );
119 end case;
120 end Receive;
121