Taz bisounours-codeur | si ça amuse quelqu'un, j'ai retrouvé ça : un exemple de ce qu'est la structure hostent
Code :
- #include <netdb.h>
- #include <stdio.h>
- int main(int argc, char *argv[])
- {
- while(--argc)
- {
- const struct hostent *h=gethostbyname(argv[argc]);
-
- if(h)
- {
- int i;
- printf("[ %s ]\n"
- "h_name = %s\n",
- argv[argc], h->h_name);
- if(h->h_aliases[0])
- {
- printf("h_aliases = \n" );
- for(i=0; h->h_aliases[i]; ++i)
- {
- printf("\t%s\n", h->h_aliases[i]);
- }
- }
- printf("h_addrtype = %d\n"
- "h_length = %d\n",
- h->h_addrtype,
- h->h_length);
-
- if(h->h_addr_list[0])
- {
- printf("h_addr_list = \n" );
- for(i=0; h->h_addr_list[i]; ++i)
- {
- printf("\t%u.%u.%u.%u\n",
- h->h_addr_list[i][0] & 0xff,
- h->h_addr_list[i][1] & 0xff,
- h->h_addr_list[i][2] & 0xff,
- h->h_addr_list[i][3] & 0xff
- );
- }
- }
- }
- putchar('\n');
- }
- return 0;
- }
|
|