Programming with TCP/IP - PowerPoint PPT Presentation

About This Presentation
Title:

Programming with TCP/IP

Description:

Socket system calls for connection-oriented protocol socket() bind() listen() accept() Client blocks until connection from client socket() connection establishment ... – PowerPoint PPT presentation

Number of Views:40
Avg rating:3.0/5.0
Slides: 7
Provided by: Johnn338
Category:

less

Transcript and Presenter's Notes

Title: Programming with TCP/IP


1
Socket system calls for connection-oriented proto
col
2
Not necessary in UDP!!
3
Socket system call
  • int sockfd socket (int family, int type, int
    protocol
  • Family AF_UNIX, AF_INET Type SOCK_STREAM,
    SOCK_DGRAM, SOCK_RAW
  • struct sockaddr
  • unsigned short sa_family
    //specifies the address type
  • char sa_data14
    //specifies the address value
  • struct sockaddr_in
  • short sin_family
  • unsigned short sin_port 16 bit
  • struct in_addr sin_addr 32 bit unsigned long
    s_addr
  • char sin_zero8

4
Network Byte Order Functions
  • Example
  • struct sockaddr_in sin
  • sin.sin_family AF_INET
  • sin.sin_port htons(9999)
  • sin.sin_addr.s_addr inet_addr(130.233.224.13)
  • inet_aton(130.233.224.13, sin.sin_addr)
  • unsigned short htons(unsigned short)
  • unsigned short ntohs(unsigned short)
  • unsigned long htonl(unsigned long)
  • unsigned long ntohl(unsigned long)

5
Server system calls
  • int bind(int sockfd, struct sockaddr myaddr, int
    addrlen)
  • int listen(int socket, int qlength)
  • !newsockfd accept(int sockfd, void peer, int
    addrlen)
  • int getpeername(int sockfd, struct sockaddr
    addr, int addrlen)
  • struct hostent gethostbyaddr(const char
    peer_addr, int len, int type)
  • ! (char) socaddr_in.sin_addr, name in
    hostent-gth_name

6
Client system calls
  • int connect(int sockfd, struct sockaddr
    servaddr, int addrlen)
  • struct hostent gethostbyname(const char name)
  • ! addr.sin_addr ((struct in_addr )
    hostent-gth_addr)
  • write or read(fd, buff_ptr, num_bytes)
  • int send(int s, const char msg, int len, int
    flags)
  • int recv(int s, char buf, int len, int flags)
  • flags MSG_PEEK, MSG_OOB etc.
  • close(int socket), shutdown(int socket, int how)
Write a Comment
User Comments (0)
About PowerShow.com