Skip to content

Commit

Permalink
Assure host is always an IP address (#69)
Browse files Browse the repository at this point in the history
Use `InetAddress.getHostAddress()` instead of `InetAddress.getHostName()` to get the host IP. The second one sometimes returns a textual name of the local host and this info is not really useful as a source address unless there's a way to resolve that name.
  • Loading branch information
punarinta authored and mvayngrib committed Jan 1, 2020
1 parent b34d764 commit 7b7be6a
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected Void doInBackground(Pair<DatagramSocket, UdpReceiverTask.OnDataReceive
final InetAddress address = packet.getAddress();
final String base64Data = Base64.encodeToString(packet.getData(), packet.getOffset(),
packet.getLength(), Base64.NO_WRAP);
receiverListener.didReceiveData(base64Data, address.getHostName(), packet.getPort());
receiverListener.didReceiveData(base64Data, address.getHostAddress(), packet.getPort());
} catch (IOException ioe) {
if (receiverListener != null) {
receiverListener.didReceiveError(ioe.getMessage());
Expand Down

0 comments on commit 7b7be6a

Please sign in to comment.