bcssocket/challenges.c

47 lines
1.3 KiB
C

#include "include/challenges.h"
// char introChallenge(int fd, char * output, char * message, char * question, char * flag) {
// printf("%s\n", message);
// int readChars;
// while ((readChars = read(fd, output, MAX_LEN - 1)) != 0) {
// if (readChars < 0)
// printSystemError("Challenges: read()");
// output[readChars] = '\0';
// }
// printf("%s\n", question);
// return strcmp(output, flag) == 0;
// }
// char genChallenge(int fd, char * output, char * message, char * question, char * flag) {
// printf("%s\n", message);
// int readChars;
// while ((readChars = read(fd, output, MAX_LEN - 1)) != 0) {
// if (readChars < 0)
// printSystemError("Challenges: read()");
// output[readChars] = '\0';
// }
// printf("%s\n", question);
// return !strcmp(output, flag);
// }
char genChallenge(int fd, char * output, challenge_t challenge) {
printf("%s\n", challenge.message);
int readChars;
// while ((readChars = read(fd, output, MAX_LEN - 1)) != 0) {
readChars = read(fd, output, MAX_LEN - 1);
if (readChars < 0)
printSystemError("Challenges: read()");
output[readChars] = '\0';
// }
printf("%s\n", challenge.question);
return strcmp(output, challenge.flag);
}