dns
Constantinos A. Kotsokalis
C.Kotsokalis at ece.ntua.gr
Tue Mar 9 15:39:22 EET 1999
On 9 Mar 1999 12:37:34 +0200, Vasilis Vasaitis wrote:
> I gethostbyname dexetai mia xara _kai_ IP addresses (os strings vevaia).
>Me tin sigkekrimeni allagi, kliseis tou programmatos tou tipou `hostname
>127.0.0.1' eksakolouthoun na douleuoun to idio kala me prin.
Dokimh sxetika me auto:
#include <stdio.h>
#include <netdb.h>
#include <netinet/in.h>
main(int argc, char *argv[]){
struct hostent *hp;
struct in_addr ina;
hp = gethostbyname(argv[1]);
if (!hp){
printf("NULL\n");
exit(0);
}
else {
printf("Hostname: %s\n", hp->h_name);
while (*(hp->h_aliases)){
printf("Alias: %s\n", *(hp->h_aliases));
(hp->h_aliases)++;
}
printf("Address type: %d\n", hp->h_addrtype);
printf("Address length: %d\n", hp->h_length);
while (*(hp->h_addr_list)){
bcopy(*(hp->h_addr_list), (char *)&ina, hp->h_length);
printf("IP address: %s\n", inet_ntoa(ina));
(hp->h_addr_list)++;
}
}
}
Tre3imo tou parapanw:
root at geek ~/tmp # ./a.out 147.102.223.210
Hostname: 147.102.223.210
Address type: 2
Address length: 4
IP address: 147.102.223.210
Opws blepeis, den brhke onoma... Opote auto pou epistrefei h gethostyname()
me argument IP address einai toulaxiston elleipes. Par'ola auta, gia to
poly sygkekrimeno pou h8ele o filos mas (hostname->IP) nai h gethostbyname()
apo monh ths tha doulebe mia xara.
Costas
--
Constantinos A. Kotsokalis || C.Kotsokalis at ece.ntua.gr
National Technical University of Athens - GREECE
Electrical and Computer Engineering Department
"111111111 * 111111111 = 12345678987654321"
--
====================================================================
Gia boithia (h na diagrafhte) e-mail sto majordomo at hellug.gr
Ta archives tis listas einai sto http://lists.hellug.gr
prin steilete kapoia erothsh psakte mipos exei hdh apanththei.
Gia opoiodipote problima stilte e-mail ston owner-linux-greek-users
====================================================================
More information about the Linux-greek-users
mailing list