From d4bf2556aaf48829c8997e89ba95e1942bd12637 Mon Sep 17 00:00:00 2001 From: ChouTatsumi <choutatsumi@gmail.com> Date: Fri, 24 May 2019 21:38:16 +1000 Subject: [PATCH] fix dh.c bug 21:38 --- dh.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/dh.c b/dh.c index 5b16d40..8e0273b 100644 --- a/dh.c +++ b/dh.c @@ -3,9 +3,8 @@ #include <stdlib.h> #include <string.h> #include <netdb.h> -// #include <netinet/in.h> -#include <strings.h> -// #include <sys/socket.h> +#include <netinet/in.h> +#include <sys/socket.h> #include <sys/types.h> #include <unistd.h> @@ -28,7 +27,8 @@ int calculate(int base, int pow, int modulus); int main(int argc, char** argv) { // used to save message char buffer[BUFFERSIZE]; - + // used to save status + int status; int b_Value; // get b value @@ -87,9 +87,9 @@ int main(int argc, char** argv) { strcpy(buffer, USERNAME); buffer[strlen(buffer)] = MESSAGE_ENDING; - n = write(sockfd, buffer, strlen(buffer)); + status = write(sockfd, buffer, strlen(buffer)); - if (n < 0) { + if (status < 0) { perror("ERROR writing to socket"); exit(0); } @@ -101,9 +101,9 @@ int main(int argc, char** argv) { sprintf(buffer, "%d", B); buffer[strlen(buffer)] = MESSAGE_ENDING; - n = write(sockfd, buffer, strlen(buffer)); + status = write(sockfd, buffer, strlen(buffer)); - if (n < 0) { + if (status < 0) { perror("ERROR writing to socket"); exit(0); } @@ -111,9 +111,9 @@ int main(int argc, char** argv) { // receive g^a (mod p) memset(buffer, '\0', BUFFERSIZE); - n = read(sockfd, buffer, BUFFERSIZE - 1); + status = read(sockfd, buffer, BUFFERSIZE - 1); - if (n < 0) { + if (status < 0) { perror("ERROR reading from socket"); exit(0); } @@ -127,9 +127,9 @@ int main(int argc, char** argv) { sprintf(buffer, "%d", keyB); buffer[strlen(buffer)] = MESSAGE_ENDING; - n = write(sockfd, buffer, strlen(buffer)); + status = write(sockfd, buffer, strlen(buffer)); - if (n < 0) { + if (status < 0) { perror("ERROR writing to socket"); exit(0); } @@ -137,9 +137,9 @@ int main(int argc, char** argv) { // receive status report memset(buffer, '\0', BUFFERSIZE); - n = read(sockfd, buffer, BUFFERSIZE - 1); + status = read(sockfd, buffer, BUFFERSIZE - 1); - if (n < 0) { + if (status < 0) { perror("ERROR reading from socket"); exit(0); } -- GitLab