Questions tagged [hostent]
9 questions
24
votes
4 answers
Does struct hostent have a field "h_addr"?
I encountered the following code snapshot:
struct hostent *hp;
hp = my_gethostbyname(localhost);
if (hp == NULL) {
ls_syslog(LOG_ERR, I18N_FUNC_FAIL, fname, "my_gethostbyname()");
return -1;
}
strcpy(localhost,…

wangshuaijie
- 1,821
- 3
- 21
- 37
6
votes
5 answers
Segmentation fault when looking up host name and IP address
I have the following piece of code for getting the hostname and IP address,
#include
#include
#include /* This is the header file needed for gethostbyname() */
#include
#include
#include…

Biranchi
- 16,120
- 23
- 124
- 161
1
vote
1 answer
Loop to get multiple entries in host, network, protocol, and service database
I am having a hard time understanding a previous assignment. I was to use functions given in the Addison-Wesley Advanced Programming in the UNIX Environment Third edition text (chapter 16.3.3) to print the host, network, protocol, and services…

Dawson Binder
- 25
- 4
1
vote
0 answers
Memcpy and hostent struct on C
So gethostbyaddr() returns a hostent.
struct hostent {
char *h_name; /* official name of host */
char **h_aliases; /* alias list */
int h_addrtype; /* host address type */
int h_length; /*…

Loperena
- 11
- 1
- 2
1
vote
2 answers
Is gethostbyname guaranteed to return hostent structures with IPv4 addresses?
I cannot use getaddrinfo(...) for resolving hostnames and therefore must stick to gethostbyname(...)
Is the gethostbyname(...) function guaranteed to return hostent structures that contain only IPv4 (AF_INET) addresses on success, so that the…

Robert
- 878
- 6
- 14
1
vote
2 answers
Failing with gethost() (use Net::hostent)
I am doing something wrong here and I don't know what. This small program is supposed to take the 4 IPv4 addresses listed and use hostent's gethost() to resolve the Domain. If it fails, it keeps the IPv4 format.
Output:
180.76.5.59 has a hostname of…

Alex Bacon
- 13
- 2
0
votes
0 answers
Hostent returning null from char* . Works with hardcoded address
people.
I know hostent is deprecated but have to use it for a project.
For some reason if I do this...
hp = getbyhostname ("www.google.com");
hp works all right.
But then, if I do this:
char *addre;
addre = someFunction();
printf ("The address is…
0
votes
3 answers
Issues with 'operator=' and sockaddr members
im getting issues with the folowing code:
#include
#include "socket.h"
#define INVALID_SOCKET -1
#define SOCKET_ERROR -1
int SenderAddrSize = sizeof(sockaddr);
sockaddr CSocket::SenderAddr;
bool CSocket::tcpconnect(char *address, int…

Nicholas Terry
- 1,812
- 24
- 40
0
votes
1 answer
Why does this hostent cause a segfault?
struct hostent *hostName;
struct in_addr ipv4addr;
inet_pton(AF_INET, inet_ntoa(client.sin_addr), &ipv4addr);
hostName = gethostbyaddr(&ipv4addr, sizeof(ipv4addr), AF_INET);
printf("Host name: %s\n", hostName->h_name);
It segfaults on the last…

porque_no_les_deux
- 479
- 1
- 6
- 18