2012-11-10 32 views
1

使用本文來源RAW_SOCKET to forge UDP packets我從其他主機生成包含eth0 ip地址的數據包,例如192.168.10.1 - > 192.168.10.131。自己的UDP RAW_SOCKET數據包是在回送接口而不是eth0上捕獲的

但tcpdump的顯示,即數據包到達入LO,沒有eth0的... 上LO -

10:10:18.332284 IP (tos 0x0, ttl 64, id 768, offset 0, flags [DF], proto UDP (17), length 71) 
192.168.10.1.57961 > 192.168.10.131.12001: [udp sum ok] UDP, length 43 

,並在eth0上是沉默。

如何更改代碼,使數據包到達eth0? direct link to C source file

回答

1

依我之見,你必須使用而不是UDP TCP功能

對於UDP,您可以設置OPTNAME到SO_BINDTODEVICE

const char device[] = "eth0"; 
rc=setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, device, sizeof(device)); 
if (rc != 0) 
{ 
printf ("%s: could not set SO_BINDTODEVICE (%s)\n", 
    argv[0], strerror(errno)); 
exit (EXIT_FAILURE); 
} 
+0

大衛,我需要UDP只... –

+1

乘坐請看http://beej.us/guide/bgnet/output/html/multipage/setsockoptman.html –

+0

它是無論如何在lo ... 'tcpdump -i lo -nn -vv -XX -s 4096'udp和端口12001' tcpdump:監聽lo,鏈路類型EN10MB(以太網),捕獲大小4096字節 11:51:15.406405 IP(tos 0x0,tt164,id 0,offset 0,flags [DF],proto UDP(17),length 128) 192.168.10.1.12002> 192.168.10.131.12001:[udp sum OK] UDP,長度爲100 \t 0x0000:0000 0000 0000 0000 0000 0000 0800 4500 .............. E。 \t 0x0010:0080 0000 4000 4011 a498 c0a8 0a01 c0a8 .... @。@ .........' –

相關問題