]>
git.proxmox.com Git - mirror_frr.git/blob - pimd/test_igmpv3_join.c
3 Copyright (C) 2008 Everton da Silva Marques
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
20 $QuaggaId: $Format:%an, %ai, %h$ $
30 #include <sys/types.h>
31 #include <sys/socket.h>
33 #include <arpa/inet.h>
36 #include "pim_igmp_join.h"
38 const char *prog_name
= 0;
40 static int iface_solve_index(const char *ifname
)
42 struct if_nameindex
*ini
;
43 ifindex_t ifindex
= -1;
53 "%s: interface=%s: failure solving index: errno=%d: %s\n",
54 prog_name
, ifname
, err
, strerror(err
));
59 for (i
= 0; ini
[i
].if_index
; ++i
) {
62 "%s: interface=%s matching against local ifname=%s ifindex=%d\n",
63 prog_name
, ifname
, ini
[i
].if_name
, ini
[i
].if_index
);
65 if (!strcmp(ini
[i
].if_name
, ifname
)) {
66 ifindex
= ini
[i
].if_index
;
71 if_freenameindex(ini
);
76 int main(int argc
, const char *argv
[])
78 struct in_addr group_addr
;
79 struct in_addr source_addr
;
89 fd
= socket(AF_INET
, SOCK_DGRAM
, IPPROTO_UDP
);
92 "%s: could not create socket: socket(): errno=%d: %s\n",
93 prog_name
, errno
, strerror(errno
));
99 "usage: %s interface group source\n"
100 "example: %s eth0 232.1.1.1 1.1.1.1\n",
101 prog_name
, prog_name
);
109 ifindex
= iface_solve_index(ifname
);
111 fprintf(stderr
, "%s: could not find interface: %s\n",
116 result
= inet_pton(AF_INET
, group
, &group_addr
);
118 fprintf(stderr
, "%s: bad group address: %s\n",
123 result
= inet_pton(AF_INET
, source
, &source_addr
);
125 fprintf(stderr
, "%s: bad source address: %s\n",
130 result
= pim_igmp_join_source(fd
, ifindex
, group_addr
, source_addr
);
133 "%s: setsockopt(fd=%d) failure for IGMP group %s source %s ifindex %d on interface %s: errno=%d: %s\n",
134 prog_name
, fd
, group
, source
, ifindex
, ifname
,
135 errno
, strerror(errno
));
139 printf("%s: joined channel (S,G)=(%s,%s) on interface %s\n",
140 prog_name
, source
, group
, ifname
);
142 printf("%s: waiting...\n", prog_name
);
148 printf("%s: left channel (S,G)=(%s,%s) on interface %s\n",
149 prog_name
, source
, group
, ifname
);