UDP 数据包无法到达 Ubuntu 上正在监听的应用程序

UDP 数据包无法到达 Ubuntu 上正在监听的应用程序

我从 Arduino 发送了一个 UDP 数据包,该数据包到达我的 Ubuntu 服务器,因为您可以在 tcpdump 上看到它,如您所见。但它从未转发到正在监听端口 8888 的应用程序。有人知道数据包出了什么问题吗?

我的 Ubuntu 版本是:Ubuntu 12.04.1 LTS(GNU/Linux 3.2.0-29-generic-pae i686)

这是tcpdump

tcpdump -i 1 udp port 8888 -vv -X
tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 65535 byte                                                       s
19:06:20.179117 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto UDP (17), length 131)
    192.168.1.53.3333 > diskServer.8888: [udp sum ok] UDP, length 103
        0x0000:  4500 0083 0000 4000 4011 b6b1 c0a8 0135  E.....@[email protected]
        0x0010:  c0a8 0133 0d05 22b8 006f 87d6 7465 7374  ...3.."..o..test
        0x0020:  2030 3132 3334 3536 3738 3930 2074 6573  .01234567890.tes
        0x0030:  7420 3031 3233 3435 3637 3839 3020 7465  t.01234567890.te
        0x0040:  7374 2030 3132 3334 3536 3738 3930 2074  st.01234567890.t
        0x0050:  6573 7420 3031 3233 3435 3637 3839 3020  est.01234567890.
        0x0060:  7465 7374 2030 3132 3334 3536 3738 3930  test.01234567890
        0x0070:  2074 6573 7420 3031 3233 3435 3637 3839  .test.0123456789
        0x0080:  3020 00                                  0..

这是监听端口:

root@diskServer:~# netstat -a
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 diskServer:mysql        *:*                     LISTEN
tcp        0      0 *:netbios-ssn           *:*                     LISTEN
tcp        0      0 *:ssh                   *:*                     LISTEN
tcp        0      0 *:https                 *:*                     LISTEN
tcp        0      0 *:microsoft-ds          *:*                     LISTEN
tcp        0      0 diskServer:ssh          flavix:53077            ESTABLISHED
tcp        0    144 diskServer:ssh          flavix:53028            ESTABLISHED
tcp        0      0 diskServer:ssh          192.168.1.107:54978     ESTABLISHED
tcp        0      0 diskServer:ssh          192.168.1.107:55000     ESTABLISHED
tcp6       0      0 [::]:8009               [::]:*                  LISTEN
tcp6       0      0 [::]:http-alt           [::]:*                  LISTEN
tcp6       0      0 [::]:ssh                [::]:*                  LISTEN
tcp6       0      0 [::]:8443               [::]:*                  LISTEN
tcp6       0      0 localhost:8005          [::]:*                  LISTEN
udp        0      0 diskServer:ntp          *:*
udp        0      0 localhost:ntp           *:*
udp        0      0 *:ntp                   *:*
udp        0      0 192.168.1.25:netbios-ns *:*
udp        0      0 diskServer:netbios-ns   *:*
udp        0      0 *:netbios-ns            *:*
udp        0      0 192.168.1.2:netbios-dgm *:*
udp        0      0 diskServer:netbios-dgm  *:*
udp        0      0 *:netbios-dgm           *:*
udp        0      0 diskServer:8888         *:***
udp6       0      0 ip6-localhost:ntp       [::]:*
udp6       0      0 fe80::20e:7bff:feac:ntp [::]:*
udp6       0      0 [::]:ntp                [::]:*

UDP 的记忆:

root@diskServer:~# cat /proc/sys/net/ipv4/udp_mem
18066   24090   36132

root@diskServer:~# netstat -su
IcmpMsg:
    InType3: 10316969
    InType8: 18368
    OutType0: 18368
    OutType3: 10317030
Udp:
    211263 packets received
    10309092 packets to unknown port received.
    0 packet receive errors
    10348446 packets sent
UdpLite:
IpExt:
    InMcastPkts: 24678
    InBcastPkts: 287164
    OutBcastPkts: 12685
    InOctets: -1
    OutOctets: -1
    InMcastOctets: 690984
    InBcastOctets: 48281994
    OutBcastOctets: 3170039

