res_mkquery.c revision e8031f0a8ed0e45c6d8847c5e09424e66fd34a4b
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "c_synonyms.h"
#include <stdio.h>
#include <resolv.h>
#include <errno.h>
#include <netdb.h>
/*
* Kludge to time out quickly if there is no /etc/resolv.conf
* and a TCP connection to the local DNS server fails.
*
* Moved function from res_send.c to res_mkquery.c. This
* solves a long timeout problem with nslookup.
*
* __areweinnamed is needed because there is a possibility that the
* user might do bad things to resolv.conf and cause in.named to call
* _confcheck and deadlock the server.
*/
int __areweinnamed()
{
return (0);
}
static int _confcheck()
{
int ns;
struct sockaddr_in ns_sin;
/* First, we check to see if /etc/resolv.conf exists.
* If it doesn't, then localhost is mostlikely to be
* the nameserver.
*/
/* Next, we check to see if _res.nsaddr is set to loopback.
* If it isn't, it has been altered by the application
* explicitly and we then want to bail with success.
*/
if (__areweinnamed())
return (0);
/* Lastly, we try to connect to the TCP port of the
* nameserver. If this fails, then we know that
* DNS is misconfigured and we can quickly exit.
*/
sizeof ns_sin) == -1) {
return(-1);
}
else {
return(0);
}
}
return(0);
}
return (0);
}
/*
* Form all types of queries.
* Returns the size of the result or -1.
*/
int
int op; /* opcode of query */
char *dname; /* domain name */
char *data; /* resource record data */
int datalen; /* length of data */
char *buf; /* buffer to put query */
int buflen; /* size of buffer */
{
register char *cp;
register int n;
#ifdef DEBUG
#endif /* DEBUG */
/*
* Check to see if we can bailout quickly.
* Also rerun res_init if we failed in the past.
*/
return(-1);
}
if (_confcheck() == -1) {
return(-1);
}
/*
* Initialize header fields.
*/
return (-1);
#ifdef SYSV
#else
#endif
/*
* perform opcode specific processing
*/
switch (op) {
case QUERY:
return (-1);
return (-1);
cp += n;
buflen -= n;
break;
/*
* Make an additional record for completion domain.
*/
return (-1);
cp += n;
buflen -= n;
break;
case IQUERY:
/*
* Initialize answer section
*/
return (-1);
if (datalen) {
#ifdef SYSV
#else
#endif
}
break;
#ifdef ALLOW_UPDATES
/*
* (Record to be modified is followed by its replacement in msg.)
*/
case UPDATEM:
case UPDATEMA:
case UPDATED:
/*
* The res code for UPDATED and UPDATEDA is the same; user
* calls them differently: specifies data for UPDATED; server
* ignores data if specified for UPDATEDA.
*/
case UPDATEDA:
return (-1);
cp += n;
if (datalen) {
#ifdef SYSV
#else
#endif
}
break;
}
case UPDATEA: /* Add new resource record */
return (-1);
cp += n;
#ifdef SYSV
#else
#endif
}
break;
#endif /* ALLOW_UPDATES */
}
}