mirror of
https://github.com/obgm/libcoap.git
synced 2026-12-03 03:01:05 +03:00
multicast: Add in IPv4 and update IPv6 multicast support
include/coap2/net.h: src/net.c: Update code using #587 as a base to fix potential issues. Fixes CID 1502429 CMakeLists.txt: cmake_coap_config.h.in: Test for <net/if.h> examples/coap-rd.c: examples/coap-server.c: man/coap-rd.txt.in: man/coap-server.txt.in: Add in -G option to support specifying interface to use for multicasting. Otherwise, the interface allocated by the O/S is used depending on the address (if any) bound to. man/Makefile.am: man/coap_context.txt.in: Document the coap_join_mcast_group_intf() function. src/coap_debug.c: Make sure that coap_print_addr() returns a NULL terminated buffer.
This commit is contained in:
1 parent
42b2f03470
commit
a34228c80f
11 files changed
+231
-97
No files matched your search
+10
-3
@@ -611,12 +611,15 @@ usage( const char *program, const char *version) {
|
||||
break;
|
||||
}
|
||||
fprintf(stderr, "\n"
|
||||
"Usage: %s [-g group] [-p port] [-v num] [-A address]\n"
|
||||
"Usage: %s [-g group] [-G group_if] [-p port] [-v num] [-A address]\n"
|
||||
"\t [[-h hint] [-k key]]\n"
|
||||
"\t [[-c certfile] [-C cafile] [-n] [-R trust_casfile]]\n"
|
||||
"General Options\n"
|
||||
"\t-g group\tJoin the given multicast group.\n"
|
||||
"\t \t\tNote: DTLS over multicast is not currently supported\n"
|
||||
"\t-G group_if\tUse this interface for listening for the multicast\n"
|
||||
"\t \t\tgroup. This can be different from the implied interface\n"
|
||||
"\t \t\tif the -A option is used\n"
|
||||
"\t-p port\t\tListen on specified port\n"
|
||||
"\t-v num \t\tVerbosity level (default 3, maximum is 9). Above 7,\n"
|
||||
"\t \t\tthere is increased verbosity in GnuTLS and OpenSSL logging\n"
|
||||
@@ -805,13 +808,14 @@ main(int argc, char **argv) {
|
||||
char addr_str[NI_MAXHOST] = "::";
|
||||
char port_str[NI_MAXSERV] = "5683";
|
||||
char *group = NULL;
|
||||
char *group_if = NULL;
|
||||
int opt;
|
||||
coap_log_t log_level = LOG_WARNING;
|
||||
#ifndef _WIN32
|
||||
struct sigaction sa;
|
||||
#endif
|
||||
|
||||
while ((opt = getopt(argc, argv, "A:c:C:g:h:k:n:R:p:v:")) != -1) {
|
||||
while ((opt = getopt(argc, argv, "A:c:C:g:G:h:k:n:R:p:v:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'A' :
|
||||
strncpy(addr_str, optarg, NI_MAXHOST-1);
|
||||
@@ -826,6 +830,9 @@ main(int argc, char **argv) {
|
||||
case 'g' :
|
||||
group = optarg;
|
||||
break;
|
||||
case 'G' :
|
||||
group_if = optarg;
|
||||
break;
|
||||
case 'h' :
|
||||
if (!optarg[0]) {
|
||||
hint = NULL;
|
||||
@@ -869,7 +876,7 @@ main(int argc, char **argv) {
|
||||
return -1;
|
||||
|
||||
if (group)
|
||||
coap_join_mcast_group_intf(ctx, group, NULL);
|
||||
coap_join_mcast_group_intf(ctx, group, group_if);
|
||||
|
||||
init_resources(ctx);
|
||||
|
||||
|
||||
+12
-4
@@ -2187,8 +2187,8 @@ usage( const char *program, const char *version) {
|
||||
break;
|
||||
}
|
||||
fprintf(stderr, "\n"
|
||||
"Usage: %s [-d max] [-e] [-g group] [-l loss] [-p port] [-v num]\n"
|
||||
"\t\t[-A address] [-L value] [-N]\n"
|
||||
"Usage: %s [-d max] [-e] [-g group] [-G group_if] [-l loss] [-p port]\n"
|
||||
"\t\t[-v num] [-A address] [-L value] [-N]\n"
|
||||
"\t\t[-P scheme://address[:port],name1[,name2..]]\n"
|
||||
"\t\t[[-h hint] [-i match_identity_file] [-k key]\n"
|
||||
"\t\t[-s match_psk_sni_file] [-u user]]\n"
|
||||
@@ -2201,6 +2201,10 @@ usage( const char *program, const char *version) {
|
||||
"\t \t\tuntil one of the dynamic resources has been deleted\n"
|
||||
"\t-e \t\tEcho back the data sent with a PUT\n"
|
||||
"\t-g group\tJoin the given multicast group\n"
|
||||
"\t \t\tNote: DTLS over multicast is not currently supported\n"
|
||||
"\t-G group_if\tUse this interface for listening for the multicast\n"
|
||||
"\t \t\tgroup. This can be different from the implied interface\n"
|
||||
"\t \t\tif the -A option is used\n"
|
||||
"\t-l list\t\tFail to send some datagrams specified by a comma\n"
|
||||
"\t \t\tseparated list of numbers or number ranges\n"
|
||||
"\t \t\t(for debugging only)\n"
|
||||
@@ -2630,6 +2634,7 @@ int
|
||||
main(int argc, char **argv) {
|
||||
coap_context_t *ctx;
|
||||
char *group = NULL;
|
||||
char *group_if = NULL;
|
||||
coap_tick_t now;
|
||||
char addr_str[NI_MAXHOST] = "::";
|
||||
char port_str[NI_MAXSERV] = "5683";
|
||||
@@ -2653,7 +2658,7 @@ main(int argc, char **argv) {
|
||||
|
||||
clock_offset = time(NULL);
|
||||
|
||||
while ((opt = getopt(argc, argv, "c:d:eg:h:i:j:J:k:l:mnp:s:u:v:A:C:L:M:NP:R:S:")) != -1) {
|
||||
while ((opt = getopt(argc, argv, "c:d:eg:G:h:i:j:J:k:l:mnp:s:u:v:A:C:L:M:NP:R:S:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'A' :
|
||||
strncpy(addr_str, optarg, NI_MAXHOST-1);
|
||||
@@ -2674,6 +2679,9 @@ main(int argc, char **argv) {
|
||||
case 'g' :
|
||||
group = optarg;
|
||||
break;
|
||||
case 'G' :
|
||||
group_if = optarg;
|
||||
break;
|
||||
case 'h' :
|
||||
if (!optarg[0]) {
|
||||
hint = NULL;
|
||||
@@ -2784,7 +2792,7 @@ main(int argc, char **argv) {
|
||||
sizeof(cache_ignore_options)/sizeof(cache_ignore_options[0]));
|
||||
/* join multicast group if requested at command line */
|
||||
if (group)
|
||||
coap_join_mcast_group_intf(ctx, group, NULL);
|
||||
coap_join_mcast_group_intf(ctx, group, group_if);
|
||||
|
||||
coap_fd = coap_context_get_coap_fd(ctx);
|
||||
if (coap_fd != -1) {
|
||||
|
||||
Reference in new issue
Block a user