Skip to content
Snippets Groups Projects
Commit d4bf2556 authored by ChouTatsumi's avatar ChouTatsumi
Browse files

fix dh.c bug 21:38

parent 53eae3be
Branches
No related tags found
No related merge requests found
......@@ -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);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment