So, I am writing a client and server with a login system with the transfered data hashed with sha1.
So I have a few questions. One, I am working on the name checking function. It checks if the name already exists in the database. I have it working with the first name only and wanted to know if I can traverse the names without a singly linked list? Would using a singly linked list be more efficient?
Here is what I have for the name checking function. The file being opened for reading only makes no difference because it will eventually be integrated with the main code.
Code:
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]) {
FILE *file = fopen("dbase.txt", "rb");
if(file == NULL) {
printf("FOPEN(NULL) error --> %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
char name[35], *chpoint;
printf("Please enter a name to check: ");
fgets(name, sizeof(name), stdin);
printf("Name -> %s", name);
chpoint = strchr(name, '\n');
if (chpoint != NULL) {
*chpoint = '\0';
}
int size = sizeof(name);
int n = strlen(name);
char temp[size];
fseek(file, 0, SEEK_END);
int fsize = ftell(file);
rewind(file);
//printf("The size of your file is %d characters.\n", fsize);
int bytes_read = fread(temp, fsize, 1, file);
if(bytes_read < 0) {
printf("FREAD(-1) error --> %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
printf("Temp -> \n%s", temp);
int mcmp = memcmp(temp, name, n);
if(mcmp == 0) {
printf("! Name already exists\n");
exit(EXIT_FAILURE);
}
else {
printf("Name does not exist.\n");
exit(EXIT_SUCCESS);
}
return 0;
}
Question number two; Can I use a newline char as a condition for a loop while working with binary? For example:
Code:
while(ch != '\n') {
move memory a into memory b.
}
What I do not know is weather the newline char remains an ascii char while working with binary files.
Question 3; In order to get the data that is sent and received from client to server(Yes it is synchronous comm and not asynch... yet) hashed, I am going to use Openssl and it's sha1 function. I have downloaded Openssl from the official site and installed it that way as well as the apt-get method.
I am compiling with:
Code:
gcc -Wall -lcrypto test02.c -o test02
But my compiler cannot find crypto
if i compile with;
Code:
gcc -Wall -L/usr/include/crypto.h test02.c -o test02
I get an undefined reference to SHA1 in main
I have configured openssl's install like so
Code:
./config --prefix=/usr/include/openssl --openssldir=/usr/include/openssl
What could be wrong?