1---------------------------------------------------------------- 2-- IRONSIDES - DNS SERVER 3-- 4-- By: Martin C. Carlisle and Barry S. Fagin 5-- Department of Computer Science 6-- United States Air Force Academy 7-- 8-- This is free software; you can redistribute it and/or 9-- modify without restriction. We do ask that you please keep 10-- the original author information, and clearly indicate if the 11-- software has been modified. 12-- 13-- This software is distributed in the hope that it will be useful, 14-- but WITHOUT ANY WARRANTY; without even the implied warranty 15-- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 16---------------------------------------------------------------- 17 18with DNS_Types; 19WITH Gnat.Sockets; 20--# inherit DNS_Types,System; 21package DNS_Network 22--# own protected Network : Network_Type; 23is 24 --# type Network_Type is abstract; 25 -- how long do we allow a receive/send to occur before we timeout 26 Socket_Timeout_Milliseconds : CONSTANT := 2_000; 27 Max_Query_Size : CONSTANT := 311; 28 29 type Network_Address_and_Port is limited private; 30 type DNS_Socket is private; 31 32 procedure Initialize_TCP; 33 --# global in out Network; 34 --# derives Network from Network; 35 36 procedure Initialize_UDP; 37 --# global in out Network; 38 --# derives Network from Network; 39 40 procedure Get_Connection_TCP( 41 Socket : out DNS_Socket); 42 --# global in out Network; 43 --# derives Network from * & Socket from Network; 44 45 -- post condition comes from DNS_Network_Receive 46 procedure Receive_DNS_Packet_TCP 47 (Packet : out DNS_Types.DNS_Tcp_Packet; 48 Number_Bytes : out DNS_Types.Packet_Length_Range; 49 Socket : in DNS_Socket; 50 Failure : out Boolean); 51 --# global in out Network; 52 --# derives Network, Packet, Number_Bytes, Failure from Network, Socket; 53 54 procedure Send_DNS_Packet_Tcp 55 (Packet : in out DNS_Types.DNS_Tcp_Packet; 56 Number_Bytes : in DNS_Types.Packet_Length_Range; 57 Socket : in DNS_Socket; 58 Failure : out Boolean); 59 --# global in out Network; 60 --# derives Failure,Network from Network, Packet, Number_Bytes, Socket & 61 --# Packet from Network; 62 --# pre Integer(Number_Bytes) > DNS_Types.Header_Bits/8; 63 --# post System.Default_Bit_Order=System.High_Order_First -> Packet = Packet~; 64 65 -- Reads a single UDP packet from network on port 53 66 -- Last is the number of bytes read (assuming no failure) 67 -- post condition comes from DNS_Network_Receive 68 procedure Receive_DNS_Packet( 69 Packet : out DNS_Types.DNS_Packet; 70 Number_Bytes : out DNS_Types.Packet_Length_Range; 71 Reply_Address : out Network_Address_and_Port; 72 Failure : out Boolean); 73 --# global in out Network; 74 --# derives Network, Packet, Number_Bytes, Reply_Address, Failure from Network; 75 76 -- send a single UDP DNS reply packet to the given address 77 -- Last is number of bytes to send 78 procedure Send_DNS_Packet(Packet : in out DNS_Types.DNS_Packet; 79 Number_Bytes : in DNS_Types.Packet_Length_Range; 80 To_Address : in Network_Address_and_Port; 81 Failure : out Boolean); 82 --# global in out Network; 83 --# derives Failure,Network from Network, Packet, Number_Bytes, To_Address & 84 --# Packet from Network; 85 --# pre Integer(Number_Bytes) > DNS_Types.Header_Bits/8; 86 --# post System.Default_Bit_Order=System.High_Order_First -> Packet = Packet~; 87 88 procedure Discard_Socket(Socket : in DNS_Socket); 89 --# global in out Network; 90 --# derives Network from *, Socket; 91PRIVATE 92 --# hide DNS_Network 93 type Network_Address_And_Port is new Gnat.Sockets.Sock_Addr_Type; 94 type DNS_Socket is new Gnat.Sockets.Socket_Type; 95end DNS_Network; 96 97