network

low level network subjects
Log | Files | Refs | Submodules | README | git clone https://git.ne02ptzero.me/git/network

commit dbe6c6cfc0a8497145cfab4f6e193612f75dd17a
parent 4e0738b5233f6651d964def1b1665a9265ef92ad
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Mon, 27 Mar 2017 16:45:30 +0200

Fix(Package): Fix endianess and multiple things

Diffstat:
Minc/package.h | 6+++---
Msrc/client_test.c | 5++---
Msrc/write_package.c | 19++++++++++++++++++-
3 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/inc/package.h b/inc/package.h @@ -27,10 +27,10 @@ typedef struct intern_package_s { char *category; char *description; char *archive; - u16_t sbu; + float sbu; char *dependencies; - u16_t arch_size; - u16_t inst_size; + float arch_size; + float inst_size; char *arch_hash; u64_t *dependencies_arr; u16_t dependencies_arr_size; diff --git a/src/client_test.c b/src/client_test.c @@ -188,7 +188,6 @@ TEST(pkg_req_get_pkg_2_write) { return TEST_SUCCESS; } - TEST(pkg_req_get_pkg_2_read) { mlist_t *pkgs = NULL; intern_package_t *pkg; @@ -236,7 +235,7 @@ TEST(pkg_req_get_pkg_test_all) { pkg->archive, pkg->arch_hash, pkg->dependencies_arr_size, pkg->dependencies_arr); TEST_ASSERT_FMT(memcmp(ptr, ret, size) == 0, - "Expected package is wrong %s", print_package(ptr, ret, size, r_n)); + "Expected package is wrong (ID: %llu): %s", pkg->id, print_package(ptr, ret, size, r_n)); free(ret); free(ptr); } @@ -268,7 +267,7 @@ void begin_client_test(void) { reg_test("get_pkg", pkg_req_get_pkg_1_read); reg_test("get_pkg", pkg_req_get_pkg_2_write); reg_test("get_pkg", pkg_req_get_pkg_2_read); - /*reg_test("get_pkg", pkg_req_get_pkg_test_all);*/ + reg_test("get_pkg", pkg_req_get_pkg_test_all); reg_test("clean", cleanup_co); reg_test("clean", cleanup_db); test_all(); diff --git a/src/write_package.c b/src/write_package.c @@ -1,5 +1,19 @@ #include "package.h" +static float reverse_float(const float in_float) { + float ret_val; + char *floatToConvert = (char *)&in_float; + char *returnFloat = (char *)&ret_val; + + returnFloat[0] = floatToConvert[3]; + returnFloat[1] = floatToConvert[2]; + returnFloat[2] = floatToConvert[1]; + returnFloat[3] = floatToConvert[0]; + + return ret_val; +} + + static void *write_header(prot_package_t *pkg, size_t *count) { void *header; @@ -165,6 +179,9 @@ static void *write_payload_resp_pkg(void *pkg, size_t *count) { sizeof(resp->dependencies_size) * sizeof(*resp->dependencies) + 100 ); assert(ret != NULL); + resp->comp_time = reverse_float(resp->comp_time); + resp->inst_size = reverse_float(resp->inst_size); + resp->arch_size = reverse_float(resp->arch_size); write_member(resp->id, ret, *count); write_member(resp->comp_time, ret, *count); write_member(resp->inst_size, ret, *count); @@ -185,7 +202,7 @@ static void *write_payload_resp_pkg(void *pkg, size_t *count) { for (u16_t i = 0; i < resp->dependencies_size; i++) { memcpy(ret + *count, &resp->dependencies[i], sizeof(resp->dependencies[i])); - *count += sizeof(resp->dependencies[i]); + *count += sizeof(u64_t); } return ret;