FreeBSD/sbin/ipfw/ipv6.c
/*
 * Print the ip address contained in a command.
 */
Print the ip address contained in a command.
Print the ip address contained in a command .
void
print_ip6(struct buf_pr *bp, ipfw_insn_ip6 *cmd, char const *s)
{
       struct hostent *he = NULL;
       int len = F_LEN((ipfw_insn *) cmd) - 1;
       struct in6_addr *a = &(cmd->addr6);
       char trad[255];
       bprintf(bp, "%s%s ", cmd->o.len & F_NOT ? " not": "", s);
       if (cmd->o.opcode == O_IP6_SRC_ME || cmd->o.opcode == O_IP6_DST_ME) {
	       bprintf(bp, "me6");
	       return;
       }
       if (cmd->o.opcode == O_IP6) {
	       bprintf(bp, " ip6");
	       return;
       }
       for (len = len / 4; len > 0; len -= 2, a += 2) {
	   int mb =	
	       (cmd->o.opcode == O_IP6_SRC || cmd->o.opcode == O_IP6_DST) ?
	       128 : contigmask((uint8_t *)&(a[1]), 128);
	   if (mb == 128 && co.do_resolv)
	       he = gethostbyaddr((char *)a, sizeof(*a), AF_INET6);
	   if (he != NULL)	     
	       bprintf(bp, "%s", he->h_name);
	   else if (mb == 0)	   
	       bprintf(bp, "any");
	   else {	  
	       if (inet_ntop(AF_INET6,  a, trad, sizeof( trad ) ) == NULL)
		   bprintf(bp, "Error ntop in print_ip6\n");
	       bprintf(bp, "%s",  trad );
	       if (mb < 0)     
		   bprintf(bp, ":%s",
		       inet_ntop(AF_INET6, &a[1], trad, sizeof(trad)));
	       else if (mb < 128)
		   bprintf(bp, "/%d", mb);
	   }
	   if (len > 2)
	       bprintf(bp, ",");
       }
}
void print_ip6 ( struct buf_pr * bp , ipfw_insn_ip6 * cmd , char const * s ) { struct hostent * he = NULL ; int len = F_LEN ( ( ipfw_insn * ) cmd ) - 1 ; struct in6_addr * a = & ( cmd -> addr6 ) ; char trad [ 255 ] ; bprintf ( bp , " " , cmd -> o . len & F_NOT ? " " : " " , s ) ; if ( cmd -> o . opcode == O_IP6_SRC_ME || cmd -> o . opcode == O_IP6_DST_ME ) { bprintf ( bp , " " ) ; return ; } if ( cmd -> o . opcode == O_IP6 ) { bprintf ( bp , " " ) ; return ; } for ( len = len / 4 ; len > 0 ; len -= 2 , a += 2 ) { int mb = ( cmd -> o . opcode == O_IP6_SRC || cmd -> o . opcode == O_IP6_DST ) ? 128 : contigmask ( ( uint8_t * ) & ( a [ 1 ] ) , 128 ) ; if ( mb == 128 && co . do_resolv ) he = gethostbyaddr ( ( char * ) a , sizeof ( * a ) , AF_INET6 ) ; if ( he != NULL ) bprintf ( bp , " " , he -> h_name ) ; else if ( mb == 0 ) bprintf ( bp , " " ) ; else { if ( inet_ntop ( AF_INET6 , a , trad , sizeof ( trad ) ) == NULL ) bprintf ( bp , " \n " ) ; bprintf ( bp , " " , trad ) ; if ( mb < 0 ) bprintf ( bp , " " , inet_ntop ( AF_INET6 , & a [ 1 ] , trad , sizeof ( trad ) ) ) ; else if ( mb < 128 ) bprintf ( bp , " " , mb ) ; } if ( len > 2 ) bprintf ( bp , " " ) ; } }
Print the ip address contained in a command.
Print the ip address contained in a command .
/*
	* len == 4 indicates a single IP, whereas lists of 1 or more
	* addr/mask pairs have len = (2n+1). We convert len to n so we
	* use that to count the number of entries.
	*/ /* mask length */ /* resolved to name */ /* any */ /* numeric IP followed by some kind of mask */ /* XXX not really legal... */