Getting hostname of remote machine with gethostbyaddr()
Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Getting hostname of remote machine with gethostbyaddr()
This program is to find the hostname of a given IPv4 address. The problem
is that it works only for some IPs and does not for some others (refer
output).
Perhaps this means that I need to enable some services or set some configuration files for it to work properly?
The name server on the network is 192.168.240.1. Other relevant files are pasted inline.
Please help!
luv
thomas
------------------------
My program: ip2hostname.c
------------------------
-------------------
My /etc/hosts file
-------------------
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
192.168.240.64 thomas
----------------------
My /etc/host.conf file
----------------------
order bind,hosts
----------------------------
The output I get
----------------------------
[root@thomas root]# ./ip2hostname 192.168.240.64
Hello world! thomas
#Entry there in /etc/hosts
[root@thomas root]# ./ip2hostname 127.0.0.1
Hello world! localhost.localdomain
#Entry there in /etc/hosts
[root@thomas root]# ./ip2hostname 192.168.240.1
Hello world! server.ushustech.com
#not there in /etc/hosts, so contact made with network i guess
[root@thomas root]# ./ip2hostname 192.168.240.2
Could not locate 192.168.240.2
#i could successfully ping it though
[root@thomas root]# ./ip2hostname 192.168.240.3
Hello world! mail.ushustech.com
#again, not there in /etc/hosts.
[root@thomas root]# ./ip2hostname 192.168.240.4
Hello world! ushusweb.ushustech.com
#again, not there in /etc/hosts.
[root@thomas root]# ./ip2hostname 192.168.240.5
Could not locate 192.168.240.5
#ping worked fine!
[root@thomas root]# ./ip2hostname 192.168.240.6
Could not locate 192.168.240.6
#ping worked.
[root@thomas root]# ./ip2hostname 192.168.240.7
Hello world! owa.ushustech.com
#again, not there in /etc/hosts.
[root@thomas root]# ./ip2hostname 192.168.240.8
Hello world! zafin.ushustech.com
#again, not there in /etc/hosts.
[root@thomas root]# ./ip2hostname 192.168.240.9
Could not locate 192.168.240.9
#ping worked
[root@thomas root]# ./ip2hostname 192.168.240.10
Could not locate 192.168.240.10
#again ping worked. system very much present.
[root@thomas root]# ./ip2hostname 192.168.240.132
Hello world! vinodh.ushustech.com
#again, not there in /etc/hosts. from the network! hurray?
----------------------
my /etc/resolv.conf
----------------------
search ushustech.com
nameserver 192.168.240.1
--------------------------
the server 192.168.240.1 is a Windows machine. Could that be the problem? Do I need to do anything at the server-end?
My code seems to work fine (unchanged) when i run it from Windows using Winsock. I am very much puzzled! I thought -nix OSes had better support for networking than you-know-what. :-(
windows machines are rather chatty on the network. By default they broadcast thier address and any available services periodically. *nixes generally only speak when they are spoken to.
There is a problem with your DNS server. You may not have A record entries for each host. I don't know how you have your DNS set up. It could be active directory or using WINS to dynamically update DNS or neither. In any case, there is nothing wrong with the code because it compiles and runs fine on my BSD box.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.