Revision: 2c165f37e30a
Author: Jean Deruelle <[email protected]>
Date: Tue Dec 4 22:13:49 2012
Log: Update Issue 37
(git repo)
http://java.net/jira/browse/JSIP-440
Fixes the issue by specifying to which IP Address the socket is binding to
(cherry picked from commit 6bbd8188993704bb724e4195824de18306813ddd)
http://code.google.com/p/jain-sip/source/detail?r=2c165f37e30a
Modified:
/src/gov/nist/core/net/DefaultNetworkLayer.java
/src/gov/nist/javax/sip/stack/IOHandler.java
=======================================
--- /src/gov/nist/core/net/DefaultNetworkLayer.java Thu Jun 30 23:35:24 2011
+++ /src/gov/nist/core/net/DefaultNetworkLayer.java Tue Dec 4 22:13:49 2012
@@ -106,7 +106,18 @@
/* Added by Daniel J. Martinez Manzano <[email protected]> */
public SSLSocket createSSLSocket(InetAddress address, int port)
throws IOException {
+ return createSSLSocket(address, port, null);
+ }
+
+ /* Added by Daniel J. Martinez Manzano <[email protected]> */
+ public SSLSocket createSSLSocket(InetAddress address, int port,
+ InetAddress myAddress) throws IOException {
SSLSocket sock = (SSLSocket) sslSocketFactory.createSocket();
+ if (myAddress != null) {
+ // trying to bind to the correct ipaddress (in case of multiple vip
addresses by example)
+ // and let the JDK pick an ephemeral port
+ sock.bind(new InetSocketAddress(myAddress, 0));
+ }
try {
sock.connect(new InetSocketAddress(address, port), 8000);
} catch (SocketTimeoutException e) {
@@ -114,17 +125,14 @@
}
return sock;
}
-
- /* Added by Daniel J. Martinez Manzano <[email protected]> */
- public SSLSocket createSSLSocket(InetAddress address, int port,
- InetAddress myAddress) throws IOException {
- return createSSLSocket(address, port);
- }
public Socket createSocket(InetAddress address, int port,
InetAddress myAddress) throws IOException {
if (myAddress != null) {
Socket sock = new Socket();
+ // http://java.net/jira/browse/JSIP-440 trying to bind to the
correct ipaddress (in case of multiple vip addresses by example)
+ // and let the JDK pick an ephemeral port
+ sock.bind(new InetSocketAddress(myAddress, 0));
try {
sock.connect(new InetSocketAddress(address, port),
8000);
} catch (SocketTimeoutException e) {
@@ -163,18 +171,42 @@
InetAddress myAddress, int myPort)
throws IOException
{
- if (myAddress != null)
- return new Socket(address, port, myAddress, myPort);
- else if (port != 0)
- {
- //myAddress is null (i.e. any) but we have a port number
+ if (myAddress != null) {
Socket sock = new Socket();
- sock.bind(new InetSocketAddress(port));
- sock.connect(new InetSocketAddress(address, port), 8000);
+ // http://java.net/jira/browse/JSIP-440 trying to bind to the
correct ipaddress (in case of multiple vip addresses by example)
+ // and let the JDK pick an ephemeral port
+ sock.bind(new InetSocketAddress(myAddress, 0));
+ try {
+ sock.connect(new InetSocketAddress(address, port),
8000);
+ } catch (SocketTimeoutException e) {
+ throw new ConnectException("Socket timeout error
(8sec)" + address + ":" + port);
+ }
return sock;
- }
- else
- return new Socket(address, port);
+ }
+ else {
+ Socket sock = new Socket();
+ if(myPort != 0) {
+ sock.bind(new InetSocketAddress(port));
+ }
+ try {
+ sock.connect(new InetSocketAddress(address, port),
8000);
+ } catch (SocketTimeoutException e) {
+ throw new ConnectException("Socket timeout error
(8sec)" + address + ":" + port);
+ }
+ return sock;
+ }
+// if (myAddress != null)
+// return new Socket(address, port, myAddress, myPort);
+// else if (port != 0)
+// {
+// //myAddress is null (i.e. any) but we have a port number
+// Socket sock = new Socket();
+// sock.bind(new InetSocketAddress(port));
+// sock.connect(new InetSocketAddress(address, port), 8000);
+// return sock;
+// }
+// else
+// return new Socket(address, port);
}
}
=======================================
--- /src/gov/nist/javax/sip/stack/IOHandler.java Thu May 31 13:40:31 2012
+++ /src/gov/nist/javax/sip/stack/IOHandler.java Tue Dec 4 22:13:49 2012
@@ -269,7 +269,8 @@
int length = bytes.length;
if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG)) {
logger.logDebug(
- "sendBytes " + transport + " inAddr "
+ "sendBytes " + transport + " local inAddr "
+ + senderAddress.getHostAddress() + " remote inAddr
"
+ receiverAddress.getHostAddress() + " port = "
+ contactPort + " length = " + length + "
isClient " + isClient );
@@ -314,6 +315,9 @@
throw new SocketException(e.getClass() + " " +
e.getMessage() + " " + e.getCause() + " Problem connecting " +
receiverAddress + " " + contactPort + " " +
senderAddress + " for message " + new String(bytes, "UTF-8"));
}
+ if
(logger.isLoggingEnabled(LogWriter.TRACE_DEBUG)) {
+ logger.logDebug("local inaddr = " +
clientSock.getLocalAddress().getHostAddress());
+ }
OutputStream outputStream = clientSock
.getOutputStream();
writeChunks(outputStream, bytes, length);