Presentation is loading. Please wait.

Presentation is loading. Please wait.

Advanced UNIX programming Fall 2002 Instructor: Ashok Srinivasan Lecture 17 Acknowledgements: The syllabus and power point presentations are modified versions.

Similar presentations


Presentation on theme: "Advanced UNIX programming Fall 2002 Instructor: Ashok Srinivasan Lecture 17 Acknowledgements: The syllabus and power point presentations are modified versions."— 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 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]; } Socket address structure

6 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? Network byte order

7 –#include 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 Byte ordering functions

8 –#include 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); Byte manipulation functions

9 Address conversion functions #include –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);


Download ppt "Advanced UNIX programming Fall 2002 Instructor: Ashok Srinivasan Lecture 17 Acknowledgements: The syllabus and power point presentations are modified versions."

Similar presentations


Ads by Google