Embora eu ainda não tenha conseguido fazer com que o apache se vincule a um único endereço que não pertence a uma interface, fiz um programa C de teste que funciona e pode vincular a qualquer endereço IPv6 , independentemente de o endereço pertencer a uma interface:
/*
Test program to bind to an IPv6 address not owned by an interface.
This code is from public domain sources, and is released into the public domain.
*/
#include <arpa/inet.h>
#include <error.h>
#include <errno.h>
#include <net/if.h>
#include <netinet/in.h> // also includes bits/in.h
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h> // also includes bits/ioctls.h
#include <sys/socket.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
// A real address to use as a sanity check and make sure the program can
// bind to an address which *is* owned by an interface
#define REALADDR {{{0x2a,0x00, ...}}}
// A fake address to show the program can bind to an address which is *not*
// owned by any interface
#define SOMEADDR {{{0x20,0x01, 0x0d,0xb8, 0x00,0x00, 0x00,0x00, \
0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x01 }}}
int main(int argc, char *argv[])
{
struct sockaddr_in6 serv_addr;
int listenfd = 0, connfd = 0, i;
char sendBuff[1025];
time_t ticks;
listenfd = socket(AF_INET6, SOCK_STREAM, 0);
printf("socket fd is %d\n", listenfd);
memset(&serv_addr, 0, sizeof(serv_addr));
memset(sendBuff, 0, sizeof(sendBuff));
serv_addr.sin6_family = AF_INET6;
serv_addr.sin6_port = htons(5000);
struct in6_addr someaddr = SOMEADDR;
serv_addr.sin6_addr = someaddr;
// Here's the magic:
int opt = 1;
if (setsockopt(listenfd, SOL_IP, IP_FREEBIND, &opt, sizeof(opt)) < 0)
error(1, errno, "setsockopt(IP_FREEBIND) failed");
printf("Binding to ");
for (i = 0; i < 14; i += 2)
printf("%x:", (serv_addr.sin6_addr.s6_addr[i] << 8) +
serv_addr.sin6_addr.s6_addr[i+1]);
printf("%x\n", (serv_addr.sin6_addr.s6_addr[14] << 8) +
serv_addr.sin6_addr.s6_addr[15]);
if (bind(listenfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0)
error(1, errno, "bind failed");
if (listen(listenfd, 10) < 0)
error(1, errno, "listen failed");
while(1)
{
connfd = accept(listenfd, (struct sockaddr*)NULL, NULL);
printf("accept returned %d\n", connfd);
// Send some data - the current date and time.
ticks = time(NULL);
snprintf(sendBuff, sizeof(sendBuff), "Now is %.24s\r\n", ctime(&ticks));
write(connfd, sendBuff, strlen(sendBuff));
close(connfd);
sleep(1);
}
}