interface: fix IPV6 hostname buffer deallocation from automatics

The host buffer that hostname pointed to is no longer on the
stack by the time the SECURE() message is printed.  So make it
static and thus accessible to all.  We won't be calling this
stuff in the middle of a child process/thread/task, so there's
no

Also, hostname is a constant string we shouldn't modify, so mark
it as const char *.

git-svn-id: https://svn.musicpd.org/mpd/trunk@6842 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
Eric Wong 2007-09-01 12:20:49 +00:00
parent c5c8548ba2
commit c2e742106f

View File

@ -254,7 +254,6 @@ static void closeInterface(Interface * interface)
void openAInterface(int fd, struct sockaddr *addr) void openAInterface(int fd, struct sockaddr *addr)
{ {
char *hostname;
int i; int i;
for (i = 0; i < interface_max_connections for (i = 0; i < interface_max_connections
@ -264,28 +263,24 @@ void openAInterface(int fd, struct sockaddr *addr)
ERROR("Max Connections Reached!\n"); ERROR("Max Connections Reached!\n");
xclose(fd); xclose(fd);
} else { } else {
const char *hostname;
switch (addr->sa_family) { switch (addr->sa_family) {
case AF_INET: case AF_INET:
{ hostname = (const char *)inet_ntoa(((struct sockaddr_in *)
char *host = inet_ntoa(((struct sockaddr_in *)
addr)->sin_addr); addr)->sin_addr);
if (host) { if (!hostname)
hostname = host;
} else {
hostname = "error getting ipv4 address"; hostname = "error getting ipv4 address";
}
}
break; break;
#ifdef HAVE_IPV6 #ifdef HAVE_IPV6
case AF_INET6: case AF_INET6:
{ {
char host[INET6_ADDRSTRLEN + 1]; static char host[INET6_ADDRSTRLEN + 1];
memset(host, 0, INET6_ADDRSTRLEN + 1); memset(host, 0, INET6_ADDRSTRLEN + 1);
if (inet_ntop(AF_INET6, (void *) if (inet_ntop(AF_INET6, (void *)
&(((struct sockaddr_in6 *)addr)-> &(((struct sockaddr_in6 *)addr)->
sin6_addr), host, sin6_addr), host,
INET6_ADDRSTRLEN)) { INET6_ADDRSTRLEN)) {
hostname = host; hostname = (const char *)host;
} else { } else {
hostname = "error getting ipv6 address"; hostname = "error getting ipv6 address";
} }