确定Java中多播数据包的剩余TTL [英] Determine the remaining TTL of a multicast packet in Java

查看:181
本文介绍了确定Java中多播数据包的剩余TTL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个侦听多播数据的Java程序,如何判断传入数据报的剩余TTL是多少?

If I have a Java program that listens to multicast data, how can I tell what the remaining TTL of the incoming datagram is?

我知道如何在发送的多播套接字上设置TTL,但是我想知道到达的数据包的剩余TTL.

I know how to set the TTL on the sending multicast socket, but I want to know the remaining TTL of the arriving packet.

推荐答案

如果收到带有原始套接字的UDP数据报,则可以检查TTL(或IP或UDP标头中的任何其他内容).尽管如此,还是有很多陷阱:

If you receive the UDP datagrams with a raw socket you can inspect the TTL (or anything else in the IP or UDP headers). There are lots of gotchas, though:

  • 原始套接字不是Java的本机(尽管至少有一个多平台的第三方插件是可用的: http://www.savarese.org/software/rocksaw/index.html ).
  • 在大多数操作系统上,您必须具有root用户访问权限或管理权限才能使用原始套接字
  • 如果您还想使用UDP数据,则您必须自己进行校验和和碎片数据报的重组……以及可能在碎片之间遇到不同的TTL(如jambjo所说).
  • Raw Sockets are non-native to Java (though at least one multi-platform 3rd party add-on is available: http://www.savarese.org/software/rocksaw/index.html ).
  • On most operating systems, you must have root access or administrative privileges to use raw sockets
  • If you wanted to use the UDP data also, you would have to do checksums and reassembly of fragmented datagrams yourself ...as well as possibly encountering different TTLs among fragments (as jambjo said).

这篇关于确定Java中多播数据包的剩余TTL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