简体   繁体   English

了解udp套接字上内核分配的本地地址

[英]Understanding kernel assigned local addresses on a udp socket

i'm developing a java application using the jstun library (hxxp://jstun.javawi.de/), and i need to compare my public ip with the one chosen by the kernel (wildcard address - hxxp://java.sun.com/j2se/1.5.0/docs/api/java/net/DatagramSocket.html#DatagramSocket() ) when i create a udp socket. 我正在使用jstun库(hxxp://jstun.javawi.de/)开发一个Java应用程序,并且需要将我的公共IP与内核选择的IP比较(通配符地址-hxxp://java.sun .com / j2se / 1.5.0 / docs / api / java / net / DatagramSocket.html#DatagramSocket()),当我创建udp套接字时。

what i don't understand is, if my local ip on my natted network is in the form of 192.168.1.x, why do i get an ip such as 10.xxx ? 我不明白的是,如果我的网络中的本地IP格式为192.168.1.x,为什么我会得到一个IP,例如10.xxx?

is there a particular reason why the two are totally unrelated? 两者完全不相关有特定原因吗? if i wasn't behind a nat, would the kernel bind the socket to my public address? 如果我不是一个NAT之后,将内核绑定套接字到我的公网地址?

thanks a lot! 非常感谢! asymmetric 不对称

For a sending socket the source IP would be determined by the host routing table according to the destination IP; 对于发送套接字,源IP将由主机路由表根据目标IP确定。 for receiving socket the destination IP is what you get. 用于接收套接字的目标IP是您获得的。 The "public" IP your peers see is the source address on the packet from you, which is re-written by NAT to be whatever internal addresses are translated to. 您的对等方看到的“公共” IP是来自您的数据包上的源地址,该地址由NAT重写为任何内部地址。

i failed to mention a rather important thing: i'm developing for android, and running my code on the android emulator, which explains the 10.xxx address thing.. 我没有提到一个相当重要的事情:我正在为android开发,并在android模拟器上运行我的代码,这解释了10.xxx地址的问题。

i should dig deeper into that.. thanks for the help! 我应该深入研究..谢谢您的帮助!

for those that are interested: hxxp://developer.android.com/guide/developing/tools/emulator.html#networkaddresses 对于感兴趣的用户:hxxp://developer.android.com/guide/developing/tools/emulator.html#networkaddresses

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM