CS 447 Networks and Data Communication Server-Process Organization IP address and SockAddr_In Data Structure Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki Socekt-2/000
Socekt-2/001 Project Phase 1: Suggested server organization CS447 - Computer and Data Communication socket_id = socket ( ……. ): void main (void) { bind (socket_id, ……. ): listen (socket_id, ……. ): duplicated_socket = accept (socket_id, ……. ): recv (duplicated_socket, ……. ): send (duplicated_socket, ……. ): closesocket (duplicated_socket): int socket_id int duplicated_socket while (TRUE) { Not “socket_id” but “duplicated_socket” } Infinite loop
Socekt-2/002 CS447 - Computer and Data Communication socket_id = socket ( ……. ): void main (void) { bind (socket_id, ……. ): listen (socket_id, ……. ): struct sockaddr_in server_addr; /* Server Internet address */ struct sockaddr_in client_addr; /* Client address */ Project Phase 1: Suggested server organization (continued) We are going to create two “sockaddr_in” data structures duplicated_socket = accept (socket_id, ……. ): “sockaddr_in” structure Hold IP address and port
Socekt-2/003 CS447 - Computer and Data Communication socket_id = socket ( ……. ): void main (void) { bind (socket_id, (struct sockaddr *) &server_addr, ….. ): listen (socket_id, ……. ): struct sockaddr_in server_addr; /* Server Internet address */ struct sockaddr_in client_addr; /* Client address */ Project Phase 1: Suggested server organization (continued) duplicated_socket = accept (socket_id, ……. ):
CS447 - Computer and Data Communication Server Host Computer Network Interface Card (NIC) Network A Network B NIC IP: IP: server_addr.sin_family = AF_INET; /* Address Family To Be Used */ server_addr.sin_port = htons (1050); /* Port number */ server_addr.sin_addr.s_addr = htonl ( ); /* IP address */ Socekt-2/004 Accept request only from network A
CS447 - Computer and Data Communication Server Host Computer Network Interface Card (NIC) Network A Network B NIC IP: IP: server_addr.sin_family = AF_INET; /* Address Family To Be Used */ server_addr.sin_port = htons (1050); /* Port number */ server_addr.sin_addr.s_addr = htonl ( ); /* IP address */ Socekt-2/005 Accept request only from network B
CS447 - Computer and Data Communication Server Host Computer Network Interface Card (NIC) Network A Network B NIC IP: IP: server_addr.sin_family = AF_INET; /* Address Family To Be Used */ server_addr.sin_port = htons (1050); /* Port number */ server_addr.sin_addr.s_addr = htonl (INADDR_ANY); /* IP address */ Socekt-2/006 Accept requests from both networks
Socekt-2/007 CS447 - Computer and Data Communication socket_id = socket ( ……. ): void main (void) { bind (socket_id, ……. ): listen (socket_id, ……. ): struct sockaddr_in server_addr; /* Server Internet address */ struct sockaddr_in client_addr; /* Client address */ Project Phase 1: Suggested server organization (continued) duplicated_socket = accept (socket_id, (struct sockaddr *) &client_addr, …… ): IP address of a client Port# of a client
Socekt-2/008 CS447 - Computer and Data Communication socket_id = socket ( ……. ): void main (void) { bind (socket_id, server_addr, ….. ): listen (socket_id, ……. ): struct sockaddr_in server_addr; /* Server Internet address */ struct sockaddr_in client_addr; /* Client address */ Project Phase 1: Suggested server organization (continued) duplicated_socket = accept (socket_id, client_addr, p_client_add_size); int client_add_size = sizeof(client_addr); int * p_client_add_size = &client_add_size;