|
@@ -775,6 +775,15 @@ public class IRCParser extends BaseParser implements SecureParser, EncodingParse
|
775
|
775
|
disconnectOnFatal = newValue;
|
776
|
776
|
}
|
777
|
777
|
|
|
778
|
+ /**
|
|
779
|
+ * Create a new Socket object for the given target, using the given proxy
|
|
780
|
+ * if appropriate.
|
|
781
|
+ *
|
|
782
|
+ * @param target Target URI to connect to.
|
|
783
|
+ * @param proxy Proxy URI to use
|
|
784
|
+ * @return Socket, with IP Binding or Proxy as appropriate,
|
|
785
|
+ * @throws IOException If there was an issue creating the socket.
|
|
786
|
+ */
|
778
|
787
|
private Socket newSocket(final URI target, final URI proxy) throws IOException {
|
779
|
788
|
if (target.getPort() > 65535 || target.getPort() <= 0) {
|
780
|
789
|
throw new IOException("Server port (" + target.getPort() + ") is invalid.");
|
|
@@ -785,20 +794,33 @@ public class IRCParser extends BaseParser implements SecureParser, EncodingParse
|
785
|
794
|
callDebugInfo(DEBUG_SOCKET, "Not using Proxy");
|
786
|
795
|
mySocket = new Socket();
|
787
|
796
|
|
788
|
|
- if (getBindIP() != null && !getBindIP().isEmpty()) {
|
789
|
|
- callDebugInfo(DEBUG_SOCKET, "Binding to IP: " + getBindIP());
|
790
|
|
- try {
|
791
|
|
- mySocket.bind(new InetSocketAddress(InetAddress.getByName(getBindIP()), 0));
|
792
|
|
- } catch (IOException e) {
|
793
|
|
- callDebugInfo(DEBUG_SOCKET, "Binding failed: " + e.getMessage());
|
|
797
|
+ final InetSocketAddress sockAddr = new InetSocketAddress(target.getHost(), target.getPort());
|
|
798
|
+
|
|
799
|
+ if (sockAddr.getAddress() instanceof Inet6Address) {
|
|
800
|
+ if (getBindIPv6() != null && !getBindIPv6().isEmpty()) {
|
|
801
|
+ callDebugInfo(DEBUG_SOCKET, "Binding to IPv6: " + getBindIP());
|
|
802
|
+ try {
|
|
803
|
+ mySocket.bind(new InetSocketAddress(InetAddress.getByName(getBindIPv6()), 0));
|
|
804
|
+ } catch (IOException e) {
|
|
805
|
+ callDebugInfo(DEBUG_SOCKET, "Binding failed: " + e.getMessage());
|
|
806
|
+ }
|
|
807
|
+ }
|
|
808
|
+ } else {
|
|
809
|
+ if (getBindIP() != null && !getBindIP().isEmpty()) {
|
|
810
|
+ callDebugInfo(DEBUG_SOCKET, "Binding to IPv4: " + getBindIP());
|
|
811
|
+ try {
|
|
812
|
+ mySocket.bind(new InetSocketAddress(InetAddress.getByName(getBindIP()), 0));
|
|
813
|
+ } catch (IOException e) {
|
|
814
|
+ callDebugInfo(DEBUG_SOCKET, "Binding failed: " + e.getMessage());
|
|
815
|
+ }
|
794
|
816
|
}
|
795
|
817
|
}
|
796
|
818
|
|
797
|
|
- mySocket.connect(new InetSocketAddress(target.getHost(), target.getPort()), connectTimeout);
|
|
819
|
+ mySocket.connect(sockAddr, connectTimeout);
|
798
|
820
|
} else {
|
799
|
821
|
callDebugInfo(DEBUG_SOCKET, "Using Proxy");
|
800
|
822
|
|
801
|
|
- if (getBindIP() != null && !getBindIP().isEmpty()) {
|
|
823
|
+ if ((getBindIP() != null && !getBindIP().isEmpty()) || (getBindIPv6() != null && !getBindIPv6().isEmpty())) {
|
802
|
824
|
callDebugInfo(DEBUG_SOCKET, "IP Binding is not possible when using a proxy.");
|
803
|
825
|
}
|
804
|
826
|
|