byacc,flex
client6_addr.c ++#define _PATH_PROCNET_DEV "/proc/net/dev" ++/** ++ * for IPv6 Only Mode ++ */ ++char *get_name(char *name, char *p) ++{ ++ /* Extract <name>[:<alias>] from nul-terminated p where p matches ++ <name>[:<alias>]: after leading whitespace. ++ If match is not made, set name empty and return unchanged p */ ++ int namestart=0, nameend=0, aliasend; ++ while (isspace(p[namestart])) ++ namestart++; ++ nameend=namestart; ++ while (p[nameend] && p[nameend]!=':' && !isspace(p[nameend])) ++ nameend++; ++ if (p[nameend]==':') { ++ aliasend=nameend+1; ++ while (p[aliasend] && isdigit(p[aliasend])) ++ aliasend++; ++ if (p[aliasend]==':') { ++ nameend=aliasend; ++ } ++ if ((nameend-namestart)<IF_NAMESIZE) { ++ memcpy(name,&p[namestart],nameend-namestart); ++ name[nameend-namestart]='\0'; ++ p=&p[nameend]; ++ } else { ++ /* Interface name too large */ ++ name[0]='\0'; ++ } ++ } else { ++ /* first ':' not found - return empty */ ++ name[0]='\0'; ++ } ++ return p + 1; ++} ++ ++int ++create_iaid(struct iaid_table *iaidtab, int num_device) ++{ ++ struct iaid_table *temp = iaidtab; ++ char buff[1024]; ++ char buf[512]; ++ struct ifconf ifc; ++ struct ifreq *ifr,*ifr6; ++ int i; ++ int sock6fd; ++ FILE *fh; ++ ++ ifc.ifc_len = sizeof(buff); ++ ifc.ifc_buf = buff; ++ ++ // _PATH_PROCNET_DEV is path to /proc/dev/net ++ fh = fopen(_PATH_PROCNET_DEV,"r"); ++ if (!fh) { ++ fprintf(stderr,"Cannot open %s\n", _PATH_PROCNET_DEV); ++ return -1; ++ } ++ fgets(buf, sizeof buf, fh); //delete first line of _PATH_PROCNET_DEV ++ fgets(buf, sizeof buf, fh); //delete second line of _PATH_PROCNET_DEV ++ ++ while (fgets(buf, sizeof buf, fh)) { ++ char *s, name[128]; ++ s = get_name(name, buf); ++ //fprintf(stderr,"%s\n",name); ++ if (!strcmp(name, "lo")) continue; ++ temp->hwaddr.len = gethwid(temp->hwaddr.data, sizeof(temp->hwaddr.data), name, &temp->hwaddr.type); ++ switch (temp->hwaddr.type) { ++ case ARPHRD_ETHER: ++ case ARPHRD_IEEE802: ++ memcpy(&temp->iaid, temp->hwaddr.data, sizeof(temp->iaid)); ++ break; ++ case ARPHRD_PPP: ++ temp->iaid = do_hash(ifr->ifr_name,sizeof(ifr->ifr_name)) ++ + if_nametoindex(ifr->ifr_name); ++ fprintf(stderr, "ifr->ifr_name is %s\n",ifr->ifr_name); ++ fprintf(stderr, "temp->iaid is %d",temp->iaid); ++ break; ++ default: ++ dprintf(LOG_INFO, "doesn't support %s address family %d", ++ ifr->ifr_name, temp->hwaddr.type); ++ continue; ++ } ++ dprintf(LOG_DEBUG, "%s"" create iaid %u for interface %s", ++ FNAME, temp->iaid, ifr->ifr_name); ++ num_device++; ++ temp++; ++ ++ } ++ fclose(fh); ++ return num_device; ++} netlink.c - case IFLA_INET6_CACHEINFO: - break;