struct sockaddr_in *addr = NULL;
struct sockaddr_in6 *addr6 = NULL;
struct nameinfo_query *niquery;
+ unsigned int port = 0;
/* Verify the buffer size */
if (salen == sizeof(struct sockaddr_in))
- addr = (struct sockaddr_in *)sa;
+ {
+ addr = (struct sockaddr_in *)sa;
+ port = addr->sin_port;
+ }
else if (salen == sizeof(struct sockaddr_in6))
- addr6 = (struct sockaddr_in6 *)sa;
+ {
+ addr6 = (struct sockaddr_in6 *)sa;
+ port = addr6->sin6_port;
+ }
else
{
callback(arg, ARES_ENOTIMP, 0, NULL, NULL);
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;
service = lookup_service((unsigned short)(port & 0xffff),
flags, buf, sizeof(buf));
callback(arg, ARES_SUCCESS, 0, NULL, service);
/* A numeric host can be handled without DNS */
if ((flags & ARES_NI_NUMERICHOST))
{
- unsigned int port = 0;
char ipbuf[IPBUFSIZ];
char srvbuf[33];
char *service = NULL;
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
append_scopeid(addr6, flags, ipbuf, sizeof(ipbuf));
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)
{
char *hostname = NULL;
int rc = ARES_SUCCESS;
+#ifdef HAVE_GETHOSTNAME
+ char *dot;
+#endif
if (channel->flags == -1)
channel->flags = 0;
} while(0);
- if (strchr(hostname, '.')) {
+ dot = strchr(hostname, '.');
+ if (dot) {
/* a dot was found */
-
channel->domains = malloc(sizeof(char *));
if (!channel->domains) {
rc = ARES_ENOMEM;
goto error;
}
- channel->domains[0] = strdup(strchr(hostname, '.') + 1);
+ channel->domains[0] = strdup(dot + 1);
if (!channel->domains[0]) {
rc = ARES_ENOMEM;
goto error;
conn->host.name++; /* skip over the starting bracket */
portptr = strchr(conn->host.name, ']');
- *portptr++ = 0; /* zero terminate, killing the bracket */
- if(':' != *portptr)
- portptr = NULL; /* no port number available */
+ if(portptr) {
+ *portptr++ = '\0'; /* zero terminate, killing the bracket */
+ if(':' != *portptr)
+ portptr = NULL; /* no port number available */
+ }
}
else
portptr = strrchr(conn->host.name, ':');