发信人: keys (xiao dao), 信区: Programming
标 题: Re: a socket Question
发信站: Unknown Space - 未名空间 (Thu Nov 4 17:08:17 2004) WWW-POST
when you send a packet, OS's routing algorithm will check if destination ip
address is actually owned by its local interfaces. If yes, the packet will go
through loopback interface ('lo' 127.0.0.1) and never be sent out through the
physical interface, so you'd never see it appear on the wire through a sniffer
program like ethereal.
If you are using linux, there is kernel patch called send-to-self which can
bypass loopback interface. You need to apply this patch to your kernel source
and recompile a new kernel.
Another way is using a layer 2 socket (PF_PACKET on linux). This way you have
to assemble a packet from scratch, including ethernet header, ip header,
tcp/udp header etc. and implement TCP/IP stack by your self. Unless you are
just doing IP layer (layer 3) programming, it's not recommended.
If you are working on windows, I'm not sure if there are other ways doing
【 在 oml (我是宝宝我怕谁@@) 的大作中提到: 】
: I have 2 NIC on my machine, each has a static ip address
: I want them talk to each other only through wire
: how can I do that?
: so far waht I did is bind different socket to them, but it won't work, even
: I don't have a loop, they can talk to each other
: what to do ne?
※ 来源:．Unknown Space - 未名空间 mitbbs.com．[FROM: 208.181.]