fix endianness

This commit is contained in:
Andrew Pamment 2018-05-25 13:00:27 +10:00
parent 11233fa4d7
commit 8864ce3773

View File

@ -26,14 +26,14 @@ struct msgarea_t {
}; };
struct msg_t { struct msg_t {
int area; uint32_t area;
char from[32]; char from[32];
char to[32]; char to[32];
char subject[64]; char subject[64];
uint32_t timedate; uint32_t timedate;
int oaddr; uint32_t oaddr;
int daddr; uint32_t daddr;
int type; uint32_t type;
char reply[36]; char reply[36];
} __attribute__ ((packed)); } __attribute__ ((packed));
@ -42,6 +42,14 @@ int area_count;
int mynode = 0; int mynode = 0;
int hubnode = 0; int hubnode = 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);
}
int copy_file(char *src, char *dest) { int copy_file(char *src, char *dest) {
FILE *src_file; FILE *src_file;
FILE *dest_file; FILE *dest_file;
@ -297,6 +305,8 @@ int main(int argc, char **argv) {
return -1; return -1;
} }
msg_to_nl(&msg);
fwrite(&msg, sizeof(struct msg_t), 1, fptr); fwrite(&msg, sizeof(struct msg_t), 1, fptr);
fwrite("ADD\r", 4, 1, fptr); fwrite("ADD\r", 4, 1, fptr);
fclose(fptr); fclose(fptr);
@ -344,6 +354,8 @@ int main(int argc, char **argv) {
return -1; return -1;
} }
msg_to_nl(&msg);
fwrite(&msg, sizeof(struct msg_t), 1, fptr); fwrite(&msg, sizeof(struct msg_t), 1, fptr);
fwrite("REMOVE\r", 7, 1, fptr); fwrite("REMOVE\r", 7, 1, fptr);
fclose(fptr); fclose(fptr);