4 * Copyright (C) 2004, 2007 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 2000, 2001 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: netaddr_multicast.c,v 1.12 2007/06/19 23:47:00 tbox Exp */
28 #include <isc/netaddr.h>
29 #include <isc/string.h>
30 #include <isc/types.h>
35 TESTDECL(netaddr_multicast
);
40 isc_boolean_t is_multicast
;
43 static t_addr_t addrs
[] = {
44 { AF_INET
, "1.2.3.4", ISC_FALSE
},
45 { AF_INET
, "4.3.2.1", ISC_FALSE
},
46 { AF_INET
, "224.1.1.1", ISC_TRUE
},
47 { AF_INET
, "1.1.1.244", ISC_FALSE
},
48 { AF_INET6
, "::1", ISC_FALSE
},
49 { AF_INET6
, "ff02::1", ISC_TRUE
}
51 #define NADDRS (sizeof(addrs) / sizeof(t_addr_t))
53 static isc_result_t
to_netaddr(t_addr_t
*, isc_netaddr_t
*);
56 to_netaddr(t_addr_t
*addr
, isc_netaddr_t
*na
) {
61 switch (addr
->family
) {
63 r
= inet_pton(AF_INET
, addr
->addr
, (unsigned char *)&in
);
65 return (ISC_R_FAILURE
);
66 isc_netaddr_fromin(na
, &in
);
69 r
= inet_pton(AF_INET6
, addr
->addr
, (unsigned char *)&in6
);
71 return (ISC_R_FAILURE
);
72 isc_netaddr_fromin6(na
, &in6
);
75 return (ISC_R_UNEXPECTED
);
78 return (ISC_R_SUCCESS
);
82 netaddr_multicast(void) {
91 for (i
= 0; i
< NADDRS
; i
++) {
93 result
= to_netaddr(addr
, &na
);
94 if (result
!= ISC_R_SUCCESS
) {
95 printf("I:to_netaddr() returned %s on item %u\n",
96 isc_result_totext(result
), i
);
99 tf
= isc_netaddr_ismulticast(&na
);
100 if (tf
== addr
->is_multicast
) {
101 printf("I:%s is%s multicast (PASSED)\n",
102 (addr
->addr
), (tf
? "" : " not"));
104 printf("I:%s is%s multicast (FAILED)\n",
105 (addr
->addr
), (tf
? "" : " not"));