#include #include #include #include #include #include #include #include #include int main(int argc, char ** argv){ struct sockaddr_in6 sad; sad.sin6_family = AF_INET6; sad.sin6_flowinfo = 0; sad.sin6_port = htons(5143); sad.sin6_addr = in6addr_any; sad.sin6_scope_id = 0; int skt = socket(AF_INET6, SOCK_STREAM, 0); // Step 1 if(skt == -1){ perror("socket"); return 1; } if( bind(skt, (struct sockaddr*)(&sad), sizeof(struct sockaddr_in6)) ){ // step 2 perror("bind"); return 1; } if( listen(skt, 5) ){ // step 3 perror("listen"); return 1; } while(1){ int client_fd; struct sockaddr_in client_address; socklen_t address_size = sizeof(struct sockaddr_in6); client_fd = accept(skt, (struct sockaddr *)(&client_address), &address_size); // step 4 if(client_fd < 0){ perror("accept"); break; } write(client_fd, "Good Morning ", 13); write(client_fd, "Now it is afternoon", 20); char client_message[100]; read(client_fd, client_message, 100); printf("Client sent: %s\n", client_message); // printf("Connection made from address %s\n", inet_ntoa(client_address.sin6_addr)); close(client_fd); } return 0; }