root@diskServer:~# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
fail2ban-apache-badbots  tcp  --  anywhere             anywhere             multiport dports http,https
fail2ban-apache-overflows  tcp  --  anywhere             anywhere             multiport dports http,https
fail2ban-apache-noscript  tcp  --  anywhere             anywhere             multiport dports http,https
fail2ban-apache  tcp  --  anywhere             anywhere             multiport dports http,https
fail2ban-ssh  tcp  --  anywhere             anywhere             multiport dports ssh
ufw-before-logging-input  all  --  anywhere             anywhere
ufw-before-input  all  --  anywhere             anywhere
ufw-after-input  all  --  anywhere             anywhere
ufw-after-logging-input  all  --  anywhere             anywhere
ufw-reject-input  all  --  anywhere             anywhere
ufw-track-input  all  --  anywhere             anywhere

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
ufw-before-logging-forward  all  --  anywhere             anywhere
ufw-before-forward  all  --  anywhere             anywhere
ufw-after-forward  all  --  anywhere             anywhere
ufw-after-logging-forward  all  --  anywhere             anywhere
ufw-reject-forward  all  --  anywhere             anywhere

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
ufw-before-logging-output  all  --  anywhere             anywhere
ufw-before-output  all  --  anywhere             anywhere
ufw-after-output  all  --  anywhere             anywhere
ufw-after-logging-output  all  --  anywhere             anywhere
ufw-reject-output  all  --  anywhere             anywhere
ufw-track-output  all  --  anywhere             anywhere

Chain fail2ban-apache (1 references)
target     prot opt source               destination
RETURN     all  --  anywhere             anywhere

Chain fail2ban-apache-badbots (1 references)
target     prot opt source               destination
RETURN     all  --  anywhere             anywhere

Chain fail2ban-apache-noscript (1 references)
target     prot opt source               destination
RETURN     all  --  anywhere             anywhere

Chain fail2ban-apache-overflows (1 references)
target     prot opt source               destination
RETURN     all  --  anywhere             anywhere

Chain fail2ban-ssh (1 references)
target     prot opt source               destination
RETURN     all  --  anywhere             anywhere

Chain ufw-after-forward (1 references)
target     prot opt source               destination

Chain ufw-after-input (1 references)
target     prot opt source               destination

Chain ufw-after-logging-forward (1 references)
target     prot opt source               destination

Chain ufw-after-logging-input (1 references)
target     prot opt source               destination

Chain ufw-after-logging-output (1 references)
target     prot opt source               destination

Chain ufw-after-output (1 references)
target     prot opt source               destination

Chain ufw-before-forward (1 references)
target     prot opt source               destination

Chain ufw-before-input (1 references)
target     prot opt source               destination

Chain ufw-before-logging-forward (1 references)
target     prot opt source               destination

Chain ufw-before-logging-input (1 references)
target     prot opt source               destination

Chain ufw-before-logging-output (1 references)
target     prot opt source               destination

Chain ufw-before-output (1 references)
target     prot opt source               destination

Chain ufw-reject-forward (1 references)
target     prot opt source               destination

Chain ufw-reject-input (1 references)
target     prot opt source               destination

Chain ufw-reject-output (1 references)
target     prot opt source               destination

Chain ufw-track-input (1 references)
target     prot opt source               destination

Chain ufw-track-output (1 references)
target     prot opt source               destination

ufw 已被禁用。

答案1

问题出在数据包中,这是错误的,因为以太网级别的目的地设置为 0,这是 wireShark 的输出:

以太网 II,源:74:69:69:2d:30:31(74:69:69:2d:30:31),目标:00:00:00_00:00:00(00:00:00:00:00:00)

这是因为我的 Arduino 开发板存在硬件问题。

谢谢大家,再见。

答案2

实际问题可能出在使用的 ethercard 库中。它没有正确处理目标的 ARP 查找,导致目标 mac 地址全为零(请参阅https://github.com/jcw/ethercard/issues/181)。

另一个可行的库是 Ethernet_UIP,可以在以下位置找到:https://github.com/ntruchsess/arduino_uip其中有一个发送 UDP 数据包的示例;我测试了该示例并且它确实有效。

相关内容