2005-11-14 14:26:17 +01:00
|
|
|
/* $Id$ */
|
|
|
|
|
2005-05-16 20:06:54 +02:00
|
|
|
/* Copyright 2005 by Dominick Meglio
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this
|
|
|
|
* software and its documentation for any purpose and without
|
|
|
|
* fee is hereby granted, provided that the above copyright
|
|
|
|
* notice appear in all copies and that both that copyright
|
|
|
|
* notice and this permission notice appear in supporting
|
|
|
|
* documentation, and that the name of M.I.T. not be used in
|
|
|
|
* advertising or publicity pertaining to distribution of the
|
|
|
|
* software without specific, written prior permission.
|
|
|
|
* M.I.T. makes no representations about the suitability of
|
|
|
|
* this software for any purpose. It is provided "as is"
|
|
|
|
* without express or implied warranty.
|
|
|
|
*/
|
|
|
|
#include "setup.h"
|
|
|
|
|
2008-09-17 13:31:37 +02:00
|
|
|
#ifdef HAVE_GETSERVBYPORT_R
|
|
|
|
# if !defined(GETSERVBYPORT_R_ARGS) || \
|
|
|
|
(GETSERVBYPORT_R_ARGS < 4) || (GETSERVBYPORT_R_ARGS > 6)
|
|
|
|
# error "you MUST specifiy a valid number of arguments for getservbyport_r"
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2008-09-15 19:14:29 +02:00
|
|
|
#ifdef HAVE_SYS_SOCKET_H
|
2008-09-17 03:02:57 +02:00
|
|
|
# include <sys/socket.h>
|
2008-09-15 19:14:29 +02:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_NETINET_IN_H
|
2008-09-17 03:02:57 +02:00
|
|
|
# include <netinet/in.h>
|
2008-09-15 19:14:29 +02:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_NETDB_H
|
2008-09-17 03:02:57 +02:00
|
|
|
# include <netdb.h>
|
2008-09-15 19:14:29 +02:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ARPA_INET_H
|
2008-09-17 03:02:57 +02:00
|
|
|
# include <arpa/inet.h>
|
2008-09-15 19:14:29 +02:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ARPA_NAMESER_H
|
2008-09-17 03:02:57 +02:00
|
|
|
# include <arpa/nameser.h>
|
|
|
|
#else
|
|
|
|
# include "nameser.h"
|
2008-09-15 19:14:29 +02:00
|
|
|
#endif
|
2005-05-16 20:06:54 +02:00
|
|
|
#ifdef HAVE_ARPA_NAMESER_COMPAT_H
|
2008-09-17 03:02:57 +02:00
|
|
|
# include <arpa/nameser_compat.h>
|
2005-05-16 20:06:54 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_NET_IF_H
|
|
|
|
#include <net/if.h>
|
|
|
|
#endif
|
|
|
|
|
2005-05-17 06:18:41 +02:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2005-05-16 20:06:54 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "ares.h"
|
|
|
|
#include "ares_ipv6.h"
|
|
|
|
#include "inet_ntop.h"
|
2008-09-11 05:46:47 +02:00
|
|
|
#include "ares_private.h"
|
2005-05-16 20:06:54 +02:00
|
|
|
|
|
|
|
#ifdef WATT32
|
|
|
|
#undef WIN32
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct nameinfo_query {
|
|
|
|
ares_nameinfo_callback callback;
|
|
|
|
void *arg;
|
|
|
|
union {
|
|
|
|
struct sockaddr_in addr4;
|
|
|
|
struct sockaddr_in6 addr6;
|
|
|
|
} addr;
|
|
|
|
int family;
|
|
|
|
int flags;
|
2007-09-28 16:46:51 +02:00
|
|
|
int timeouts;
|
2005-05-16 20:06:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
|
|
|
|
#define IPBUFSIZ 40+IF_NAMESIZE
|
|
|
|
#else
|
|
|
|
#define IPBUFSIZ 40
|
|
|
|
#endif
|
|
|
|
|
2007-09-28 16:46:51 +02:00
|
|
|
static void nameinfo_callback(void *arg, int status, int timeouts, struct hostent *host);
|
2005-12-10 20:21:59 +01:00
|
|
|
static char *lookup_service(unsigned short port, int flags,
|
|
|
|
char *buf, size_t buflen);
|
2005-05-16 21:14:25 +02:00
|
|
|
#ifdef HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
|
2005-11-25 23:14:28 +01:00
|
|
|
static void append_scopeid(struct sockaddr_in6 *addr6, unsigned int scopeid,
|
|
|
|
char *buf, size_t buflen);
|
2005-05-16 21:14:25 +02:00
|
|
|
#endif
|
2005-05-16 20:06:54 +02:00
|
|
|
static char *ares_striendstr(const char *s1, const char *s2);
|
|
|
|
|
2005-12-12 00:37:58 +01:00
|
|
|
void ares_getnameinfo(ares_channel channel, const struct sockaddr *sa, socklen_t salen,
|
2005-05-16 20:06:54 +02:00
|
|
|
int flags, ares_nameinfo_callback callback, void *arg)
|
|
|
|
{
|
2006-10-25 16:16:01 +02:00
|
|
|
struct sockaddr_in *addr = NULL;
|
|
|
|
struct sockaddr_in6 *addr6 = NULL;
|
2005-05-16 20:06:54 +02:00
|
|
|
struct nameinfo_query *niquery;
|
|
|
|
|
|
|
|
/* Verify the buffer size */
|
|
|
|
if (salen == sizeof(struct sockaddr_in))
|
|
|
|
addr = (struct sockaddr_in *)sa;
|
|
|
|
else if (salen == sizeof(struct sockaddr_in6))
|
|
|
|
addr6 = (struct sockaddr_in6 *)sa;
|
|
|
|
else
|
|
|
|
{
|
2007-09-28 16:46:51 +02:00
|
|
|
callback(arg, ARES_ENOTIMP, 0, NULL, NULL);
|
2005-05-16 20:06:54 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If neither, assume they want a host */
|
|
|
|
if (!(flags & ARES_NI_LOOKUPSERVICE) && !(flags & ARES_NI_LOOKUPHOST))
|
|
|
|
flags |= ARES_NI_LOOKUPHOST;
|
|
|
|
|
|
|
|
/* All they want is a service, no need for DNS */
|
|
|
|
if ((flags & ARES_NI_LOOKUPSERVICE) && !(flags & ARES_NI_LOOKUPHOST))
|
|
|
|
{
|
|
|
|
char buf[33], *service;
|
|
|
|
unsigned int port = 0;
|
|
|
|
|
|
|
|
if (salen == sizeof(struct sockaddr_in))
|
|
|
|
port = addr->sin_port;
|
|
|
|
else
|
|
|
|
port = addr6->sin6_port;
|
2007-02-01 16:36:56 +01:00
|
|
|
service = lookup_service((unsigned short)(port & 0xffff),
|
|
|
|
flags, buf, sizeof(buf));
|
2007-09-28 16:46:51 +02:00
|
|
|
callback(arg, ARES_SUCCESS, 0, NULL, service);
|
2005-05-16 20:06:54 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* They want a host lookup */
|
|
|
|
if ((flags & ARES_NI_LOOKUPHOST))
|
|
|
|
{
|
|
|
|
/* A numeric host can be handled without DNS */
|
|
|
|
if ((flags & ARES_NI_NUMERICHOST))
|
|
|
|
{
|
|
|
|
unsigned int port = 0;
|
|
|
|
char ipbuf[IPBUFSIZ];
|
2005-12-10 20:21:59 +01:00
|
|
|
char srvbuf[33];
|
2005-05-16 20:06:54 +02:00
|
|
|
char *service = NULL;
|
|
|
|
ipbuf[0] = 0;
|
|
|
|
|
2005-09-21 12:45:25 +02:00
|
|
|
/* Specifying not to lookup a host, but then saying a host
|
2005-05-16 20:06:54 +02:00
|
|
|
* is required has to be illegal.
|
|
|
|
*/
|
|
|
|
if (flags & ARES_NI_NAMEREQD)
|
|
|
|
{
|
2007-09-28 16:46:51 +02:00
|
|
|
callback(arg, ARES_EBADFLAGS, 0, NULL, NULL);
|
2005-05-16 20:06:54 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (salen == sizeof(struct sockaddr_in6))
|
|
|
|
{
|
|
|
|
ares_inet_ntop(AF_INET6, &addr6->sin6_addr, ipbuf, IPBUFSIZ);
|
|
|
|
port = addr6->sin6_port;
|
|
|
|
/* If the system supports scope IDs, use it */
|
|
|
|
#ifdef HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
|
2005-11-25 23:14:28 +01:00
|
|
|
append_scopeid(addr6, flags, ipbuf, sizeof(ipbuf));
|
2005-05-16 20:06:54 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ares_inet_ntop(AF_INET, &addr->sin_addr, ipbuf, IPBUFSIZ);
|
|
|
|
port = addr->sin_port;
|
|
|
|
}
|
|
|
|
/* They also want a service */
|
|
|
|
if (flags & ARES_NI_LOOKUPSERVICE)
|
2007-02-01 16:36:56 +01:00
|
|
|
service = lookup_service((unsigned short)(port & 0xffff),
|
|
|
|
flags, srvbuf, sizeof(srvbuf));
|
2007-09-28 16:46:51 +02:00
|
|
|
callback(arg, ARES_SUCCESS, 0, ipbuf, service);
|
2005-05-16 20:06:54 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* This is where a DNS lookup becomes necessary */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
niquery = malloc(sizeof(struct nameinfo_query));
|
|
|
|
if (!niquery)
|
|
|
|
{
|
2007-09-28 16:46:51 +02:00
|
|
|
callback(arg, ARES_ENOMEM, 0, NULL, NULL);
|
2005-05-16 20:06:54 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
niquery->callback = callback;
|
|
|
|
niquery->arg = arg;
|
|
|
|
niquery->flags = flags;
|
2007-09-28 16:46:51 +02:00
|
|
|
niquery->timeouts = 0;
|
2005-09-21 12:45:25 +02:00
|
|
|
if (sa->sa_family == AF_INET)
|
2005-05-16 20:06:54 +02:00
|
|
|
{
|
|
|
|
niquery->family = AF_INET;
|
|
|
|
memcpy(&niquery->addr.addr4, addr, sizeof(addr));
|
2005-09-21 12:45:25 +02:00
|
|
|
ares_gethostbyaddr(channel, &addr->sin_addr, sizeof(struct in_addr), AF_INET,
|
2005-05-16 20:06:54 +02:00
|
|
|
nameinfo_callback, niquery);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
niquery->family = AF_INET6;
|
|
|
|
memcpy(&niquery->addr.addr6, addr6, sizeof(addr6));
|
2005-09-21 12:45:25 +02:00
|
|
|
ares_gethostbyaddr(channel, &addr6->sin6_addr, sizeof(struct in6_addr), AF_INET6,
|
2005-05-16 20:06:54 +02:00
|
|
|
nameinfo_callback, niquery);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-28 16:46:51 +02:00
|
|
|
static void nameinfo_callback(void *arg, int status, int timeouts, struct hostent *host)
|
2005-05-16 20:06:54 +02:00
|
|
|
{
|
|
|
|
struct nameinfo_query *niquery = (struct nameinfo_query *) arg;
|
|
|
|
char srvbuf[33];
|
|
|
|
char *service = NULL;
|
|
|
|
|
2007-09-28 16:46:51 +02:00
|
|
|
niquery->timeouts += timeouts;
|
2005-05-16 20:06:54 +02:00
|
|
|
if (status == ARES_SUCCESS)
|
|
|
|
{
|
|
|
|
/* They want a service too */
|
|
|
|
if (niquery->flags & ARES_NI_LOOKUPSERVICE)
|
|
|
|
{
|
|
|
|
if (niquery->family == AF_INET)
|
2005-09-21 12:45:25 +02:00
|
|
|
service = lookup_service(niquery->addr.addr4.sin_port,
|
2005-12-10 20:21:59 +01:00
|
|
|
niquery->flags, srvbuf, sizeof(srvbuf));
|
2005-05-16 20:06:54 +02:00
|
|
|
else
|
2005-09-21 12:45:25 +02:00
|
|
|
service = lookup_service(niquery->addr.addr6.sin6_port,
|
2005-12-10 20:21:59 +01:00
|
|
|
niquery->flags, srvbuf, sizeof(srvbuf));
|
2005-05-16 20:06:54 +02:00
|
|
|
}
|
|
|
|
/* NOFQDN means we have to strip off the domain name portion.
|
|
|
|
We do this by determining our own domain name, then searching the string
|
|
|
|
for this domain name and removing it.
|
|
|
|
*/
|
2008-11-28 23:41:14 +01:00
|
|
|
#ifdef HAVE_GETHOSTNAME
|
2005-05-16 20:06:54 +02:00
|
|
|
if (niquery->flags & ARES_NI_NOFQDN)
|
|
|
|
{
|
|
|
|
char buf[255];
|
|
|
|
char *domain;
|
|
|
|
gethostname(buf, 255);
|
|
|
|
if ((domain = strchr(buf, '.')))
|
|
|
|
{
|
|
|
|
char *end = ares_striendstr(host->h_name, domain);
|
|
|
|
if (end)
|
|
|
|
*end = 0;
|
2005-09-21 12:45:25 +02:00
|
|
|
}
|
2005-05-16 20:06:54 +02:00
|
|
|
}
|
2008-11-28 23:41:14 +01:00
|
|
|
#endif
|
2007-09-28 16:46:51 +02:00
|
|
|
niquery->callback(niquery->arg, ARES_SUCCESS, niquery->timeouts, (char *)(host->h_name),
|
2007-01-29 21:56:27 +01:00
|
|
|
service);
|
2005-05-16 20:06:54 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* We couldn't find the host, but it's OK, we can use the IP */
|
|
|
|
else if (status == ARES_ENOTFOUND && !(niquery->flags & ARES_NI_NAMEREQD))
|
|
|
|
{
|
|
|
|
char ipbuf[IPBUFSIZ];
|
|
|
|
if (niquery->family == AF_INET)
|
|
|
|
ares_inet_ntop(AF_INET, &niquery->addr.addr4.sin_addr, ipbuf, IPBUFSIZ);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ares_inet_ntop(AF_INET6, &niquery->addr.addr6.sin6_addr, ipbuf, IPBUFSIZ);
|
|
|
|
#ifdef HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
|
2005-11-25 23:14:28 +01:00
|
|
|
append_scopeid(&niquery->addr.addr6, niquery->flags, ipbuf, sizeof(ipbuf));
|
2005-05-16 20:06:54 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
/* They want a service too */
|
|
|
|
if (niquery->flags & ARES_NI_LOOKUPSERVICE)
|
|
|
|
{
|
|
|
|
if (niquery->family == AF_INET)
|
2005-09-21 12:45:25 +02:00
|
|
|
service = lookup_service(niquery->addr.addr4.sin_port,
|
2005-12-10 20:21:59 +01:00
|
|
|
niquery->flags, srvbuf, sizeof(srvbuf));
|
2005-05-16 20:06:54 +02:00
|
|
|
else
|
2005-09-21 12:45:25 +02:00
|
|
|
service = lookup_service(niquery->addr.addr6.sin6_port,
|
2005-12-10 20:21:59 +01:00
|
|
|
niquery->flags, srvbuf, sizeof(srvbuf));
|
2005-05-16 20:06:54 +02:00
|
|
|
}
|
2007-10-04 10:09:52 +02:00
|
|
|
niquery->callback(niquery->arg, ARES_SUCCESS, niquery->timeouts, ipbuf, service);
|
2005-05-16 20:06:54 +02:00
|
|
|
return;
|
|
|
|
}
|
2007-10-04 10:09:04 +02:00
|
|
|
niquery->callback(niquery->arg, status, niquery->timeouts, NULL, NULL);
|
2005-05-16 20:06:54 +02:00
|
|
|
free(niquery);
|
|
|
|
}
|
|
|
|
|
2005-09-21 12:45:25 +02:00
|
|
|
static char *lookup_service(unsigned short port, int flags,
|
2005-12-10 20:21:59 +01:00
|
|
|
char *buf, size_t buflen)
|
2005-05-16 20:06:54 +02:00
|
|
|
{
|
2005-12-10 20:21:59 +01:00
|
|
|
const char *proto;
|
|
|
|
struct servent *sep;
|
|
|
|
#ifdef HAVE_GETSERVBYPORT_R
|
|
|
|
struct servent se;
|
|
|
|
#endif
|
|
|
|
char tmpbuf[4096];
|
|
|
|
|
2005-05-16 20:06:54 +02:00
|
|
|
if (port)
|
2006-10-25 16:16:01 +02:00
|
|
|
{
|
2005-05-16 20:06:54 +02:00
|
|
|
if (flags & ARES_NI_NUMERICSERV)
|
2005-12-10 20:21:59 +01:00
|
|
|
sep = NULL;
|
2005-05-16 20:06:54 +02:00
|
|
|
else
|
2006-10-25 16:16:01 +02:00
|
|
|
{
|
2005-05-16 20:06:54 +02:00
|
|
|
if (flags & ARES_NI_UDP)
|
|
|
|
proto = "udp";
|
|
|
|
else if (flags & ARES_NI_SCTP)
|
|
|
|
proto = "sctp";
|
|
|
|
else if (flags & ARES_NI_DCCP)
|
|
|
|
proto = "dccp";
|
|
|
|
else
|
|
|
|
proto = "tcp";
|
2005-09-18 18:44:49 +02:00
|
|
|
#ifdef HAVE_GETSERVBYPORT_R
|
2005-12-10 20:21:59 +01:00
|
|
|
sep = &se;
|
|
|
|
memset(tmpbuf, 0, sizeof(tmpbuf));
|
2005-09-21 12:45:25 +02:00
|
|
|
#if GETSERVBYPORT_R_ARGS == 6
|
2005-12-10 20:21:59 +01:00
|
|
|
if (getservbyport_r(port, proto, &se, (void *)tmpbuf, sizeof(tmpbuf), &sep) != 0)
|
|
|
|
sep = NULL;
|
2005-09-21 12:45:25 +02:00
|
|
|
#elif GETSERVBYPORT_R_ARGS == 5
|
2005-12-10 20:21:59 +01:00
|
|
|
sep = getservbyport_r(port, proto, &se, (void *)tmpbuf, sizeof(tmpbuf));
|
2005-09-21 12:45:25 +02:00
|
|
|
#elif GETSERVBYPORT_R_ARGS == 4
|
2005-12-10 20:21:59 +01:00
|
|
|
if (getservbyport_r(port, proto, &se, (void *)tmpbuf) != 0)
|
|
|
|
sep = NULL;
|
2006-10-25 16:16:01 +02:00
|
|
|
#else
|
2005-09-18 18:44:49 +02:00
|
|
|
/* Lets just hope the OS uses TLS! */
|
2005-12-10 20:21:59 +01:00
|
|
|
sep = getservbyport(port, proto);
|
2006-10-25 16:16:01 +02:00
|
|
|
#endif
|
|
|
|
#else
|
2005-09-21 12:45:25 +02:00
|
|
|
/* Lets just hope the OS uses TLS! */
|
2007-07-03 18:00:36 +02:00
|
|
|
#if (defined(NETWARE) && !defined(__NOVELL_LIBC__))
|
|
|
|
sep = getservbyport(port, (char*)proto);
|
|
|
|
#else
|
2005-12-10 20:21:59 +01:00
|
|
|
sep = getservbyport(port, proto);
|
2007-07-03 18:00:36 +02:00
|
|
|
#endif
|
2006-10-25 16:16:01 +02:00
|
|
|
#endif
|
|
|
|
}
|
2005-12-10 20:21:59 +01:00
|
|
|
if (sep && sep->s_name)
|
|
|
|
/* get service name */
|
|
|
|
strcpy(tmpbuf, sep->s_name);
|
|
|
|
else
|
|
|
|
/* get port as a string */
|
2007-02-05 05:10:32 +01:00
|
|
|
sprintf(tmpbuf, "%u", (unsigned int)ntohs(port));
|
2005-12-10 20:21:59 +01:00
|
|
|
if (strlen(tmpbuf) < buflen)
|
|
|
|
/* return it if buffer big enough */
|
|
|
|
strcpy(buf, tmpbuf);
|
|
|
|
else
|
|
|
|
/* avoid reusing previous one */
|
|
|
|
buf[0] = '\0';
|
2005-05-16 20:06:54 +02:00
|
|
|
return buf;
|
|
|
|
}
|
2005-12-10 20:21:59 +01:00
|
|
|
buf[0] = '\0';
|
2005-05-16 20:06:54 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
|
2005-11-25 23:14:28 +01:00
|
|
|
static void append_scopeid(struct sockaddr_in6 *addr6, unsigned int flags,
|
|
|
|
char *buf, size_t buflen)
|
2005-05-16 20:06:54 +02:00
|
|
|
{
|
2007-02-06 04:31:27 +01:00
|
|
|
#ifdef HAVE_IF_INDEXTONAME
|
|
|
|
int is_ll, is_mcll;
|
|
|
|
#endif
|
2005-11-25 23:14:28 +01:00
|
|
|
char fmt_u[] = "%u";
|
|
|
|
char fmt_lu[] = "%lu";
|
|
|
|
char tmpbuf[IF_NAMESIZE + 2];
|
|
|
|
size_t bufl;
|
|
|
|
char *fmt = (sizeof(addr6->sin6_scope_id) > sizeof(unsigned int))?fmt_lu:fmt_u;
|
2005-05-16 20:06:54 +02:00
|
|
|
|
|
|
|
tmpbuf[0] = '%';
|
2005-11-25 23:14:28 +01:00
|
|
|
|
2005-05-16 20:06:54 +02:00
|
|
|
#ifdef HAVE_IF_INDEXTONAME
|
2007-02-06 04:31:27 +01:00
|
|
|
is_ll = IN6_IS_ADDR_LINKLOCAL(&addr6->sin6_addr);
|
|
|
|
is_mcll = IN6_IS_ADDR_MC_LINKLOCAL(&addr6->sin6_addr);
|
2005-09-21 12:45:25 +02:00
|
|
|
if ((flags & ARES_NI_NUMERICSCOPE) ||
|
2007-02-06 04:31:27 +01:00
|
|
|
(!is_ll && !is_mcll))
|
2005-05-16 20:06:54 +02:00
|
|
|
{
|
2005-11-25 23:14:28 +01:00
|
|
|
sprintf(&tmpbuf[1], fmt, addr6->sin6_scope_id);
|
2005-05-16 20:06:54 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (if_indextoname(addr6->sin6_scope_id, &tmpbuf[1]) == NULL)
|
2005-11-25 23:14:28 +01:00
|
|
|
sprintf(&tmpbuf[1], fmt, addr6->sin6_scope_id);
|
2005-05-16 20:06:54 +02:00
|
|
|
}
|
|
|
|
#else
|
2005-11-25 23:14:28 +01:00
|
|
|
sprintf(&tmpbuf[1], fmt, addr6->sin6_scope_id);
|
2005-11-14 14:26:17 +01:00
|
|
|
(void) flags;
|
2005-05-16 20:06:54 +02:00
|
|
|
#endif
|
2005-11-25 23:14:28 +01:00
|
|
|
tmpbuf[IF_NAMESIZE + 1] = '\0';
|
|
|
|
bufl = strlen(buf);
|
|
|
|
|
|
|
|
if(bufl + strlen(tmpbuf) < buflen)
|
|
|
|
/* only append the scopeid string if it fits in the target buffer */
|
|
|
|
strcpy(&buf[bufl], tmpbuf);
|
2005-05-16 20:06:54 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Determines if s1 ends with the string in s2 (case-insensitive) */
|
|
|
|
static char *ares_striendstr(const char *s1, const char *s2)
|
|
|
|
{
|
|
|
|
const char *c1, *c2, *c1_begin;
|
2007-02-01 02:42:13 +01:00
|
|
|
int lo1, lo2;
|
2005-05-16 20:06:54 +02:00
|
|
|
size_t s1_len = strlen(s1), s2_len = strlen(s2);
|
|
|
|
|
|
|
|
/* If the substr is longer than the full str, it can't match */
|
|
|
|
if (s2_len > s1_len)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Jump to the end of s1 minus the length of s2 */
|
2005-05-17 06:20:58 +02:00
|
|
|
c1_begin = s1+s1_len-s2_len;
|
|
|
|
c1 = (const char *)c1_begin;
|
2005-05-16 20:06:54 +02:00
|
|
|
c2 = s2;
|
|
|
|
while (c2 < s2+s2_len)
|
|
|
|
{
|
2007-02-01 02:42:13 +01:00
|
|
|
lo1 = tolower(*c1);
|
|
|
|
lo2 = tolower(*c2);
|
|
|
|
if (lo1 != lo2)
|
2005-05-16 20:06:54 +02:00
|
|
|
return NULL;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
c1++;
|
|
|
|
c2++;
|
|
|
|
}
|
|
|
|
}
|
2005-05-17 06:18:41 +02:00
|
|
|
if (c2 == c1 && c2 == NULL)
|
2005-05-16 21:14:25 +02:00
|
|
|
return (char *)c1_begin;
|
2005-05-16 20:06:54 +02:00
|
|
|
return NULL;
|
|
|
|
}
|