We will see in chapter 5 that the code does not work

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: fprintf(stderr, "pthread_create error: %s\n", strerror(retcode)); exit(0); } DNS-style error handling The gethostbyname and gethostbyaddr functions that retrieve DNS (Domain Name System) host entries have yet another approach for returning errors. These functions return a NULL pointer on failure and set the global h errno variable. DNS-style error handling is typically of the form: 1 2 3 4 if ((p = gethostbyname(name)) == NULL) { fprintf(stderr, "gethostbyname error: %s\n:", hstrerror(h_errno)); exit(0); } A.3. ERROR-HANDLING WRAPPERS The hstrerror function returns a text description for a particular value of h errno. 667 Summary of error-reporting functions Thoughout this book, we use the following error-reporting functions to accomodate different error-handling styles. #include "csapp.h" void void void void unix error(char *msg); posix error(int code, char *msg); dns error(char *msg); app error(char *msg); return: nothing As their names suggest, the unix error, posix error, and dns error functions report Unix-style errors, Posix-style, and DNS-style errors and then terminate. The app error func...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online