1 /* Copyright (c) 2007 Google Inc. 2 * 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef DNSWALL_QUERY_RECORD_H_ 17 #define DNSWALL_QUERY_RECORD_H_ 18 19 #include <netinet/in.h> 20 21 // State of a pending query. 22 typedef struct { 23 int id; // The id of this query. 24 int old_id; // The query's original id field. 25 struct sockaddr_in src_addr; // The query's original source. 26 } QueryRecord; 27 28 // Call once at program startup to initalize the heap of query records. 29 void InitQueryRecordHeap(); 30 31 // Allocates a QueryRecord with a random id. If too many QueryRecords are 32 // allocated, the records will be reused in a manner to ensure the randomness of 33 // their ids. 34 QueryRecord* AllocQueryRecord(); 35 36 // Return a QueryRecord to the pool of unallocated QueryRecords. 37 void FreeQueryRecord(QueryRecord* record); 38 39 // Retrieve a QueryRecord by |id|. If the QueryRecord is not allocated, this 40 // function will return NULL. 41 QueryRecord* GetQueryRecordById(int id); 42 43 #endif // DNSWALL_QUERY_RECORD_H_ 44 45