I'm trying to send some random datagram to host www.google.fr to both ipv4 and ipv6 interfaces, this work fine for ipv4 but not for ipv6. I wanted to do it with a single not-connected socket via UDP protocol.
I did something using getaddrinfo, and sendto function but when I call sendto on ipv6 interfaces, it fails and print "network is unreachable".
int main() {
int s = socket(AF_INET6, SOCK_DGRAM, 0);
char test[4];
struct addrinfo hints = {0};
hints.ai_family = AF_INET6;
hints.ai_socktype = SOCK_DGRAM;
hints.ai_protocol = 0;
hints.ai_flags = AI_V4MAPPED|AI_ALL;
struct addrinfo* res = {0};
struct addrinfo* list;
int exit_status = getaddrinfo("www.google.fr","8080", &hints, &res);
if (exit_status != 0){
perror("getaddrinfo:");
return EXIT_FAILURE;
}
for (list = res; list != NULL; list = list->ai_next) {
if (list->ai_family == AF_INET6) {
printf("AF_INET6\n");
int rc = sendto(s, test, 4, MSG_MORE, list->ai_addr, sizeof(*list->ai_addr));
if (rc < 0) {
perror("PROBLEME ... ");
}
}
}
return EXIT_SUCCESS;
}
I Expect no perror printing but I get network is unreacheable. I would like to know why this dont work someone any idea ?