在所有接口上侦听多播

发布于 2024-11-09 19:17:56 字数 3457 浏览 0 评论 0原文

我有以下接口:

ifconfig
bond0     Link encap:Ethernet  HWaddr 1C:C1:DE:1F:71:CA  
          inet addr:10.3.3.13  Bcast:10.3.3.255  Mask:255.255.255.0
          inet6 addr: fe80::1ec1:deff:fe1f:71ca/64 Scope:Link
          UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
          RX packets:39972916 errors:0 dropped:0 overruns:0 frame:0
          TX packets:21849588 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:60630723698 (56.4 GiB)  TX bytes:1570500163 (1.4 GiB)

eth0      Link encap:Ethernet  HWaddr 1C:C1:DE:1F:71:CA  
          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:39959516 errors:0 dropped:0 overruns:0 frame:0
          TX packets:21849585 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:60629214902 (56.4 GiB)  TX bytes:1570499971 (1.4 GiB)
          Interrupt:16 Memory:f2000000-f2012800 

eth1      Link encap:Ethernet  HWaddr 1C:C1:DE:1F:71:CA  
          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:13400 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1508796 (1.4 MiB)  TX bytes:192 (192.0 b)
          Interrupt:17 Memory:f0000000-f0012800 

eth5      Link encap:Ethernet  HWaddr 00:0F:53:07:50:7D  
          inet addr:90.206.66.13  Bcast:90.206.66.255  Mask:255.255.255.0
          inet6 addr: fe80::f:5300:107:507d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:8590042795 errors:0 dropped:4 overruns:0 frame:0
          TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:8308671 (7.9 MiB)  TX bytes:1132 (1.1 KiB)
          Interrupt:39 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:10 errors:0 dropped:0 overruns:0 frame:0
          TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:700 (700.0 b)  TX bytes:700 (700.0 b)

我有以下多播代码要监听:

  socket_file_descriptor_ = socket ( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
  int flag_on = 1;
  if ( ( setsockopt ( socket_file_descriptor_, SOL_SOCKET, SO_REUSEADDR, &flag_on,
                        sizeof(flag_on) ) ) < 0 )
      { exit(1); }

  struct ip_mreq mc_req;
  inet_pton ( AF_INET, listen_ip_.c_str(), &(mc_req.imr_multiaddr.s_addr) ); 
  mc_req.imr_interface.s_addr = htonl(INADDR_ANY);
  if ( ( setsockopt ( socket_file_descriptor_, IPPROTO_IP, IP_ADD_MEMBERSHIP, 
                            (void*) &mc_req, sizeof(mc_req))) < 0) 
  { exit(1); } 

  {
    struct sockaddr_in mcast_Addr;
    bzero ( &mcast_Addr, sizeof(mcast_Addr) );
    mcast_Addr.sin_family = AF_INET;
    mcast_Addr.sin_addr.s_addr = htonl(INADDR_ANY);
    mcast_Addr.sin_port = htons ( listen_port_ );
    /* bind to specified port onany interface */
    if ( bind ( socket_file_descriptor_, (struct sockaddr *) &mcast_Addr, sizeof ( struct sockaddr_in ) ) < 0 )
      { exit(1); }
  }
  // then recvfrom ( socket_file_descriptor_, _dest_, _len_, 0, NULL, NULL );

但这似乎没有返回接口“eth5”上收到的数据。有什么指点吗?

I have the following interfaces :

ifconfig
bond0     Link encap:Ethernet  HWaddr 1C:C1:DE:1F:71:CA  
          inet addr:10.3.3.13  Bcast:10.3.3.255  Mask:255.255.255.0
          inet6 addr: fe80::1ec1:deff:fe1f:71ca/64 Scope:Link
          UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
          RX packets:39972916 errors:0 dropped:0 overruns:0 frame:0
          TX packets:21849588 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:60630723698 (56.4 GiB)  TX bytes:1570500163 (1.4 GiB)

eth0      Link encap:Ethernet  HWaddr 1C:C1:DE:1F:71:CA  
          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:39959516 errors:0 dropped:0 overruns:0 frame:0
          TX packets:21849585 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:60629214902 (56.4 GiB)  TX bytes:1570499971 (1.4 GiB)
          Interrupt:16 Memory:f2000000-f2012800 

eth1      Link encap:Ethernet  HWaddr 1C:C1:DE:1F:71:CA  
          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:13400 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1508796 (1.4 MiB)  TX bytes:192 (192.0 b)
          Interrupt:17 Memory:f0000000-f0012800 

eth5      Link encap:Ethernet  HWaddr 00:0F:53:07:50:7D  
          inet addr:90.206.66.13  Bcast:90.206.66.255  Mask:255.255.255.0
          inet6 addr: fe80::f:5300:107:507d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:8590042795 errors:0 dropped:4 overruns:0 frame:0
          TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:8308671 (7.9 MiB)  TX bytes:1132 (1.1 KiB)
          Interrupt:39 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:10 errors:0 dropped:0 overruns:0 frame:0
          TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:700 (700.0 b)  TX bytes:700 (700.0 b)

I have the following multicast code to listen :

  socket_file_descriptor_ = socket ( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
  int flag_on = 1;
  if ( ( setsockopt ( socket_file_descriptor_, SOL_SOCKET, SO_REUSEADDR, &flag_on,
                        sizeof(flag_on) ) ) < 0 )
      { exit(1); }

  struct ip_mreq mc_req;
  inet_pton ( AF_INET, listen_ip_.c_str(), &(mc_req.imr_multiaddr.s_addr) ); 
  mc_req.imr_interface.s_addr = htonl(INADDR_ANY);
  if ( ( setsockopt ( socket_file_descriptor_, IPPROTO_IP, IP_ADD_MEMBERSHIP, 
                            (void*) &mc_req, sizeof(mc_req))) < 0) 
  { exit(1); } 

  {
    struct sockaddr_in mcast_Addr;
    bzero ( &mcast_Addr, sizeof(mcast_Addr) );
    mcast_Addr.sin_family = AF_INET;
    mcast_Addr.sin_addr.s_addr = htonl(INADDR_ANY);
    mcast_Addr.sin_port = htons ( listen_port_ );
    /* bind to specified port onany interface */
    if ( bind ( socket_file_descriptor_, (struct sockaddr *) &mcast_Addr, sizeof ( struct sockaddr_in ) ) < 0 )
      { exit(1); }
  }
  // then recvfrom ( socket_file_descriptor_, _dest_, _len_, 0, NULL, NULL );

But this does not seem to be returning data received on interface "eth5". Any pointers ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

于我来说 2024-11-16 19:17:56

您使用什么平台?我猜是linux操作系统?

您完全确定消息到达您的接口(tcpdump、netcat?)。预期的数据来自哪里 - 您是否也开发了“发送者”代码?它使用 SO_BROADCAST 选项吗?

What platform are you using? I'd guess a linux OS?

Are you completely sure that messages arrive on your interface (tcpdump, netcat?). Where does the expected data come from - did you develop the 'sender' code too? Does it use SO_BROADCAST option?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文