Example: confidence

TCP通信の基礎 - sbcr.jp

1. Chapter 2. 2. 3. TCP 4. Chapter 2 TCP .. 5. TCP . TCP .. Web . 6. 7. 25 1:23:52 PM. Chapter2 TCP 2-1 TCP .. 2-1 TCP .. 1. 2-2 . TCP 2 .. 2.. socket socket .. 3.. socket TCP . API. Application Programming 4. Interface API POSIX . 2-1 . socket . Linux . 5. 2-1 Linux socket . 32 .. socket . List 2-1 socket 6. #include < >. sockfd = socket(. int socket_family, / /. int socket_type, / /. int protocol / /. API ); 7. 2 .. 3 . 2-1 . 26 27. 26-27 1:23:53 PM. Chapter2 TCP 2-1 TCP . socket 3 .. socket_family SOCK_STREAM.

Chapter2 TCP通信の基礎 28 29 2-1 TCPによるプログラミングの流れ 1 2 3 4 5 6 7 の組み合わせにより決定します。socket()システムコールも、それにあわせて3つの引数を取

Tags:

  Sbcr

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of TCP通信の基礎 - sbcr.jp

1 1. Chapter 2. 2. 3. TCP 4. Chapter 2 TCP .. 5. TCP . TCP .. Web . 6. 7. 25 1:23:52 PM. Chapter2 TCP 2-1 TCP .. 2-1 TCP .. 1. 2-2 . TCP 2 .. 2.. socket socket .. 3.. socket TCP . API. Application Programming 4. Interface API POSIX . 2-1 . socket . Linux . 5. 2-1 Linux socket . 32 .. socket . List 2-1 socket 6. #include < >. sockfd = socket(. int socket_family, / /. int socket_type, / /. int protocol / /. API ); 7. 2 .. 3 . 2-1 . 26 27. 26-27 1:23:53 PM. Chapter2 TCP 2-1 TCP . socket 3 .. socket_family SOCK_STREAM.

2 1. 2-1 . IPv4 AF_INET IPv6 AF_INET6 SOCK_DGRAM .. 2-1 2. AF_INET SOCK_STREAM TCP . AF_INET IPv4 . AF_INET6 IPv6 . AF_UNIX AF_LOCAL SOCK_DGRAM . AF_PACKET .. 3. SOCK_STREAM SOCK_. 2 socket_type DGRAM 2-3 . Linux . 2-3 2 . 2-2 man 2 socket .. SOCK_STREAM 4. SOCK_DGRAM . SOCK_STREAM byte stream . out-of-band . SOCK_DGRAM . SOCK_SEQPACKET . socket 3 protocol .. 3 5. SOCK_RAW . SOCK_RDM . 0 . SOCK_PACKET IP /etc/protocols . $sudo cat ./etc/protocols . AF_INET SOCK_STREAM IPv4 TCP AF_INET # Internet (IP) protocols 6.

3 #. SOCK_DGRAM IPv4 UDP IPv6 AF_ # Updated from and other INET6+SOCK_STREAM IPv6 TCP AF_INET6 SOCK_DGRAM IPv6 UDP # sources. # New protocols will be added on request if they have been officially . # assigned by IANA and are not historical. AF_UNIX SOCK_STREAM AF_UNIX SOCK_DGRAM AF_INET SOCK_RAW RAW # If you need a huge list of used numbers please install the nmap package. AF_UNIX Chapter 6 SOCK_RAW Chapter 12 . SOCK_STREAM . ip 0 IP # internet protocol, pseudo protocol number 7. #hopopt 0 HOPOPT # IPv6 Hop-by-Hop Option [RFC1883].

4 SOCK_DGRAM 2 icmp 1 ICMP # internet control message protocol igmp 2 IGMP # Internet Group Management SOCK_STREAM . 28 29. 28-29 1:23:55 PM. Chapter2 TCP 2-1 TCP . int . ggp 3 GGP # gateway-gateway protocol ipencap 4 IP-ENCAP # IP encapsulated in IP (officially ``IP'') . st 5 ST # ST datagram mode socket -1 . tcp 6 TCP # transmission control protocol 1. egp 8 EGP # exterior gateway protocol errno Chapter 2-3 . igp 9 IGP # any private interior gateway(Cisco) 0 . pup 12 PUP # PARC universal packet protocol udp 17 UDP # user datagram protocol 0 open.

