Download presentation
Presentation is loading. Please wait.
1
PF_INET versus AF_INET AF_ -- address family PF_ -- protocol family Historically the intent was that a single protocol family might support multiple address families PF_ value: to create the socket AF_ value: used in socket address structure. Actually, a protocol family supporting multiple address families has never been supported defines PF_ value for a given protocol to be equal to the AF_ value
2
errno value When an error occurs in a unix function ( such as one of the socket function), the global variable errno is set to a positive value indicating the type of error and the function normally return –1. The value of errno is set by a function only if an error occurs. Its value is undefined if the function does not return an error Example: printout “connection timed out” if errno equals ETIMEDOUT
3
Read () Read function takes three arguments: –Descriptor –Buffer address –Number of bytes to read N = read( s, buff, 24); Read 24 bytes of data from descriptor s If an application attempts to read more bytes than the file contains, the read function extracts as many as the s contains and return the number read as its result.
4
Read() continued If the file is positioned at the end of a file when an application calls read, the read call returns zero to indicate an end-of-file condition.
5
Loop to read data while( (n = read(s,buff,MAXLINE))>0) { buff[n] = 0; // null terminate if( fputs(buff, stdout) == EOF) { printf(“fputs error\n”); exit(0); } if( n < 0) { printf(“read error\n”); printf(“ %s \n”, strerror(errno)); exit(0); }
6
fgetc reads a character from a specified file fputc write a character to a specified file fgets(buff, desc) read a line from a specified file. fputs(buff, desc) write a line to a specified file
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.