Removes unnecessary dns query when connecting with jabber, add input check for ip address in NetworkUtils getARecord and getAAAARecord.

cusax-fix
Damian Minkov 14 years ago
parent 72b87bcd3b
commit daa694846d

@ -31,12 +31,12 @@ public class SmackPacketDebugger
/**
* Local address for the connection.
*/
private byte[] localAddress = new byte[4];
private byte[] localAddress;
/**
* Remote address for the connection.
*/
private byte[] remoteAddress = new byte[4];
private byte[] remoteAddress;
/**
* Instance for the packet logging service.
@ -58,33 +58,6 @@ public SmackPacketDebugger()
public void setConnection(XMPPConnection connection)
{
this.connection = connection;
try
{
InetSocketAddress inetAddress;
if(Boolean.getBoolean("java.net.preferIPv6Addresses"))
{
inetAddress = NetworkUtils.getAAAARecord(
connection.getHost(), 0);
}
else
{
inetAddress = NetworkUtils.getARecord(
connection.getHost(), 0);
}
if(inetAddress != null)
remoteAddress = inetAddress.getAddress().getAddress();
// to create empty ipv6 address default is ipv4
if(remoteAddress.length != localAddress.length)
localAddress = new byte[remoteAddress.length];
}
catch(Throwable t)
{
t.printStackTrace();
}
}
/**
@ -105,6 +78,14 @@ public void interceptPacket(Packet packet)
PacketLoggingService.ProtocolName.JABBER)
&& packet != null && connection.getSocket() != null)
{
if(remoteAddress == null)
{
remoteAddress = connection.getSocket()
.getInetAddress().getAddress();
localAddress = connection.getSocket()
.getLocalAddress().getAddress();
}
packetLogging.logPacket(
PacketLoggingService.ProtocolName.JABBER,
localAddress,

@ -916,7 +916,24 @@ public static InetSocketAddress[] getAandAAAARecords(String domain, int port)
public static InetSocketAddress getARecord(String domain, int port)
throws ParseException
{
Record[] records = null;
byte[] address;
if((address = strToIPv4(domain)) != null)
{
try
{
return new InetSocketAddress(
InetAddress.getByAddress(domain, address), port);
}
catch (UnknownHostException e)
{
//should not happen
logger.error(
"Unable to create InetAddress for <" + domain + ">", e);
return null;
}
}
Record[] records;
try
{
//note that we intentionally do not use our parallel resolver here.
@ -956,7 +973,24 @@ public static InetSocketAddress getARecord(String domain, int port)
public static InetSocketAddress getAAAARecord(String domain, int port)
throws ParseException
{
Record[] records = null;
byte[] address;
if((address = strToIPv6(domain)) != null)
{
try
{
return new InetSocketAddress(
InetAddress.getByAddress(domain, address), port);
}
catch (UnknownHostException e)
{
//should not happen
logger.error(
"Unable to create InetAddress for <" + domain + ">", e);
return null;
}
}
Record[] records;
try
{
//note that we intentionally do not use our parallel resolver here.

Loading…
Cancel
Save