Setsockopt in Java Programs

Starting with version 8, FreeBSD supports the IP_BINDANY socket option, which is indicated on the manual page:

If the IP_BINDANY parameter is included in SOCK_STREAM, SOCK_DGRAM, or SOCK_RAW, you can bind (2) to any address that is not even bound to any available network interface in the system. This functionality (in combination with special firewall rules) can be used to implement transparent proxies. PRIV_NETINET_BINDANY privilege is required to install this option.

Is it possible to write a Java program that can use this functionality? I checked the SocketOptions docs and obviously does not list this option. So is there a workaround?

taking into account,

Rajah

+3
source share
2 answers

Is it possible to write a Java program that can use this function?

Unable to use pure Java.

So is there a workaround?

There are several JNA / JNI libraries for creating Posix system calls from a Java program; see this question / answer for more details:

I do not know if they are available for Java on FreeBSD.


Think about whether this is possible to implement in pure (although inevitably not portable) Java. This will entail the creation of subclasses of SocketImpl and / or DatagramSocketImpl and the necessary infrastructure for their use. That would be difficult.

+1
source

I wrote a library in JNA to make the bit setsockoptreasonably portable. You can find it here .

, bind, . . , :

, java.net.Socket, setsockopt() , , bind() - , ? , - Socket Java ( OpenJDK JVM Oracle) . Javas bind(), setsockopt() .

- .

0

Source: https://habr.com/ru/post/1532262/


All Articles