Advanced UNIX programming - PowerPoint PPT Presentation

About This Presentation
Title:

Advanced UNIX programming

Description:

What happen when we run example2.c as server on program and example1.c as client ... What is the difference between program and linprog? Network byte order ... – PowerPoint PPT presentation

Number of Views:108
Avg rating:3.0/5.0
Slides: 10
Provided by: asri9
Learn more at: http://www.cs.fsu.edu
Category:
Tags: unix | advanced | programming | run | up

less

Transcript and Presenter's Notes

Title: Advanced UNIX programming


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 215-315 pm or W 215-315 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_zero8
  • 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_data14
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 ltarpa/inet.hgt
  • 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 ltstring.hgt
  • 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 ltarpa/inet.hgt
  • 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)
Write a Comment
User Comments (0)
About PowerShow.com