PF_INET versus AF_INET AF_ -- address family PF_ -- protocol family Historically the intent was that a single protocol family might support multiple address.

Slides:



Advertisements
Similar presentations
Ipv4 Socket Address Structure struct in_addr { in_addr_t s_addr; /* 32-bit IPv4 address */ /* network byte ordered */ }; struct sockaddr_in { uint8_t sin_len;
Advertisements

Lecture 6 TCP Socket Programming CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
Socket Programming Application Programming Interface.
CSCI 171 Presentation 12 Files. Working with files File Streams – sequence of data that is connected with a specific file –Text Stream – Made up of lines.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Introduction Data files –Can be created, updated,
 2000 Prentice Hall, Inc. All rights reserved. Chapter 11 – File Processing Outline 11.1Introduction 11.2The Data Hierarchy 11.3Files and Streams 11.4Creating.
 2007 Pearson Education, Inc. All rights reserved C File Processing.
Networks: TCP/IP Socket Calls1 Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Chapter 11 C File Processing Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
Sockets Basics Conectionless Protocol. Today IPC Sockets Basic functions Handed code Q & A.
Windows Sockets Purpose Windows Sockets 2 (Winsock) enables programmers to create advanced internet, intranet, and other network-capable applications to.
Socket Addresses. Domains Internet domains –familiar with these Unix domains –for processes communicating on the same hosts –not sure of widespread use.
1 Nonblocking I/O Nonblocking reads and writes Buffers enabling overlapped nonblocking I/O Nonblocking connect.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
Console and File I/O - Basics Rudra Dutta CSC Spring 2007, Section 001.
Files Programs and data are stored on disk in structures called files Examples Turbo C++ - binary file Word binary file lab1.c - text file lab1.data.
Network Programming Tutorial #9 CPSC 261. A socket is one end of a virtual communication channel Provides network connectivity to any other socket anywhere.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 14 - Advanced C Topics Outline 14.1Introduction 14.2Redirecting Input/Output on UNIX and DOS Systems.
Sirak Kaewjamnong Computer Network Systems
Server Sockets: A server socket listens on a given port Many different clients may be connecting to that port Ideally, you would like a separate file descriptor.
Recitation 9: Error Handling, I/O, Man Andrew Faulring Section A 4 November 2002.
CS162B: Pipes Jacob T. Chan. Pipes  These allow output of one process to be the input of another process  One of the oldest and most basic forms of.
File IO and command line input CSE 2451 Rong Shi.
Chapter 8 File-Oriented Input and Output. 8.1 INTRODUCTION a file can also be designed to store data. We can easily update files, A data file as input.
Shell (Addendum). Example r What if we want to support something like this: m ps –le | sort r One process should execute ps –le and another should execute.
ECE 103 Engineering Programming Chapter 44 File I/O Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103 material developed.
1 File Handling. 2 Storage seen so far All variables stored in memory Problem: the contents of memory are wiped out when the computer is powered off Example:
Socket Programming Lab 1 1CS Computer Networks.
Artificial Intelligence Lecture No. 26 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
Chapter 11: Data Files and File Processing Files and streams Creating a sequential access file Reading data from a sequential access file Using fgetc()
Chapter 11 File Processing. Objectives In this chapter, you will learn: –To be able to create, read, write and update files. –To become familiar with.
 2000 Prentice Hall, Inc. All rights reserved Introduction Data files –Can be created, updated, and processed by C programs –Are used for permanent.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 11 – File Processing Outline 11.1Introduction.
Chapter 7 : File Processing1 File-Oriented Input & Output CHAPTER 7.
1 CHAPTER6 CHAPTER 6. Objectives: You’ll learn about;  Introduction  Files and streams  Creating a sequential access file  Reading data from a sequential.
chap8 Chapter 12 Files (reference: Deitel ’ s chap 11)
Intro to Socket Programming CS 360. Page 2 CS 360, WSU Vancouver Two views: Server vs. Client Servers LISTEN for a connection and respond when one is.
Recitation 9: Error Handling, I/O, Man Anubhav Gupta Section D.
CSCI 330 UNIX and Network Programming Unit XVI: TCP Server Programming.
I/O Multiplexing Chap 6. I/O Models  Blocking I/O Model  Nonblocking I/O Model  I/O Multiplexing Model  Signal Driven I/O Model  Asynchronous I/O.
Learners Support Publications Working with Files.
Files A collection of related data treated as a unit. Two types Text
Files. FILE * u In C, we use a FILE * data type to access files. u FILE * is defined in /usr/include/stdio.h u An example: #include int main() { FILE.
Lecture 20: C File Processing. Why Using Files? Storage of data in variables and arrays is temporary Data lost when a program terminates. Files are used.
C Programming Day 2. 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/LA07/003 Version No. 1.0 Union –mechanism to create user defined data types.
Lecture 3 TCP and UDP Sockets CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
Socket Programming in C CS587x Lecture 3 Department of Computer Science Iowa State University.
Real Numbers Device driver process within the operating system that interacts with I/O controller logical record 1 logical record 2 logical record 3.
1 Socket Interface. 2 Basic Sockets API Review Socket Library TCPUDP IP EthernetPPP ARP DHCP, Mail, WWW, TELNET, FTP... Network cardCom Layer 4 / Transport.
File I/O. I/O Flags Flags are passed to give some information about how the file is to be used. – Read only file – flag=0x0 – Write only file – flag=0x1.
UNIX AND POSIX APIs APIs – a set of application programming
Lesson One – Creating a thread
Review: TCP Client-Server Interaction
CSE1320 Files in C Dr. Sajib Datta
CSE1320 Files in C Dr. Sajib Datta
Files I/O, Streams, I/O Redirection, Reading with fscanf
Pipes A pipe provides a one-way flow of data example: who | sort| lpr
Beginning C Lecture 11 Lecturer: Dr. Zhao Qinpei
TCP Sockets Programming
Advanced Network Programming spring 2007
File I/O in C Lecture 7 Narrator: Lecture 7: File I/O in C.
File Input and Output.
Line at a time I/O with fgets() and fputs()
UNIX AND POSIX APIs APIs – a set of application programming
EPSII 59:006 Spring 2004.
Module 12 Input and Output
EECE.2160 ECE Application Programming
Professor Jodi Neely-Ritz University of Florida
System Programming: Process Management
Presentation transcript:

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

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

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.

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.

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); }

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