Sto provando a scrivere un server Web in ascolto su entrambi gli indirizzi IPv4 e IPv6. Tuttavia, il codice che ho originariamente scritto non funzionava. Poi ho scoperto che le strutture IPv6 funzionano sia per IPv4 che per IPv6. Quindi ora utilizzo le strutture IPv6, ma funzionano solo gli indirizzi IPv4. Questo post, why can't i bind ipv6 socket to a linklocal address, che ha detto di aggiungere server.sin6_scope_id = 5;
così ho fatto ma non accetta ancora connessioni telnet IPv6. Qualsiasi aiuto sarebbe molto apprezzato perché sono completamente sconcertato.
Grazie!Binding Socket to IPv6 Addresses
Il mio codice è qui sotto:
void initialize_server(int port, int connections, char* address)
{
struct sockaddr_in6 socket_struct;
/*Creates the socket*/
if ((sock_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
{
syslog(LOG_ERR, "%s\n", strerror(errno));
exit(EXIT_FAILURE);
}/*Ends the socket creation*/
/*Populates the socket address structure*/
socket_struct.sin6_family = AF_INET6;
if(address == NULL)
socket_struct.sin6_addr=in6addr_any;
else
{
inet_pton(AF_INET6, "fe80::216:3eff:fec3:3c22", (void *)&socket_struct.sin6_addr.s6_addr);
}
socket_struct.sin6_port =htons(port);
socket_struct.sin6_scope_id = 0;
if (bind(sock_fd, (struct sockaddr*) &socket_struct, sizeof(socket_struct)) < 0)
{
syslog(LOG_ERR, "%s\n", strerror(errno));
exit(EXIT_FAILURE);
}//Ends the binding.
if (listen(sock_fd, connections) <0)
{
syslog(LOG_ERR, "%s\n", strerror(errno));
exit(EXIT_FAILURE);
}//Ends the listening function
}//ends the initialize server function.
quello che so ipv6 è a 64 bit, quindi i server che utilizzano ipv6 devono essere in esecuzione su sistemi operativi a 64 bit. basta usare ipv4 per ora, ci sono un sacco di problemi usando ipv6 finora. – GiantHornet
@GiantHornet: IPv6 non è né a 32 bit né a 64 bit; può funzionare anche su altri sistemi. –
@GiantHornet sì, non penso che sia giusto perché la mia macchina Ubuntu è i686 che è a 32 bit e ha un indirizzo IPv6 – tpar44