diff --git a/dh.c b/dh.c index 5b16d40c5999e7fda2e485fdbe34545b5031e7a7..8e0273bc8ebb623c1250b32254fe55fb4f8d8c70 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); }