5 Hmp 20 HMP # host monitoring protocol socket socket 0 . xns-idp 22 XNS-IDP # Xerox NS IDP.. rdp 27 RDP # "reliable datagram" protocol 2.. List 2-3 .. if ((soc = socket(AF_INET, SOCK_DGRAM, 0)) <= 0) {. perror("socket");. return -1;. }. 3. socket . AF_INET IPv4 SOCK_STREAM .. <= 0 < 0 . AF_INET+SOCK_STREAM IPv4 TCP . socket 0 . 2-2 . stdin 0 socket . List 2-2 IPv4 TCP .. 4. #include < > List 2-4 0 . #include < >. #include < > #include < >. #include < >. int #include < >. main(). { int 5. int sock; main().}

6 {. sock = socket(AF_INET, SOCK_STREAM, 0); int sock;. if (sock < 0) {. printf("socket failed\n"); printf("fileno(stdin) = %d\n", fileno(stdin));. return 1; close(0);. }. / sock will be zero, and it is not an error! / 6. return 0; sock = socket(AF_INET, SOCK_DGRAM, 0);. } printf("sock=%d\n", sock);. return 0;. socket }.. Linux open POSIX . 7.. 2-2 . 30 31. 30-31 1:23:55 PM. Chapter2 TCP 2-2 TCP / . 2-4 POSIX TCP .. 0 stdin bind .. 1 stdout . 1. listen accept 3 . 2 stderr . 2-3 TCP . 2-4 0 . stdin close.

7 2-4 fileno stdin . socket socket . printf fileno stdin 2.. 0 close 0 close .. close 0 socket 0 . IP IP .. 0 socket . 3. 0 bind .. COLUMN listen .. 4. OS API. Application Programming Interface accept connect .. read write . open read write . malloc .. 5. getaddrinfo write read . man 2 3 . close close .. 6. bind . 2-2 TCP / . listen . connect . TCP accept 7. Chap . ter 2 TCP TCP accept . 32 33. 32-33 1:23:57 PM. Chapter2 TCP 2-2 TCP / . TCP . TCP . TCP . TCP . 1.. IP . IP . IP . bind . TCP .. TCP .. 2.

8 TCP . TCP .. TCP .. 2-4 TCP .. / close 3.. Linux TCP List 2-5 TCP . port 11111.. List 2-5 TCP 4. #include < >. #include < >. #include < >. port 80 #include < >. #include < >. port 80. port 32879 int 5. port 80. main(). port 41901 {. int sock0;. struct sockaddr_in addr;. struct sockaddr_in client;. int len;. int sock; 6. / /. TCP sock0 = socket(AF_INET, SOCK_STREAM, 0);. / /. = AF_INET;. TCP TCP = htons(12345);. HELLO = INADDR_ANY; 7. bind(sock0, (struct sockaddr )&addr, sizeof(addr)); 1. / TCP /. 34 35.}

9 34-35 1:23:59 PM. Chapter2 TCP 2-2 TCP / . List 2-6 TCP . listen(sock0, 5);. #include < >. / TCP / #include < >. len = sizeof(client); #include < > 1. sock = accept(sock0, (struct sockaddr )&client, 2 #include < >. #include < >. / 5 /. write(sock, "HELLO", 5); 3 int main(). / TCP / {. close(sock); struct sockaddr_in server; 2. int sock;. / listen socket / char buf[32];. close(sock0); int n;. return 0; / /. } sock = socket(AF_INET, SOCK_STREAM, 0);. / / 3. IP bind . 1 = AF_INET;. = htons(12345);. 2 3.)

10 / localhost /. TCP TCP inet_pton(AF_INET, " ", & );. close .. / /. connect(sock, (struct sockaddr )&server, sizeof(server));. 4. / /. TCP memset(buf, 0, sizeof(buf));. n = read(sock, buf, sizeof(buf));. printf("%d, %s\n", n, buf);. TCP TCP . / socket / 5. close(sock);. return 0;. }.. 6. TCP . TCP . HELLO . IP TCP TCP localhost .. IP 7. 2-3 . TCP List 2-6 TCP . 2-3 IP ifconfig -a . 36 37. 36-37 1:23:59 PM. Chapter2 TCP 2-3 .. TCP close close 2-3 . read EOF End Of File 1. 0 . read 0 TCP close .. close.


Related search queries