我编写了一个Android程序来接收多播数据包。 代码如下。 问题是我可以收到正常的数据包, 但我无法收到Bad UDP长度>的数据包。 IP PAYLOAD长度。 我猜这些伪造的包被某人扯了下来。 如何在Android中收到伪造的数据包,谢谢!
public class SSDP extends Thread {
/**
* Default IPv4 multicast address for SSDP messages
*/
public static final String ADDRESS = "239.100.10.100";
public static final String LOG_TAG = "SSDP";
public static final boolean DEBUG = false;
private SocketAddress mMulticastGroupAddress = new InetSocketAddress("239.100.10.100", 2060);
private MulticastSocket mMulticastSocket;
private DatagramSocket mUnicastSocket;
private NetworkInterface mNetIf;
private Context mContext;
private boolean mRunning = false;
private byte[] mFrameNumber, mNowFrameNumber, mSequenceNumber, mNowSequenceNumber;
private ByteArrayBuffer mReadBuffer;
private boolean mLast = false;
final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();
public static String bytesToHex(byte[] bytes) {
char[] hexChars = new char[bytes.length * 2];
for ( int j = 0; j < bytes.length; j++ ) {
int v = bytes[j] & 0xFF;
hexChars[j * 2] = hexArray[v >>> 4];
hexChars[j * 2 + 1] = hexArray[v & 0x0F];
}
return new String(hexChars);
}
public SSDP(Context ctx) throws IOException {
mContext = ctx;
mNetIf = Utils.getActiveNetworkInterface();
}
@Override
public synchronized void start() {
mRunning = true;
super.start();
}
@Override
public void run() {
try {
mMulticastSocket = new MulticastSocket(2060);
mMulticastSocket.setLoopbackMode(true);
mMulticastSocket.joinGroup(mMulticastGroupAddress, mNetIf);
mUnicastSocket = new DatagramSocket(null);
mUnicastSocket.setReuseAddress(true);
mUnicastSocket.bind(new InetSocketAddress(Utils.getLocalV4Address(mNetIf),2060));
} catch (IOException e) {
UtilLog("Setup SSDP failed: " + e);
}
while(mRunning)
{
DatagramPacket dp = null;
try
{
dp = receive();
//do somethins
}
catch (IOException e)
{
UtilLog("SSDP fail: " + e);
}
}
UtilLog("SSDP shutdown.");
}
public synchronized void shutdown() {
mRunning = false;
}
private void UtilLog(String message)
{
if(DEBUG)
Log.d(LOG_TAG, message);
}
private DatagramPacket receive() throws IOException {
byte[] buf = new byte[1500];
DatagramPacket dp = new DatagramPacket(buf, buf.length);
mMulticastSocket.receive(dp);
return dp;
}
}
答案 0 :(得分:0)
Index: net/ipv4/ip_input.c
===================================================================
--- net/ipv4/ip_input.c (revision 10665)
+++ net/ipv4/ip_input.c (working copy)
@@ -420,8 +420,8 @@
len = ntohs(iph->tot_len);
if (skb->len < len) {
- IP_INC_STATS_BH(dev_net(dev), IPSTATS_MIB_INTRUNCATEDPKTS);
- goto drop;
+ //IP_INC_STATS_BH(dev_net(dev), IPSTATS_MIB_INTRUNCATEDPKTS);
+ //goto drop;
} else if (len < (iph->ihl*4))
goto inhdr_error;
Index: net/ipv4/udp.c
===================================================================
--- net/ipv4/udp.c (revision 10665)
+++ net/ipv4/udp.c (working copy)
@@ -1631,13 +1631,13 @@
saddr = ip_hdr(skb)->saddr;
daddr = ip_hdr(skb)->daddr;
- if (ulen > skb->len)
- goto short_packet;
+// if (ulen > skb->len)
+// goto short_packet;
if (proto == IPPROTO_UDP) {
/* UDP validates ulen. */
- if (ulen < sizeof(*uh) || pskb_trim_rcsum(skb, ulen))
- goto short_packet;
+// if (ulen < sizeof(*uh) || pskb_trim_rcsum(skb, ulen))
+// goto short_packet;
uh = udp_hdr(skb);
}