chapter3_4 - Chapter 3: Sockets Introduc4on Chapter...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Chapter 3: Sockets Introduc4on Chapter 4: Elementary TCP Sockets Figure 4.1: Socket func4ons for elementary TCP client and server int socket(int family, int type, int protocol); #include <sys/socket.h> int connect(int sd, const struct sockaddr *servaddr, socklen_t addrlen); Figure 3.1 The Internet (IPv4) socket address structure Figure 3.3 The generic socket address structure Figure 3.6 The Internet (IPv4) socket address structure Figure 3.7 Socket address structure passed from process to kernel #include <sys/socket.h> int bind(int sd, const struct sockaddr *servaddr, socklen_t addrlen); int listen(int sd, int backlog); #include <sys/socket.h> int accept(int sd, const struct sockaddr *cliaddr, socklen_t *addrlen); Figure 3.8 Socket address structure passed from kernel to process Figure 3.9 LiSle ­endian byte order and big ­endian byte order Byte ordering func4ons #include <ne4net/in.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) Byte manipula4on func4ons void bzero(void *dst, size_t nbytes); void bcopy(const void *src, void *dst, size_t nbytes); Int bcmp(const void *ptr1, const void *ptr2, size_t nbytes); void *memset(void *dst, int c, size_t len); void *memcpy(void *dst, const void *src, size_t nbytes); Int memcmp(const void *p1, const void *p2, size_t nbytes); Address conversion func4ons int inet_aton(const char *strptr, struct in_addr *addrptr); in_addr_t inet_addr(const char *strptr); char *inet_ntoa(struct in_addr inaddr); int inet_pton(int family, const char *strptr, void *addrptr); const char *inet_ntop(int family, const void *addrptr, char *strptr, size_t len); Figure 4.11: Day4me server that prints clients IP address and port #include <unistd.h> pid_t fork(); int execl(const char *pathname, const char*arg0, … /* (char *) 0 */); int execv(const char *pathname, char *const argv); int execle(const char *pathname, const char*arg0, … /* (char *) 0 */), char *const envp); int execve(const char *pathname, char *const argv, char *const envp) int execlp(const char *filename, const char*arg0, … /* (char *) 0 */); int execvp(const char *filename, char *const argv); Figure 4.12: Rela4onship among the six exec func4ons Figure 4.13: Outline for typical concurrent server Figure 4.14: Status of client/server before call to accept returns Figure 4.15: Status of client/server acer return from accept Figure 4.16: Status of client/server acer fork returns Figure 4.17: Status of client/server acer parent and child close appropriate sockets #include <sys/socket.h> int getsockname(int sd, struct sockaddr *localaddr, socklen_t *addrlen); int getpeername(int sd, struct sockaddr *peeraddr, socklen_t *addrlen); Figure 4.18: Example of inetd spawning a server ...
View Full Document

Ask a homework question - tutors are online