Questions tagged [gethostbyname]
140 questions
29
votes
4 answers
Compile a static binary which code there a function gethostbyname
How to resolve compile a static binary which code include a function gethostbyname and if compiled without warning like this:
warning: Using 'gethostbyname' in statically linked applications
requires at runtime the shared libraries from the glibc…

Loren Ramly
- 1,091
- 4
- 13
- 21
16
votes
3 answers
gethostbyname in C
I don't know how to write applications in C, but I need a tiny program that does:
lh = gethostbyname("localhost");
output = lh->h_name;
output variable is to be printed.
The above code is used in PHP MongoDB database driver to get the hostname of…

Matic
- 469
- 2
- 8
- 16
11
votes
2 answers
Python attribute error: type object '_socketobject' has no attribute 'gethostbyname'
I am trying to do this in my program:
dest = socket.gethostbyname(host)
I have included the line:
from socket import *
in the beginning of the file.
I am getting this error:
AttributeError: type object
'_socketobject' has no attribute
…

Sheela
- 111
- 1
- 1
- 3
9
votes
2 answers
How to flush cache for socket.gethostbyname response?
Anyone run into this before:
After updating DNS records..I do a dig for 'test.somedomain.com' I get 167.69.143.234, however when I do a socket.gethostbyname('test.somedomain.com') I get 167.69.6.234.
I'm guessing socket is still using cache...how…

Jim
- 613
- 6
- 16
- 25
7
votes
2 answers
Difference between GetHostEntry and GetHostByName?
On MSDN it mentions GetHostByName is obsolete. The replacement is GetHostEntry. What are their difference?

KMC
- 19,548
- 58
- 164
- 253
7
votes
2 answers
What's wrong with gethostbyname?
I am using this snippet of code I found in http://www.kutukupret.com/2009/09/28/gethostbyname-vs-getaddrinfo/ to perform dns lookups
#include
#include
#include
#include
#include
#include…

Ottavio Campana
- 4,088
- 5
- 31
- 58
7
votes
1 answer
IP address order in gethostbyname function
Since I got no answer on my previous question, I will rephrase it.
What order of IP addresses (in case when IP addresses are bound to one interface) is used when doing gethostbyname() using PC name (NetBIOS name)?
I have this code:
#include…

splattru
- 608
- 1
- 9
- 19
6
votes
3 answers
nodejs cannot resolve 'localhost' on windows
The following code produces an exception in node.js under windows:
var Socket = require("net").Socket;
socket = new Socket();
socket.connect(80, "localhost");
here's the message:
events.js:2083: Uncaught Error: getHostByName ENOTFOUND
When I…

Corno
- 5,448
- 4
- 25
- 41
6
votes
3 answers
Alternative to gethostbyname
I can't use gethostbyname to grab a host's IP address, it is a deprecated function that only works 10% of the fricken' time on Windows!
I can't find any adequate resources on other ways to find a host's IP address using other functions (MSDN…

Saustin
- 1,117
- 6
- 15
- 27
6
votes
2 answers
Asynchronous address resolution in winsock?
Looking into asynchronous address resolution in winsock it seems that the only two options are either to use the blocking gethostbyname on a seperate thread, or use WSAAsyncGetHostByName. The latter is designed for some reason to work with window…

sold
- 2,041
- 5
- 25
- 32
6
votes
2 answers
PHP: gethostbyname bug
I am using gethostbyname() to get the ip address of domains in an application.
In some cases invalid addresses like '50.9.49' are checked also.
echo gethostbyname('50.9.49'); // returns 50.9.0.49
In this cases gethostbyname should return false or…

Martin Abraham
- 752
- 7
- 24
4
votes
2 answers
When doing socket programming, what is the correct way to look up a domain name and then connect to it?
I've programmed networked applications, but primarily in Python.
I'm writing a C++ application and I'm a little fuzzy on exactly what the syntax should be to look up a domain name and connect to it's IP address.
Specifically, I'm not sure how to go…

EB.
- 3,383
- 5
- 31
- 43
4
votes
1 answer
Odd String Issue in C
I am writing some code that uses the function gethostbyname(). This function requires that I pass it a string of the host I am trying to find the host for. Right now I have my string declared in an array of characters, with a null byte at the end so…

user494216
- 522
- 4
- 7
- 13
4
votes
0 answers
Why `getaddrinfo` doesn't support aliases?
Unlike gethostbyname, the function getaddrinfo does not return a list of alias names for a hostname. What was the reason to not include this information in the getaddrinfo result?
I searched for a reference to this decision in:
IETF mail…

Christian Ammer
- 7,464
- 6
- 51
- 108
4
votes
1 answer
Connecting a socket, using getaddrinfo, times out
I spent hours trying to find out my issue, just found the solution as I was writing my question (it always help when you need to formalize your issue and explain it). I post it, hopefully it helps someone.
Using getaddrinfo, if I try to connect a…

Pellekrino
- 346
- 2
- 14