1
0
mirror of https://github.com/fumiama/simple-dict.git synced 2026-06-12 14:10:50 +08:00
This commit is contained in:
源文雨
2022-03-29 19:58:25 +08:00
parent 8957f732aa
commit d6840358f3
3 changed files with 10 additions and 7 deletions

View File

@@ -48,8 +48,8 @@ void getMessage(void *p) {
while(bufr[i] != '$') i++; while(bufr[i] != '$') i++;
while(bufr[i] != '$') recv(sockfd, bufr+i++, 1, MSG_WAITALL); while(bufr[i] != '$') recv(sockfd, bufr+i++, 1, MSG_WAITALL);
bufr[i] = 0; bufr[i] = 0;
off_t datalen; unsigned int datalen;
sscanf(bufr, "%d", &datalen); sscanf(bufr, "%u", &datalen);
#ifdef DEBUG #ifdef DEBUG
printf("raw data len: %d\n", datalen); printf("raw data len: %d\n", datalen);
#endif #endif
@@ -66,11 +66,12 @@ void getMessage(void *p) {
//FILE* fp = fopen("raw_before_dec", "wb+"); //FILE* fp = fopen("raw_before_dec", "wb+");
//fwrite(data, datalen, 1, fp); //fwrite(data, datalen, 1, fp);
//fclose(fp); //fclose(fp);
char* newdata = raw_decrypt(data, &datalen, 0, pwd); off_t tmp = datalen;
char* newdata = raw_decrypt(data, &tmp, 0, pwd);
if(newdata) { if(newdata) {
printf("raw data len after decode: %d\n", datalen); printf("raw data len after decode: %d\n", (int)tmp);
FILE* fp = fopen(savepath, "wb+"); FILE* fp = fopen(savepath, "wb+");
fwrite(newdata, datalen, 1, fp); fwrite(newdata, (size_t)tmp, 1, fp);
fclose(fp); fclose(fp);
free(newdata); free(newdata);
puts("recv raw data succeed."); puts("recv raw data succeed.");
@@ -186,7 +187,7 @@ int main(int argc,char *argv[]) { //usage: ./client host port
else puts("Send file error."); else puts("Send file error.");
#endif #endif
fclose(fp); fclose(fp);
printf("Send count: %u\n", len); printf("Send count: %d\n", (int)len);
} else puts("Open file error!"); } else puts("Open file error!");
} }
else { else {
@@ -233,7 +234,7 @@ int main(int argc,char *argv[]) { //usage: ./client host port
else { else {
p->cmd = CMDMD5; p->cmd = CMDMD5;
p->datalen = 16; p->datalen = 16;
for(int i = 0; i < 16; i++) sscanf(buf+4+i*2, "%02x", &p->data[i]); for(int i = 0; i < 16; i++) sscanf(buf+4+i*2, "%02x", (unsigned int*)&p->data[i]);
printf("Read md5:"); printf("Read md5:");
for(int i = 0; i < 16; i++) printf("%02x", (uint8_t)(p->data[i])); for(int i = 0; i < 16; i++) printf("%02x", (uint8_t)(p->data[i]));
putchar('\n'); putchar('\n');

View File

@@ -3,6 +3,7 @@
#include <stdint.h> #include <stdint.h>
#include <simplecrypto.h> #include <simplecrypto.h>
#include <types.h>
#include "server.h" #include "server.h"
void init_crypto(); void init_crypto();

View File

@@ -1,6 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <simple_protobuf.h> #include <simple_protobuf.h>
#include <types.h>
#define DICTKEYSZOLD 64 #define DICTKEYSZOLD 64
#define DICTDATSZOLD 64 #define DICTDATSZOLD 64