c - how do I get a remote global link addr by it's local-link addr? -


i routing information protocol(rip) packet, , can link-local addr of source router packet. cannot set route link-local addr, need global link addr of source router. how should write code in c? thanks. made try, doesn't work.

#include <sys/types.h> #include <sys/socket.h> #include <netdb.h> #include <stdio.h> #include <string.h> int main () { int sockfd;   struct addrinfo hints, *servinfo, *p; int rv; char str[inet6_addrstrlen] = ""; char port[] = "521"; char addr[] ="fe80::a00:27ff:fe22:4d87"; struct sockaddr_in6 sa;  memset(&hints, 0, sizeof hints); hints.ai_family = af_inet6; hints.ai_socktype = sock_dgram; //inet_pton(af_inet6, "fe80::a00:27ff:fe22:4d87", &(sa.sin6_addr)); //hints.ai_addr = (void *)&sa; hints.ai_flags = ai_numerichost;  if ((rv = getaddrinfo(addr, null, &hints, &servinfo)) != 0) {     fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));     return 0; } for(p = servinfo; p != null; p = p->ai_next) {     if (p->ai_family == af_inet6) {         inet_ntop(af_inet6, (struct in6_addr *)p->ai_addr->sa_data, str, inet6_addrstrlen);         printf("%s\n", str);     } }  freeaddrinfo(servinfo); // done structure return 0; 

}

two things:

  • you cannot global address link-local address, unrelated
  • you can route using link-local addresses

routing using link-local addresses no problem @ all. thing have remember explicitly state outgoing interface in addition link-local next hop address.

here few lines local routing table (this mac os x, concept same i.e. linux , windows):

internet6: destination         gateway                         flags    netif expire default             fe80::222:83ff:feb5:964b%en0    ugc      en0 ::1                 link#1                          uhl      lo0 2a00:8640:1::/64    link#4                          uc       en0 

as can see default gateway fe80::222:83ff:feb5:964b%en0. pc learned router advertisement.

in routing next-hop (or gateway) address literally used determine next hop. on ethernet next-hop ipv6 address used mac address on local lan packet should sent, , using link-local address no problem @ all. global address used, not required. if don't have it: use link-local address.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -