WIP: Comply with GNU Coding Standards

This commit is contained in:
Thomas Wade 2018-10-31 22:23:57 +10:30
parent 59c594c5c3
commit 0e9076d239

View File

@ -1,8 +1,7 @@
/* // server1 - server program for demonstrating data transfer over TCP/IP
* ENGR2782 - CN Assignment
* Your challenge is to format the following code in a readable manner, anwsering the questions in the comments. // This program complies with the GNU Coding Standards found here:
* // https://www.gnu.org/prep/standards/html_node/index.html
*/
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -16,11 +15,15 @@
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <strings.h> #include <strings.h>
#define BUFFERT 512 #define BUFFERT 512
#define BACKLOG 1 #define BACKLOG 1
int create_server_socket (int port); int create_server_socket (int port);
struct sockaddr_in sock_serv,sock_clt; struct sockaddr_in sock_serv,sock_clt;
int main(int argc, char** argv){
int main(int argc, char** argv)
{
int sfd, fd; int sfd, fd;
unsigned int length = sizeof(struct sockaddr_in); unsigned int length = sizeof(struct sockaddr_in);
long int n, m, count = 0; long int n, m, count = 0;
@ -59,7 +62,7 @@ int main(int argc, char** argv){
/* Set the IP address to allow connections on any network interface on the server */ /* Set the IP address to allow connections on any network interface on the server */
sock_serv.sin_addr.s_addr = htonl(/* Q) What goes here? */); sock_serv.sin_addr.s_addr = htonl(/* Q) What goes here? */);
/* See; man 4 ip */ /* See; man 4 ip */
if (bind(sfd,(struct sockaddr*)&sock_serv,l) == -1) {perror("bind fail"); exit(EXIT_FAILURE);} if (bind(sfd,(struct sockaddr*)&sock_serv,l) == -1) {perror("bind fail"); exit(EXIT_FAILURE);}
bzero(buffer,BUFFERT); bzero(buffer,BUFFERT);
listen(sfd,BACKLOG); listen(sfd,BACKLOG);
@ -71,7 +74,7 @@ int main(int argc, char** argv){
/* See; man 2 accept */ /* See; man 2 accept */
if (nsid == -1) {perror("accept fail"); return EXIT_FAILURE;} if (nsid == -1) {perror("accept fail"); return EXIT_FAILURE;}
else { else {
if(inet_ntop(AF_INET,&sock_clt.sin_addr,dst,INET_ADDRSTRLEN)==NULL) {perror("erreur socket");exit (4);} if(inet_ntop(AF_INET,&sock_clt.sin_addr,dst,INET_ADDRSTRLEN)==NULL) {perror("erreur socket");exit (4);}
clt_port=ntohs(sock_clt.sin_port); clt_port=ntohs(sock_clt.sin_port);
@ -99,6 +102,6 @@ int main(int argc, char** argv){
printf("End of transmission with %s.%d\n",dst,clt_port); printf("End of transmission with %s.%d\n",dst,clt_port);
/* Select the appropriate variable in the following function call argument */ /* Select the appropriate variable in the following function call argument */
printf("Number of octets received : %ld \n", /* Q) What goes here? */); printf("Number of octets received : %ld \n", /* Q) What goes here? */);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }