1 / 9

Advanced UNIX programming

Advanced UNIX programming. Fall 2002 Instructor: Ashok Srinivasan Lecture 17. Acknowledgements: The syllabus and power point presentations are modified versions of those by T. Baker and X. Yuan. Announcements. Reading assignment Chapters 3 and 4 of UNP Collect midterm from me

Télécharger la présentation

Advanced UNIX programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Advanced UNIX programming Fall 2002 Instructor: Ashok Srinivasan Lecture 17 Acknowledgements: The syllabus and power point presentations are modified versions of those by T. Baker and X. Yuan

  2. Announcements • Reading assignment • Chapters 3 and 4 of UNP • Collect midterm from me • ... during my office hours • T 2:15-3:15 pm or W 2:15-3:15 pm • If you have questions on HW2 results, meet the grader

  3. Week 7 Topics • Basic TCP sockets • Socket address structure • Byte ordering and manipulation functions • socket, connect, bind, listen, accept • Client-Server design • Concurrent server

  4. Basic TCP sockets • Socket address structure • Byte ordering and manipulation functions • socket, connect, bind, listen, accept

  5. Socket address structure struct in_addr { in_addr_t s_addr; } struct sockaddr_in { uint8_t sin_len; sa_family_t sin_family; in_port_t sin_port; struct in_addr sin_addr; char sin_zero[8]; } • Always use sockaddr_in type for manipulation and convert it to sockaddr • See example1.c and example2.c struct sockaddr { uint8_t sa_len; sa_family_t sa_family; char sa_data[14]; }

  6. Network byte order • What happen when we run example2.c as server on program and example1.c as client on linprog? • sin_port and sin_addr must be in network byte order • Check example3.c • What is the difference between program and linprog?

  7. Byte ordering functions • #include <arpa/inet.h> uint16_t htons(uint16_t host16bitvalue); uint32_t htonl(uint32_t host32bitvalue); uint16_t ntohs(uint16_t net16bitvalue); uint32_t ntohl(uint32_t net32bitvalue); • See example3.c

  8. Byte manipulation functions • #include <string.h> void *memset(void *dst, int c, size_t len); void *memcpy(void *dst, void *src, size_t nbytes); void *memcmp(const void *ptr1, const void *ptr2, size_t nbytes);

  9. Address conversion functions • #include <arpa/inet.h> • in_addr_t inet_addr(const char *cp); • char *inet_ntoa(struct in_addr in); • The ones below should be preferred • inet_ntop(address family, source, destination, size); • inet_pton(address family, source, destination);

More Related