Unformatted text preview:

111CMSC 212 – S07 (lect 19)AnnouncementsProject #3– grades are available on grades.cs.umd.eduProject #4– Use gdb and valgrind– test cases given are only a subsetExam– Tuesday April 10 – 6:00-7:30pm – ARM 0126– No class on that day – extra study timeReading– socket handout - on web (Today)– notes (Thursday)2CMSC 212 – S07 (lect 19)Internet AbstractionsDomain Name System– character strings to represent names– Example name: mashie.cs.umd.eduIP Address (in IPv4)– 32 bit value that describes a network card– Example address: 128.8.129.30Port (TCP)– 16 bit endpoint for communication on a machine– Well known ports:• used to connect to a service (e.g. 80 is HTTP)– Machine assigned:• used for incoming connections223CMSC 212 – S07 (lect 19)– Unique identification of communication• 4 tuple of <[srcIp,srcPort], [destIp, destPort]>Networking Port: 25Port: 80Port: 666Port: 12344CMSC 212 – S07 (lect 19)Network API Typesstruct hostent– represents a host– struct hostent * gethostbyname(char *name);• returns the information about the passed host namestruct sockaddr– end point for communication– can be used for IP or other protocols toostruct sockaddr_in– defines an endpoint on an IP network– contains fields for src/dest IP addr and src/dest portfile descriptor– used to refer to an active socet335CMSC 212 – S07 (lect 19)Socket API Calls (Client)int socket(int domain, int type, int protocol);– create a new socket– typical usage:• fd = socket(AF_INET, SOCK_STREAM, 0);• creates a TCP socketint connect(int sockfd, struct sockadrr*server, int len);– connect to the remote host/port described by sockaddr– sockfd must be a previously created socket– len is the size of struct sockaddr6CMSC 212 – S07 (lect 19)Socket API Calls (Server)int bind(int sockfd, struct sockaddr *addr, int len);– bind a local port to the passed socket– port is specificed in the passed sockaddrint listen(int sockfd, int backlog);– inform OS to let connections happen on the passed sock– allow at most backlog pending connectionsint accept(int sockfd, struct sockaddr *addr, int len);– blocks until a connection arrives on passed sockfd– returns a new file descriptor for the active connection– fill out addr with information about established connection447CMSC 212 – S07 (lect 19)Network API - Using and Open SocketSockets can be read/written just like other fdFILE *ofp, ifp;int serverfd;serverfd = openserverfd("www.dyninst.org", 80) ;ofp = fdopen(serverfd, "w");if (!ofp) exit (-1);ifp = fdopen(serverfd, "r");if (!ifp) exit(-1);fprintf(ofp, "GET index.html\n");while (fgets(line, sizeof(line), ifp)) {printf(line);}8CMSC 212 – S07 (lect 19)Other DetailsFor example– see Client.Server/client.c– see Client.Server/server.cWhen done with a socket– use close to


View Full Document

UMD CMSC 212 - Lecture Slides

Download Lecture Slides
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Slides and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Slides 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?