1275970Scy/* 2275970Scy * Copyright (c) 2010-2012 Niels Provos and Nick Mathewson 3275970Scy * 4275970Scy * Redistribution and use in source and binary forms, with or without 5275970Scy * modification, are permitted provided that the following conditions 6275970Scy * are met: 7275970Scy * 1. Redistributions of source code must retain the above copyright 8275970Scy * notice, this list of conditions and the following disclaimer. 9275970Scy * 2. Redistributions in binary form must reproduce the above copyright 10275970Scy * notice, this list of conditions and the following disclaimer in the 11275970Scy * documentation and/or other materials provided with the distribution. 12275970Scy * 3. The name of the author may not be used to endorse or promote products 13275970Scy * derived from this software without specific prior written permission. 14275970Scy * 15275970Scy * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16275970Scy * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17275970Scy * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18275970Scy * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19275970Scy * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20275970Scy * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21275970Scy * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22275970Scy * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23275970Scy * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24275970Scy * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25275970Scy */ 26275970Scy 27275970Scy#ifndef REGRESS_TESTUTILS_H_INCLUDED_ 28275970Scy#define REGRESS_TESTUTILS_H_INCLUDED_ 29275970Scy 30275970Scy#include "event2/dns.h" 31275970Scy 32275970Scystruct regress_dns_server_table { 33275970Scy const char *q; 34275970Scy const char *anstype; 35275970Scy const char *ans; 36275970Scy int seen; 37275970Scy}; 38275970Scy 39275970Scystruct evdns_server_port * 40275970Scyregress_get_dnsserver(struct event_base *base, 41275970Scy ev_uint16_t *portnum, 42275970Scy evutil_socket_t *psock, 43275970Scy evdns_request_callback_fn_type cb, 44275970Scy void *arg); 45275970Scy 46275970Scy/* Helper: return the port that a socket is bound on, in host order. */ 47275970Scyint regress_get_socket_port(evutil_socket_t fd); 48275970Scy 49275970Scy/* used to look up pre-canned responses in a search table */ 50275970Scyvoid regress_dns_server_cb( 51275970Scy struct evdns_server_request *req, void *data); 52275970Scy 53275970Scy/* globally allocates a dns server that serves from a search table */ 54275970Scyint regress_dnsserver(struct event_base *base, ev_uint16_t *port, 55275970Scy struct regress_dns_server_table *seach_table); 56275970Scy 57275970Scy/* clean up the global dns server resources */ 58275970Scyvoid regress_clean_dnsserver(void); 59275970Scy 60275970Scystruct evconnlistener; 61275970Scystruct sockaddr; 62275970Scyint regress_get_listener_addr(struct evconnlistener *lev, 63275970Scy struct sockaddr *sa, ev_socklen_t *socklen); 64275970Scy 65275970Scy#endif /* REGRESS_TESTUTILS_H_INCLUDED_ */ 66275970Scy 67