* Print the ip address contained in a command. */
| 89 | * Print the ip address contained in a command. |
| 90 | */ |
| 91 | void |
| 92 | print_ip6(struct buf_pr *bp, const ipfw_insn_ip6 *cmd) |
| 93 | { |
| 94 | char trad[255]; |
| 95 | struct hostent *he = NULL; |
| 96 | const struct in6_addr *a = &(cmd->addr6); |
| 97 | int len, mb; |
| 98 | |
| 99 | len = F_LEN((const ipfw_insn *)cmd) - 1; |
| 100 | if (cmd->o.opcode == O_IP6_SRC_ME || cmd->o.opcode == O_IP6_DST_ME) { |
| 101 | bprintf(bp, " me6"); |
| 102 | return; |
| 103 | } |
| 104 | if (cmd->o.opcode == O_IP6) { |
| 105 | bprintf(bp, " ip6"); |
| 106 | return; |
| 107 | } |
| 108 | |
| 109 | /* |
| 110 | * len == 4 indicates a single IP, whereas lists of 1 or more |
| 111 | * addr/mask pairs have len = (2n+1). We convert len to n so we |
| 112 | * use that to count the number of entries. |
| 113 | */ |
| 114 | bprintf(bp, " "); |
| 115 | for (len = len / 4; len > 0; len -= 2, a += 2) { |
| 116 | /* mask length */ |
| 117 | mb = (cmd->o.opcode == O_IP6_SRC || |
| 118 | cmd->o.opcode == O_IP6_DST) ? 128: |
| 119 | contigmask((const uint8_t *)&(a[1]), 128); |
| 120 | |
| 121 | #ifndef FSTACK |
| 122 | if (mb == 128 && g_co.do_resolv) |
| 123 | he = gethostbyaddr((const char *)a, sizeof(*a), |
| 124 | AF_INET6); |
| 125 | |
| 126 | if (he != NULL) /* resolved to name */ |
| 127 | bprintf(bp, "%s", he->h_name); |
| 128 | else if (mb == 0) /* any */ |
| 129 | #else |
| 130 | if (mb == 0) /* any */ |
| 131 | #endif |
| 132 | bprintf(bp, "any"); |
| 133 | else { /* numeric IP followed by some kind of mask */ |
| 134 | if (inet_ntop(AF_INET6_LINUX, a, trad, |
| 135 | sizeof(trad)) == NULL) |
| 136 | bprintf(bp, "Error ntop in print_ip6\n"); |
| 137 | bprintf(bp, "%s", trad ); |
| 138 | if (mb < 0) /* mask not contiguous */ |
| 139 | bprintf(bp, "/%s", inet_ntop(AF_INET6_LINUX, &a[1], |
| 140 | trad, sizeof(trad))); |
| 141 | else if (mb < 128) |
| 142 | bprintf(bp, "/%d", mb); |
| 143 | } |
| 144 | if (len > 2) |
| 145 | bprintf(bp, ","); |
| 146 | } |
| 147 | } |
| 148 |
no test coverage detected