Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 11 Advanced Name and Address Conversion. Introduction gethostbyname, gethostbyaddr: protocol dependent getaddrinfo: –a function providing protocol.

Similar presentations


Presentation on theme: "Chapter 11 Advanced Name and Address Conversion. Introduction gethostbyname, gethostbyaddr: protocol dependent getaddrinfo: –a function providing protocol."— Presentation transcript:

1 Chapter 11 Advanced Name and Address Conversion

2 Introduction gethostbyname, gethostbyaddr: protocol dependent getaddrinfo: –a function providing protocol independence for appications –get a member of socket address structure getnameinfo

3 getaddrinfo Function #include int getaddrinfo(const addr *hostname, const char *service, const struct addrinfo *hints, struct addrinfo **result); returns : 0 if OK, nonzero on error struct info { int ai_flags; // AI_PASSIVE, AI_CANONNAME int ai_family; // AF_XXX int ai_socktype; // SOCK_XXX int ai_protocol; // 0 or IPPROTO_xxx for IPv4 and IPv6 size_t ai_addrlen; // length of ai_addr char *ai_canonname; // ptr to cannonical name for host struct sockaddr *ai_addr; // ptr to socket address structure struct addrinfo *ai_next; // ptr to next structure in linked list };

4 hostname: – a hostname or an address string(dotted-decimal for IPv4 or a hex string for IPv6) service –a service name or a decimal port number string hints –a null pointer or a pointer to an addrinfo structure that the caller fills in ai_flags: AI_PASSSIVE, AI_CANONNAME ai_family (an AF_xxx value) ai_socktype (a SOCK_xxx value ai_protocol

5 Result –a pointer to a linked list of addrinfo structures –four addrinfo structures for hint: null, two IP address first IP address, SOCK_STREAM first IP address, SOCK_DGRAM second IP address, SOCK_STREAM second IP address, SOCK_DGRAM see Figure 11.1

6

7 gai_strerror function #include char *gai_strerror(int error); returns: pointer to string describing error message

8 freeaddrinfo function #include void freeaddrinfo(struct addrinfo *ai)

9 getaddrinfo Function: IPv6 and unix Domain

10 getaddrinfo Function:Examples testga –f inet: the address family –c : the canonical name –h bsdi: the hostname –s domain: the service name

11 Testga -f inet -t stream -h gateway.tuc.noao.edu -s daytime (-t socktype, -s service name) testga -h alpha -s ftp testga -p -s 8888 (-p AI_PASSIVE) testga -c -p -h /local -s /tmp/test.1

12 host_serv function

13

14 >daytimetcpcli bsdi daytime connected to 206.62.226.35 Fri May 30 12:33:32 1999 >daytimetcpcli aix daytime

15 tcp_listen function #include “unp.h” int tcp_listen(const char *hostname, const char *service, socklen_t *lenptr); -create a TCP socket, bind the server’s well-known port -allow incoming connection requests to be accepted

16

17

18 Udp_client function unconnected UDP #include “unp.h” int udp_client(const char *hostname, const char *service, void **saptr, socklen_t *lenp);

19

20

21 udp_connect function #include “unp.h” int udp_connect(const char *hostname, const char *service); udp_server function #include “unp.h” int udp_server(const char *hostname, const char *service, socklen_t *lenptr);

22

23

24

25 getnameinfo function Takes a socket address and returns a character string describing the host and another character nstring describing the service #include int getnameinfo(const struct sockaddr *sockaddr, socklen_t addrlen, char *host, size_t hostlen, char *serv, size_t servlen, int flags);


Download ppt "Chapter 11 Advanced Name and Address Conversion. Introduction gethostbyname, gethostbyaddr: protocol dependent getaddrinfo: –a function providing protocol."

Similar presentations


Ads by Google