Skip to content

Commit

Permalink
testclient accepts interface name as argument
Browse files Browse the repository at this point in the history
  • Loading branch information
justbuchanan committed Apr 19, 2016
1 parent a1fa849 commit 986b89c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions client/testclient.cc
Expand Up @@ -10,11 +10,21 @@
#include <sys/socket.h>
#include <sys/types.h>

#define MULTICAST_INTERFACE "enp7s0"
#define MULTICAST_ADDRESS "224.5.23.1"
#define MULTICAST_PORT "10003"

int main() {
namespace {
void usage(const char* appName) {
std::cerr << "Usage:\n" << appName << " multicast_interface" << std::endl;
std::exit(EXIT_FAILURE);
}
}

int main(int argc, char** argv) {
if (argc != 2) {
usage(argv[0]);
}

// Get a socket address to bind to.
addrinfo hints;
std::memset(&hints, 0, sizeof(hints));
Expand All @@ -30,7 +40,7 @@ int main() {
}

// Look up the index of the network interface from its name.
unsigned int ifindex = if_nametoindex(MULTICAST_INTERFACE);
unsigned int ifindex = if_nametoindex(argv[1]);
if (!ifindex) {
std::cerr << std::strerror(errno) << '\n';
return 1;
Expand Down

0 comments on commit 986b89c

Please sign in to comment.