我正在使用ubuntu 12.04下的tcl脚本,当我尝试配置多播套接字时,我遇到了一些问题。我想要做的是将流量从某个套接字转发到多播套接字,但我不知道为什么虽然多播套接字创建得很好,显然;它不受我想要的多播组的约束。
这是我正在使用的脚本
#!/bin/sh
# test.tcl \
exec tclsh "$0" ${1+"$@"}
package require udp
set multicastPort "50003"
proc connector {unicastIP multicastIP port {protocol tcp}} {
if { [string equal $protocol "tcp"] } {
socket -server serverTCP -myaddr $unicastIP $port
puts "tcp"
} elseif {[string equal $protocol "udp" ] } {
serverUDP $unicastIP $multicastIP $port
puts "udp"
}
}
proc serverUDP {unicastIP multicastIP port} {
global multicastPort
set socketUDP [udp_open $port]
puts " $unicastIP"
fconfigure $socketUDP -blocking false -translation binary -buffering none -remote [list $unicastIP $port]
#fileevent $socketUDP readable [list gettingData $socketUDP]
set multicastSocket [udp_open $multicastPort]
udp_conf $multicastSocket -ttl 4
fconfigure $multicastSocket -blocking false -translation binary -buffering none -mcastadd $multicastIP -remote [list $multicastIP $port]
fileevent $socketUDP readable [list forwarding $socketUDP $multicastSocket ]
#puts $socketUDP "hello!"
#flush $socketUDP
}
proc forwarding {socketSrc socketDst} {
set data [read -nonewline $socketSrc]
puts "Read data-> $data"
puts -nonewline $socketDst $data
puts "Written data-> [read -nonewline $socketDst]"
}
connector 127.0.0.1 224.0.1.1 50000 udp
vwait forever
但是,如果我运行脚本并检查系统中的端口,则无法为多播端口分配正确的多播IP,如您所见
~$ netstat -ptnlu
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
udp 0 0 0.0.0.0:50000 0.0.0.0:* 3334/tclsh
udp 0 0 0.0.0.0:50003 0.0.0.0:* 3334/tclsh
有人可以告诉我原因吗?
提前谢谢,
问候!
答案 0 :(得分:1)
AFAIK,没关系。我使用Tcl及其udp
包生产多播守护进程,netstat
和ss
工具也显示套接字正在侦听通配符地址。
IGMP
“加入”消息到本地传输段(以太网,在大多数部署中)并进一步与附近的IGMP
路由器通信(再次,在以太网上,它们主要是交换机)。
因此,在您的情况下,只需启动tcpdump
并查看启动程序时转储的内容。对tcpdump
的有用调用看起来像这样:
tcpdump -i eth0 -n 'igmp and host 224.0.1.1'
观察UDP流量交换使用
tcpdump -i eth0 -n 'udp and host 224.0.1.1 and port 50000'