Wireshark process TCP transport layer UDP IP ICMP

  • Slides: 41
Download presentation

Wireshark

Wireshark

ネットワークアプリケーションとは? process TCP transport layer UDP IP ICMP process ARP Application layer IGMP network

ネットワークアプリケーションとは? process TCP transport layer UDP IP ICMP process ARP Application layer IGMP network layer RARP hardware interface media data link layer

bindした状態 Proto Local. Address TCP *. A クライアント プロセス Foreign. Address *. * Port

bindした状態 Proto Local. Address TCP *. A クライアント プロセス Foreign. Address *. * Port A State Closed サーバ プロセス Port B Port C ホストA IP Address: xx. xx. ホストB IP Address: xx. xx.

Datagram example (UDP) Server socket() Client bind() socket() recvfrom() Block until Data from client

Datagram example (UDP) Server socket() Client bind() socket() recvfrom() Block until Data from client bind() Data (request) sendto() Process request sendto() Data (reply) recvfrom()

Stream example (TCP) Server socket() bind() Client listen() socket() accept() Block until connect recv()

Stream example (TCP) Server socket() bind() Client listen() socket() accept() Block until connect recv() Process request send() Connection Establishmt. Data (request) connect() send() Data (reply) recv() 暗黙にbind()

エンディアン変換 u_long htonl(u_long hostlong); u_short htons(u_short hostshort); u_long ntohl(u_long netlong); u_short ntohs(u_short netshort);

エンディアン変換 u_long htonl(u_long hostlong); u_short htons(u_short hostshort); u_long ntohl(u_long netlong); u_short ntohs(u_short netshort);

必要な構造体 #include<netinet/in. h> struct sockaddr_in{ u_char sin_len; ズ*/ u_char sin_family; u_short sin_port; struct in_addr

必要な構造体 #include<netinet/in. h> struct sockaddr_in{ u_char sin_len; ズ*/ u_char sin_family; u_short sin_port; struct in_addr sin_addr; char sin_zero[8]; } /*IP addressのサイ /*AF_INET etc*/ /*port num*/ /*IP address*/ /*padding*/

必要な関数 socket bind sendto recvfrom UDP Server UDP client socket() bind() sendto() Data (request)

必要な関数 socket bind sendto recvfrom UDP Server UDP client socket() bind() sendto() Data (request) recvfrom() sendto() recvfrom() Data (reply)

socket int socket(int domain, int type, int protocol); (例) int sd; sd = socket(AF_INET,

socket int socket(int domain, int type, int protocol); (例) int sd; sd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)        AF_UNIX , SOCK_STREAM, IPPROTO_TCP SOCK_RAW, IPPROTO_ICMP

bind int bind(int sockfd, struct sockaddr *addr, int addrlen); (例) struct sockaddr_in cl_addr; memset((void

bind int bind(int sockfd, struct sockaddr *addr, int addrlen); (例) struct sockaddr_in cl_addr; memset((void *)&cl_addr, 0, sizeof(cl_addr)); cl_addr. sin_family = AF_INET; cl_addr. sin_port = htons(0); cl_addr. sin_addr. s_addr = htonl(INADDR_ANY);  /* local host*/ bind(sd, (struct sockaddr *)&cl_addr, sizeof(cl_addr))

サーバのソケットアドレスを準備する struct sockaddr_in sv_addr; memset((void *)&sv_addr, 0, sizeof(sv_addr)); sv_addr. sin_family = AF_INET; sv_addr. sin_port

サーバのソケットアドレスを準備する struct sockaddr_in sv_addr; memset((void *)&sv_addr, 0, sizeof(sv_addr)); sv_addr. sin_family = AF_INET; sv_addr. sin_port = htons(? ? ? ); inet_aton(? ? ? , &sv_addr. sin_addr);

sendto ssize_t sendto(int s, const void *msg, size_t len, int flags, const struct sockaddr

sendto ssize_t sendto(int s, const void *msg, size_t len, int flags, const struct sockaddr *to, int tolen); (例) if (sendto(sd, (char *)&msg, sizeof(msg), 0 , (struct sockaddr *)&sv_addr, sizeof(sv_addr)) < 0) { perror("sendto"); exit(-1); }

recvfrom ssize_t recvfrom (int s, void *buf, size_t len, int flags, struct sockaddr *from,

recvfrom ssize_t recvfrom (int s, void *buf, size_t len, int flags, struct sockaddr *from, int *fromlen); (例) recvlen = recvfrom(sd, (void *)buf, 1024, 0, (struct sockaddr *)&sv_addr, &svadlen);

#include #include <sys/types. h> <sys/socket. h> <netinet/in. h> <netdb. h> <stdio. h> #define BUFMAX

#include #include <sys/types. h> <sys/socket. h> <netinet/in. h> <netdb. h> <stdio. h> #define BUFMAX 1024 int main(int argc, char *argv[]){ int sd; int cc, svadlen; char buf[BUFMAX] char rmsg[BUFMAX]; struct sockaddr_in cl_addr, sv_addr; /* socketの作成 */ ? ? /* socketに名前をつける */ ? ? /* サーバのソケットアドレスの設定 */ ? ? /* 処理ルーチン(メッセージの送信,受信) */ ? ? return 0; }

Homework Create your own TCP “Success!” message server.

Homework Create your own TCP “Success!” message server.