1968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#ifndef __ARES_PRIVATE_H 2968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#define __ARES_PRIVATE_H 3968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 4968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 5968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold/* Copyright 1998 by the Massachusetts Institute of Technology. 6968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold * Copyright (C) 2004-2010 by Daniel Stenberg 7968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold * 8968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold * Permission to use, copy, modify, and distribute this 9968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold * software and its documentation for any purpose and without 10968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold * fee is hereby granted, provided that the above copyright 11968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold * notice appear in all copies and that both that copyright 12968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold * notice and this permission notice appear in supporting 13968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold * documentation, and that the name of M.I.T. not be used in 14968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold * advertising or publicity pertaining to distribution of the 15968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold * software without specific, written prior permission. 16968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold * M.I.T. makes no representations about the suitability of 17968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold * this software for any purpose. It is provided "as is" 18968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold * without express or implied warranty. 19968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold */ 20968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 21968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold/* 22968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold * Define WIN32 when build target is Win32 API 23968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold */ 24968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 25968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32) 26968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#define WIN32 27968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#endif 28968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 29968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#include <stdio.h> 30968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#include <sys/types.h> 31968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 32968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#ifdef HAVE_NETINET_IN_H 33968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#include <netinet/in.h> 34968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#endif 35968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 36968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#ifdef WATT32 37968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#include <tcp.h> 38968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#include <sys/ioctl.h> 39968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#define writev(s,v,c) writev_s(s,v,c) 40968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#define HAVE_WRITEV 1 41968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#endif 42968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 43968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#ifdef NETWARE 44968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#include <time.h> 45968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#endif 46968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 47968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#define DEFAULT_TIMEOUT 5000 /* milliseconds */ 48968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#define DEFAULT_TRIES 4 49968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#ifndef INADDR_NONE 50968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#define INADDR_NONE 0xffffffff 51968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#endif 52968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 53968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#if defined(WIN32) && !defined(WATT32) 54968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 55968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#define WIN_NS_9X "System\\CurrentControlSet\\Services\\VxD\\MSTCP" 56968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#define WIN_NS_NT_KEY "System\\CurrentControlSet\\Services\\Tcpip\\Parameters" 57968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#define NAMESERVER "NameServer" 58968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#define DHCPNAMESERVER "DhcpNameServer" 59968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#define DATABASEPATH "DatabasePath" 60968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#define WIN_PATH_HOSTS "\\hosts" 61968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 62968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#elif defined(WATT32) 63968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 64968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#define PATH_RESOLV_CONF "/dev/ENV/etc/resolv.conf" 65968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 66968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#elif defined(NETWARE) 67968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 68968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#define PATH_RESOLV_CONF "sys:/etc/resolv.cfg" 69968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#define PATH_HOSTS "sys:/etc/hosts" 70968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 71968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#elif defined(__riscos__) 72968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 73968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#define PATH_HOSTS "InetDBase:Hosts" 74968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 75968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#else 76968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 77968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#define PATH_RESOLV_CONF "/etc/resolv.conf" 78968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#ifdef ETC_INET 79968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#define PATH_HOSTS "/etc/inet/hosts" 80968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#else 81968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#define PATH_HOSTS "/etc/hosts" 82968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#endif 83968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 84968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#endif 85968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 86968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#define ARES_ID_KEY_LEN 31 87968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 88968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#include "ares_ipv6.h" 89968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#include "ares_llist.h" 90968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 91968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#ifndef HAVE_GETENV 92968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold# include "ares_getenv.h" 93968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold# define getenv(ptr) ares_getenv(ptr) 94968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#endif 95968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 96968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#ifndef HAVE_STRDUP 97968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold# include "ares_strdup.h" 98968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold# define strdup(ptr) ares_strdup(ptr) 99968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#endif 100968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 101968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#ifndef HAVE_STRCASECMP 102968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold# include "ares_strcasecmp.h" 103968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold# define strcasecmp(p1,p2) ares_strcasecmp(p1,p2) 104968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#endif 105968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 106968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#ifndef HAVE_STRNCASECMP 107968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold# include "ares_strcasecmp.h" 108968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold# define strncasecmp(p1,p2,n) ares_strncasecmp(p1,p2,n) 109968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#endif 110968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 111968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#ifndef HAVE_WRITEV 112968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold# include "ares_writev.h" 113968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold# define writev(s,ptr,cnt) ares_writev(s,ptr,cnt) 114968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#endif 115968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 116968bf19396ad404e89420f5d67900fce13f4186cGilad Arnoldstruct ares_addr { 117968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold int family; 118968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold union { 119968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold struct in_addr addr4; 120968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold struct ares_in6_addr addr6; 121968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold } addr; 122968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold}; 123968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#define addrV4 addr.addr4 124968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#define addrV6 addr.addr6 125968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 126968bf19396ad404e89420f5d67900fce13f4186cGilad Arnoldstruct query; 127968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 128968bf19396ad404e89420f5d67900fce13f4186cGilad Arnoldstruct send_request { 129968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold /* Remaining data to send */ 130968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold const unsigned char *data; 131968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold size_t len; 132968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 133968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold /* The query for which we're sending this data */ 134968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold struct query* owner_query; 135968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold /* The buffer we're using, if we have our own copy of the packet */ 136968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold unsigned char *data_storage; 137968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 138968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold /* Next request in queue */ 139968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold struct send_request *next; 140968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold}; 141968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 142968bf19396ad404e89420f5d67900fce13f4186cGilad Arnoldstruct server_state { 143968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold struct ares_addr addr; 144968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold ares_socket_t udp_socket; 145968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold ares_socket_t tcp_socket; 146968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 147968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold /* Mini-buffer for reading the length word */ 148968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold unsigned char tcp_lenbuf[2]; 149968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold int tcp_lenbuf_pos; 150968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold int tcp_length; 151968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 152968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold /* Buffer for reading actual TCP data */ 153968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold unsigned char *tcp_buffer; 154968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold int tcp_buffer_pos; 155968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 156968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold /* TCP output queue */ 157968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold struct send_request *qhead; 158968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold struct send_request *qtail; 159968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 160968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold /* Which incarnation of this connection is this? We don't want to 161968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold * retransmit requests into the very same socket, but if the server 162968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold * closes on us and we re-open the connection, then we do want to 163968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold * re-send. */ 164968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold int tcp_connection_generation; 165968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 166968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold /* Circular, doubly-linked list of outstanding queries to this server */ 167968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold struct list_node queries_to_server; 168968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 169968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold /* Link back to owning channel */ 170968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold ares_channel channel; 171968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 172968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold /* Is this server broken? We mark connections as broken when a 173968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold * request that is queued for sending times out. 174968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold */ 175968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold int is_broken; 176968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold}; 177968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 178968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold/* State to represent a DNS query */ 179968bf19396ad404e89420f5d67900fce13f4186cGilad Arnoldstruct query { 180968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold /* Query ID from qbuf, for faster lookup, and current timeout */ 181968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold unsigned short qid; 182968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold struct timeval timeout; 183968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 184968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold /* 185968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold * Links for the doubly-linked lists in which we insert a query. 186968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold * These circular, doubly-linked lists that are hash-bucketed based 187968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold * the attributes we care about, help making most important 188968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold * operations O(1). 189968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold */ 190968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold struct list_node queries_by_qid; /* hopefully in same cache line as qid */ 191968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold struct list_node queries_by_timeout; 192968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold struct list_node queries_to_server; 193968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold struct list_node all_queries; 194968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 195968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold /* Query buf with length at beginning, for TCP transmission */ 196968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold unsigned char *tcpbuf; 197968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold int tcplen; 198968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 199968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold /* Arguments passed to ares_send() (qbuf points into tcpbuf) */ 200968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold const unsigned char *qbuf; 201968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold int qlen; 202968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold ares_callback callback; 203968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold void *arg; 204968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 205968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold /* Query status */ 206968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold int try_count; /* Number of times we tried this query already. */ 207968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold int server; /* Server this query has last been sent to. */ 208968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold struct query_server_info *server_info; /* per-server state */ 209968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold int using_tcp; 210968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold int error_status; 211968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold int timeouts; /* number of timeouts we saw for this request */ 212968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold}; 213968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 214968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold/* Per-server state for a query */ 215968bf19396ad404e89420f5d67900fce13f4186cGilad Arnoldstruct query_server_info { 216968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold int skip_server; /* should we skip server, due to errors, etc? */ 217968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold int tcp_connection_generation; /* into which TCP connection did we send? */ 218968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold}; 219968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 220968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold/* An IP address pattern; matches an IP address X if X & mask == addr */ 221968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#define PATTERN_MASK 0x1 222968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#define PATTERN_CIDR 0x2 223968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 224968bf19396ad404e89420f5d67900fce13f4186cGilad Arnoldstruct apattern { 225968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold union 226968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold { 227968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold struct in_addr addr4; 228968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold struct ares_in6_addr addr6; 229968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold } addr; 230968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold union 231968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold { 232968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold struct in_addr addr4; 233968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold struct ares_in6_addr addr6; 234968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold unsigned short bits; 235968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold } mask; 236968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold int family; 237968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold unsigned short type; 238968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold}; 239968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 240968bf19396ad404e89420f5d67900fce13f4186cGilad Arnoldtypedef struct rc4_key 241968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold{ 242968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold unsigned char state[256]; 243968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold unsigned char x; 244968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold unsigned char y; 245968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold} rc4_key; 246968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 247968bf19396ad404e89420f5d67900fce13f4186cGilad Arnoldstruct ares_channeldata { 248968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold /* Configuration data */ 249968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold int flags; 250968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold int timeout; /* in milliseconds */ 251968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold int tries; 252968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold int ndots; 253968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold int rotate; /* if true, all servers specified are used */ 254968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold int udp_port; 255968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold int tcp_port; 256968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold int socket_send_buffer_size; 257968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold int socket_receive_buffer_size; 258968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold char **domains; 259968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold int ndomains; 260968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold struct apattern *sortlist; 261968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold int nsort; 262968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold char *lookups; 263968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 264968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold /* For binding to local devices and/or IP addresses. Leave 265968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold * them null/zero for no binding. 266968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold */ 267968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold char local_dev_name[32]; 268968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold unsigned int local_ip4; 269968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold unsigned char local_ip6[16]; 270968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 271968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold int optmask; /* the option bitfield passed in at init time */ 272968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 273968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold /* Server addresses and communications state */ 274968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold struct server_state *servers; 275968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold int nservers; 276968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 277968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold /* ID to use for next query */ 278968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold unsigned short next_id; 279968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold /* key to use when generating new ids */ 280968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold rc4_key id_key; 281968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 282968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold /* Generation number to use for the next TCP socket open/close */ 283968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold int tcp_connection_generation; 284968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 285968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold /* The time at which we last called process_timeouts(). Uses integer seconds 286968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold just to draw the line somewhere. */ 287968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold time_t last_timeout_processed; 288968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 289968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold /* Last server we sent a query to. */ 290968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold int last_server; 291968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 292968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold /* Circular, doubly-linked list of queries, bucketed various ways.... */ 293968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold /* All active queries in a single list: */ 294968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold struct list_node all_queries; 295968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold /* Queries bucketed by qid, for quickly dispatching DNS responses: */ 296968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#define ARES_QID_TABLE_SIZE 2048 297968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold struct list_node queries_by_qid[ARES_QID_TABLE_SIZE]; 298968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold /* Queries bucketed by timeout, for quickly handling timeouts: */ 299968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#define ARES_TIMEOUT_TABLE_SIZE 1024 300968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold struct list_node queries_by_timeout[ARES_TIMEOUT_TABLE_SIZE]; 301968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 302968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold ares_sock_state_cb sock_state_cb; 303968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold void *sock_state_cb_data; 304968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 305968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold ares_sock_create_callback sock_create_cb; 306968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold void *sock_create_cb_data; 307968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold}; 308968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 309968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold/* return true if now is exactly check time or later */ 310968bf19396ad404e89420f5d67900fce13f4186cGilad Arnoldint ares__timedout(struct timeval *now, 311968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold struct timeval *check); 312968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold/* add the specific number of milliseconds to the time in the first argument */ 313968bf19396ad404e89420f5d67900fce13f4186cGilad Arnoldint ares__timeadd(struct timeval *now, 314968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold int millisecs); 315968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold/* return time offset between now and (future) check, in milliseconds */ 316968bf19396ad404e89420f5d67900fce13f4186cGilad Arnoldlong ares__timeoffset(struct timeval *now, 317968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold struct timeval *check); 318968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold/* returns ARES_SUCCESS if library has been initialized */ 319968bf19396ad404e89420f5d67900fce13f4186cGilad Arnoldint ares_library_initialized(void); 320968bf19396ad404e89420f5d67900fce13f4186cGilad Arnoldvoid ares__rc4(rc4_key* key,unsigned char *buffer_ptr, int buffer_len); 321968bf19396ad404e89420f5d67900fce13f4186cGilad Arnoldvoid ares__send_query(ares_channel channel, struct query *query, 322968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold struct timeval *now); 323968bf19396ad404e89420f5d67900fce13f4186cGilad Arnoldvoid ares__close_sockets(ares_channel channel, struct server_state *server); 324968bf19396ad404e89420f5d67900fce13f4186cGilad Arnoldint ares__get_hostent(FILE *fp, int family, struct hostent **host); 325968bf19396ad404e89420f5d67900fce13f4186cGilad Arnoldint ares__read_line(FILE *fp, char **buf, size_t *bufsize); 326968bf19396ad404e89420f5d67900fce13f4186cGilad Arnoldvoid ares__free_query(struct query *query); 327968bf19396ad404e89420f5d67900fce13f4186cGilad Arnoldunsigned short ares__generate_new_id(rc4_key* key); 328968bf19396ad404e89420f5d67900fce13f4186cGilad Arnoldstruct timeval ares__tvnow(void); 329968bf19396ad404e89420f5d67900fce13f4186cGilad Arnoldint ares__expand_name_for_response(const unsigned char *encoded, 330968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold const unsigned char *abuf, int alen, 331968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold char **s, long *enclen); 332968bf19396ad404e89420f5d67900fce13f4186cGilad Arnoldvoid ares__init_servers_state(ares_channel channel); 333968bf19396ad404e89420f5d67900fce13f4186cGilad Arnoldvoid ares__destroy_servers_state(ares_channel channel); 334968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#if 0 /* Not used */ 335968bf19396ad404e89420f5d67900fce13f4186cGilad Arnoldlong ares__tvdiff(struct timeval t1, struct timeval t2); 336968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#endif 337968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 338968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#define ARES_SWAP_BYTE(a,b) \ 339968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold { unsigned char swapByte = *(a); *(a) = *(b); *(b) = swapByte; } 340968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 341968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#define SOCK_STATE_CALLBACK(c, s, r, w) \ 342968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold do { \ 343968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold if ((c)->sock_state_cb) \ 344968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold (c)->sock_state_cb((c)->sock_state_cb_data, (s), (r), (w)); \ 345968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold } while (0) 346968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 347968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#ifdef CURLDEBUG 348968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold/* This is low-level hard-hacking memory leak tracking and similar. Using the 349968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold libcurl lowlevel code from within library is ugly and only works when 350968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold c-ares is built and linked with a similarly curldebug-enabled libcurl, 351968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold but we do this anyway for convenience. */ 352968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#include "../lib/memdebug.h" 353968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#endif 354968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold 355968bf19396ad404e89420f5d67900fce13f4186cGilad Arnold#endif /* __ARES_PRIVATE_H */ 356