Hostnet structure struct hostent char *h name Official name of host */ char **h aliases: Alias list. * int h addrtype Host address type. * int h length / Length of address. * char **h addr list:; / List of addresses from name server. */ #define h addr h addr list[0]/Address, for backward compatibility. * CSIE NTUT Taiwan
CSIE, NTUT, Taiwan 11 Hostnet Structure struct hostent { char *h_name; /* Official name of host. */ char **h_aliases; /* Alias list. */ int h_addrtype; /* Host address type. */ int h_length; /* Length of address. */ char **h_addr_list; /* List of addresses from name server. */ }; #define h_addr h_addr_list[0] /* Address, for backward compatibility. */
Looking up a Well-known Port b Name Client also needs to look up the protocol port for the specific service Example A client of an SMTP mail server needs to look up the well-known port assigned to SMTP a Library function, getservbyname, can do this a Takes two arguments(strings) ■ Service ■ Protocol Returns a pointer to servent structure CSIE NTUT Taiwan
CSIE, NTUT, Taiwan 12 Looking up a Well-known Port by Name ◼ Client also needs to look up the protocol port for the specific service ◼ Example ◼ A client of an SMTP mail server needs to look up the well-known port assigned to SMTP ◼ Library function, getservbyname, can do this ◼ Takes two arguments (strings): ◼ Service ◼ Protocol ◼ Returns a pointer to servent structure
Servent structure struct servent char "s name /3 Official service name. i char **s aliases/* Alias list. Int s port; / Port number. */ charms proto /*x Protocol to use CSIE NTUT Taiwan
CSIE, NTUT, Taiwan 13 Servent Structure struct servent { char *s_name; /* Official service name. */ char **s_aliases; /* Alias list. */ int s_port; /* Port number. */ char *s_proto; /* Protocol to use. */ };
Looking up a protocol by name a Mapping a protocol name to the integer constant assigned to that protocol a Library function, getprotobyname, performs this lookup getprotobyname Takes a protocol name(in string) and returns the address of a protoent structure CSIE NTUT Taiwan
CSIE, NTUT, Taiwan 14 Looking up a Protocol by Name ◼ Mapping a protocol name to the integer constant assigned to that protocol ◼ Library function, getprotobyname, performs this lookup ◼ getprotobyname: Takes a protocol name (in string) and returns the address of a protoent structure
Protoent structure struct protoent char *p name /Official protocol name. char p aliases Alias list.米/ Int p proto /3 Protocol number. x/ CSIE NTUT Taiwan
CSIE, NTUT, Taiwan 15 Protoent Structure struct protoent { char *p_name; /* Official protocol name.*/ char **p_aliases; /* Alias list. */ int p_proto; /* Protocol number. */ };