endianness...

This commit is contained in:
Andrew Pamment 2018-05-25 12:44:25 +10:00
parent 4068cd4315
commit 11233fa4d7
4 changed files with 56 additions and 9 deletions

View File

@ -4,6 +4,7 @@
#include <limits.h>
#include <sys/stat.h>
#include <unistd.h>
#include <arpa/inet.h>
#include "libuuid/uuid.h"
#include "jamlib/jam.h"
@ -35,6 +36,14 @@ int mynode = 0;
int hubnode = 0;
int imhub = 0;
void msg_to_nl(struct msg_t *msg) {
msg->area = htonl(msg->area);
msg->timedate = htonl(msg->timedate);
msg->oaddr = htonl(msg->oaddr);
msg->daddr = htonl(msg->daddr);
msg->type = htonl(msg->type);
}
s_JamBase *open_jam_base(char *path) {
int ret;
s_JamBase *jb;
@ -332,6 +341,8 @@ int export_messages(int area) {
continue;
}
msg_to_nl(&msg);
fwrite(&msg, sizeof(struct msg_t), 1, fptr);
fwrite(body, strlen(body), 1, fptr);
fclose(fptr);
@ -361,6 +372,8 @@ int export_messages(int area) {
continue;
}
msg_to_nl(&msg);
fwrite(&msg, sizeof(struct msg_t), 1, fptr);
fwrite(body, strlen(body), 1, fptr);
fclose(fptr);

View File

@ -8,6 +8,7 @@
#include <fcntl.h>
#include <sys/file.h>
#include <time.h>
#include <arpa/inet.h>
#include "jamlib/jam.h"
char *baseindir = NULL;
@ -43,6 +44,14 @@ int area_count;
int mynode = 0;
int hubnode = 0;
void msg_to_hl(struct msg_t *msg) {
msg->area = ntohl(msg->area);
msg->timedate = ntohl(msg->timedate);
msg->oaddr = ntohl(msg->oaddr);
msg->daddr = ntohl(msg->daddr);
msg->type = ntohl(msg->type);
}
unsigned long generate_msgid() {
char buffer[1024];
@ -375,6 +384,8 @@ int import(char *filename) {
fread(&msg, sizeof(struct msg_t), 1, fptr);
msg_to_hl(&msg);
body = malloc(st.st_size - sizeof(struct msg_t) + 1 + strlen(fido_addr));
memset(body, 0, st.st_size - sizeof(struct msg_t) + 1 + strlen(fido_addr));

View File

@ -4,7 +4,7 @@
#include <limits.h>
#include <sys/stat.h>
#include <unistd.h>
#include <arpa/inet.h>
#include "jamlib/jam.h"
char *baseoutdir = NULL;
@ -18,14 +18,14 @@ struct msgarea_t {
};
struct msg_t {
int area;
uint32_t area;
char from[32];
char to[32];
char subject[64];
uint32_t timedate;
int oaddr;
int daddr;
int type;
uint32_t oaddr;
uint32_t daddr;
uint32_t type;
char reply[36];
} __attribute__ ((packed));
@ -35,6 +35,14 @@ int mynode = 0;
int hubnode = 0;
int imhub = 0;
void msg_to_nl(struct msg_t *msg) {
msg->area = htonl(msg->area);
msg->timedate = htonl(msg->timedate);
msg->oaddr = htonl(msg->oaddr);
msg->daddr = htonl(msg->daddr);
msg->type = htonl(msg->type);
}
s_JamBase *open_jam_base(char *path) {
int ret;
s_JamBase *jb;
@ -313,6 +321,8 @@ int export_messages(int area) {
continue;
}
msg_to_nl(&msg);
fwrite(&msg, sizeof(struct msg_t), 1, fptr);
fwrite(body, strlen(body), 1, fptr);
fclose(fptr);
@ -342,6 +352,8 @@ int export_messages(int area) {
continue;
}
msg_to_nl(&msg);
fwrite(&msg, sizeof(struct msg_t), 1, fptr);
fwrite(body, strlen(body), 1, fptr);
fclose(fptr);

View File

@ -5,6 +5,7 @@
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
#include <arpa/inet.h>
#include "jamlib/jam.h"
char *baseindir = NULL;
@ -23,14 +24,14 @@ struct msgarea_t {
};
struct msg_t {
int area;
uint32_t area;
char from[32];
char to[32];
char subject[64];
uint32_t timedate;
int oaddr;
int daddr;
int type;
uint32_t oaddr;
uint32_t daddr;
uint32_t type;
char reply[36];
} __attribute__ ((packed));
@ -39,6 +40,14 @@ int area_count;
int mynode = 0;
int hubnode = 0;
void msg_to_hl(struct msg_t *msg) {
msg->area = ntohl(msg->area);
msg->timedate = ntohl(msg->timedate);
msg->oaddr = ntohl(msg->oaddr);
msg->daddr = ntohl(msg->daddr);
msg->type = ntohl(msg->type);
}
int copy_file(char *src, char *dest) {
FILE *src_file;
FILE *dest_file;
@ -340,6 +349,8 @@ int import(char *filename) {
fread(&msg, sizeof(struct msg_t), 1, fptr);
msg_to_hl(&msg);
body = malloc(st.st_size - sizeof(struct msg_t) + 1);
memset(body, 0, st.st_size - sizeof(struct msg_t) + 1);