1 /*
2  * DNS Reply Tool (drool)
3  *
4  * Copyright (c) 2017-2018, OARC, Inc.
5  * Copyright (c) 2017, Comcast Corporation
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in
17  *    the documentation and/or other materials provided with the
18  *    distribution.
19  *
20  * 3. Neither the name of the copyright holder nor the names of its
21  *    contributors may be used to endorse or promote products derived
22  *    from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #ifndef __drool_query_h
39 #define __drool_query_h
40 
41 #include <sys/types.h>
42 #include <sys/socket.h>
43 #include <netinet/in.h>
44 
45 typedef struct drool_query drool_query_t;
46 struct drool_query {
47     unsigned short is_udp : 1;
48     unsigned short is_tcp : 1;
49     unsigned short have_ipv4 : 1;
50     unsigned short have_ipv6 : 1;
51     unsigned short have_port : 1;
52     unsigned short have_raw : 1;
53 
54     union {
55         struct in_addr  ip_dst;
56         struct in6_addr ip6_dst;
57     } addr;
58     uint16_t port;
59 
60     u_char  small[64];
61     u_char* raw;
62     size_t  length;
63 };
64 
65 drool_query_t* query_new(void);
66 void query_free(drool_query_t* query);
67 
68 int query_is_udp(const drool_query_t* query);
69 int query_is_tcp(const drool_query_t* query);
70 int query_have_ipv4(const drool_query_t* query);
71 int query_have_ipv6(const drool_query_t* query);
72 int query_have_port(const drool_query_t* query);
73 int query_have_raw(const drool_query_t* query);
74 
75 const struct in_addr* query_ip(const drool_query_t* query);
76 const struct in6_addr* query_ip6(const drool_query_t* query);
77 uint16_t query_port(const drool_query_t* query);
78 size_t query_length(const drool_query_t* query);
79 const u_char* query_raw(const drool_query_t* query);
80 
81 int query_set_udp(drool_query_t* query);
82 int query_set_tcp(drool_query_t* query);
83 int query_set_ip(drool_query_t* query, const struct in_addr* addr);
84 int query_set_ip6(drool_query_t* query, const struct in6_addr* addr);
85 int query_set_port(drool_query_t* query, uint16_t port);
86 int query_set_raw(drool_query_t* query, const u_char* raw, size_t length);
87 
88 #endif /* __drool_query_h */
89