I am making my own Iterative DNSresolver, where I need the ip of the host to use... but Datagrampacket requires InetAddresstype object. So I had to use the library function.
InetAddress ipAddress = InetAddress.getByName(DNSAddress);
....
//some code
....
DatagramPacket dnsReqPacket = new DatagramPacket(dnsFrame, dnsFrame.length, ip, DNSServerPort);
....
//some code
So, I was thinking is it possible to make my own getbyName() function without using the inetAddress library?
You can use java.net.InetAddress.getByAddress(byte[])
. It creates an InetAddress
object from the raw (network) representation of the address.
The method is rather confusingly named because unlike gethostbyaddr
, it does not perform a reverse lookup:
This method doesn't block, ie no reverse name service lookup is performed.
Using an InetAddress
created using getByAddress
together with DatagramPacket
or DatagramSocket
does not necessarily trigger name resolution, either, so there is no risk of infinite recursion (in case the Java implementation attempts to perform name resolution using your own DNS implementation).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.