110 likes | 273 Views
Chapter9 Elementary Name and Address Conversions. Introduction. Domain Name Server gethostbyname Function. gethostbyaddr Function. uname Function. gethostname Function. getsvrbyname & getsvrbyport Function. Domain Name System. FQDN(Fully qualified domain name) ex) comedu.chungbuk.ac.kr.
E N D
Chapter9 Elementary Name and Address Conversions
Introduction • Domain Name Server • gethostbyname Function. • gethostbyaddr Function. • uname Function. • gethostname Function. • getsvrbyname & getsvrbyport Function.
Domain Name System • FQDN(Fully qualified domain name) ex) comedu.chungbuk.ac.kr. • RRs(Resource Records)
Application Application code UDP request Function call Function return Resolver code Local name server Other name server UDP reply Resolver configuration files Resolvers and Name Servers /etc/resolv.conf Typical arrangement of clients, resolvers, and name servers
official hostname \0 Alises #1 \0 hostent{} Alises #2 \0 h_name h_aliases NULL h_addrtype AF_INET In_addr{} IP addr #1 h_length 4 In_addr{} h_addr_list IP addr #2 In_addr{} IP addr #3 NULL h_length =4 gethostbyname Function #include <netdb.h> struct hostent *gethostbyname (const char *hostname); struct hostent { char *h_name; /* official (canonical) name of host */ char **h_aliases; /* pointer to arrayof opinters to alises names */ int h_addrtype; /* host address type : AF_INET or AF_INET6 */ int h_length; /* length of address : 4 or 6 */ char **h_addr_list; /* ptr to array of ptrs with IPv4 or IPv6 addrs */ };
RES_USE_INET6 Resolver Option 1. #include <resolv.h> res_init(); _res.option |= RES_USE_INET6; 2. export RES_OPTION=inet6; (shell once) (in .profile One User Only) 3. options inet6 (in /etc/resolv.conf) if all program support IPv6
gethostbyname2 Function #include <netdb.h> struct hostent *gethostbyname2 (const char *hostname, int family);
gethostbyaddr Function • The field of interest in this structure is normally h_name, the canonical hostname #include <netdb.h> struct hostent *gethostbyaddr(const chr *addr, size_t len,int family);
uname Function #include <netdb.h> int uname(struct utsname *name); #define _UTS_NAMESIZE 16 #define _UTS_NODESIZE 256 struct ntsname { char sysname[_UTS_NAMESIZE]; /* name of this operationg system */ char sysname[_UTS_NAMESIZE]; /* name of this node */ char sysname[_UTS_NAMESIZE]; /* O. S. release level */ char sysname[_UTS_NAMESIZE]; /* O. S. version level */ char sysname[_UTS_NAMESIZE]; /* hardware type */ }; gethostname Function #include <netdb.h> int gethostname(char *name, size_t namelen);
getservbyname Function #include <netdb.h> struct servent *getservbyname(const char *servname, const char *protoname); struct servent { char *s_name; /* official service name */ char **s_ aliases; /* aliases list*/ int s_port; /* port number, network by order */ char *s_proto; /* protocol to use */ }; getservbyport Function #include <netdb.h> struct servent *getservbyport(int port, const char *protoname);