Question: C Code, Physical Layer: Create socket, bind its address, and listen to it? Overall: Need to create and send a message through a network layer,
C Code, Physical Layer: Create socket, bind its address, and listen to it?
Overall: Need to create and send a message through a network layer, data link layer and physical layer.
Using an older project as an example to base this code on, Otherwise what should it be like?
Code so far:

58 59 60 61 62 63 64 65 add codes to declear Local variables int sockfd, newsockfd, portno, nj socklen_t clilen; //struct sockaddr_in serv addr; //struct hostent server /packet incoming packet, outgoing packet; char buffer[256]; struct sockaddr in serv addr, cli addr pthread t threadlist[2]; int n; add codes to create a socket (sockfd), bind its address to it and listen to it/ sockfd = socket (AF_INET, SOCK-STREAM, e); 75 bzero((char *) &serv_addr, sizeof (serv_addr)) portno = atoi(argv [1]); serv-addr. Sin-family = AF_INET; serv-addr. sin-addr. S-addr = INADDR ANY; serv-addr.sin_port = htons(portno); 79 80 81 82 83 84 85 86 if (bind(sockfd, (struct sockaddr ) &serv_addr, sizeof (serv-addr))8) error("ERROR on binding"); listen(sockfd,5); 89 90 91 92 93 94 95 96 for (int i-e;i42;i=i+1) /*only accept two requests*/ accept a request from the data Link Layer newsockfd accept (sockfd, (struct sockaddr ) &cli_addr, &clilen); store the new socket into clientlist clientlist[i]-newsockfd; 98 100 101 102 103 104 105 106 107 108 creat a thread to take care of the new connection pthread t pthj this is the thread identifier pthread_create(&pth, NULL,onesocket,clientlist[i])5 threadlist[i]-pth; save the thread identifier into an array close(sockfd) so that wire will not accept further connection request pthread join(threadlist[e], NULL)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
