| 1151 | #endif |
| 1152 | |
| 1153 | static void |
| 1154 | rtrlist() |
| 1155 | { |
| 1156 | int mib[] = { CTL_NET, PF_INET6, IPPROTO_ICMPV6, ICMPV6CTL_ND6_DRLIST }; |
| 1157 | char *buf; |
| 1158 | struct in6_defrouter *p, *ep; |
| 1159 | size_t l; |
| 1160 | struct timeval now; |
| 1161 | |
| 1162 | if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), NULL, &l, NULL, 0) < 0) { |
| 1163 | err(1, "sysctl(ICMPV6CTL_ND6_DRLIST)"); |
| 1164 | /*NOTREACHED*/ |
| 1165 | } |
| 1166 | if (l == 0) |
| 1167 | return; |
| 1168 | buf = malloc(l); |
| 1169 | if (!buf) { |
| 1170 | err(1, "malloc"); |
| 1171 | /*NOTREACHED*/ |
| 1172 | } |
| 1173 | if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), buf, &l, NULL, 0) < 0) { |
| 1174 | err(1, "sysctl(ICMPV6CTL_ND6_DRLIST)"); |
| 1175 | /*NOTREACHED*/ |
| 1176 | } |
| 1177 | |
| 1178 | ep = (struct in6_defrouter *)(buf + l); |
| 1179 | for (p = (struct in6_defrouter *)buf; p < ep; p++) { |
| 1180 | int rtpref; |
| 1181 | #ifndef FSTACK |
| 1182 | if (getnameinfo((struct sockaddr *)&p->rtaddr, |
| 1183 | p->rtaddr.sin6_len, host_buf, sizeof(host_buf), NULL, 0, |
| 1184 | (nflag ? NI_NUMERICHOST : 0)) != 0) |
| 1185 | #else |
| 1186 | if (inet_ntop(AF_INET6_LINUX, &p->rtaddr.sin6_addr, host_buf, sizeof(host_buf)) == NULL) |
| 1187 | #endif |
| 1188 | strlcpy(host_buf, "?", sizeof(host_buf)); |
| 1189 | |
| 1190 | printf("%s if=%s", host_buf, |
| 1191 | if_indextoname(p->if_index, ifix_buf)); |
| 1192 | printf(", flags=%s%s", |
| 1193 | p->flags & ND_RA_FLAG_MANAGED ? "M" : "", |
| 1194 | p->flags & ND_RA_FLAG_OTHER ? "O" : ""); |
| 1195 | #ifdef DRAFT_IETF_6MAN_IPV6ONLY_FLAG |
| 1196 | printf("%s", p->flags & ND_RA_FLAG_IPV6_ONLY ? "S" : ""); |
| 1197 | #endif |
| 1198 | rtpref = ((p->flags & ND_RA_FLAG_RTPREF_MASK) >> 3) & 0xff; |
| 1199 | printf(", pref=%s", rtpref_str[rtpref]); |
| 1200 | |
| 1201 | gettimeofday(&now, 0); |
| 1202 | if (p->expire == 0) |
| 1203 | printf(", expire=Never\n"); |
| 1204 | else |
| 1205 | printf(", expire=%s\n", |
| 1206 | sec2str(p->expire - now.tv_sec)); |
| 1207 | } |
| 1208 | free(buf); |
| 1209 | } |
| 1210 | |