network

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

commit 654cc7ab13ae1b241f323236fc41a722deaad059
parent e398ccb1a18ae0a01ce8af9b8a7c2e62da328a99
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Fri, 17 Mar 2017 20:56:54 +0100

Fix(Read / Write): Now working properly with callbacks

Diffstat:
Minc/package.h | 3++-
Msrc/client_test.c | 2+-
Msrc/package.c | 17+++++++++++++++++
Msrc/read_package.c | 1+
Msrc/write_package.c | 4+++-
5 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/inc/package.h b/inc/package.h @@ -29,7 +29,7 @@ typedef struct package_s { /* Type field of the header */ typedef enum package_type_e { - PKG_TYPE_AUTH = 1, + PKG_TYPE_AUTH = 0, PKG_TYPE_AUTH_ACK, PKG_TYPE_ERROR, PKG_TYPE_REQ_GET_PKG, @@ -160,5 +160,6 @@ typedef struct resp_cat_s { void *write_package(package_t *pkg, size_t *size); package_t *read_pkg(void *data); void *pkg_build_auth(size_t *size, int major_version, int minor_version); +void *pkg_build_auth_ack(size_t *size, int major_version, int minor_version); #endif /* PACKAGE_H */ diff --git a/src/client_test.c b/src/client_test.c @@ -39,7 +39,7 @@ TEST(pkg_auth_1_read) { size_t r_n = 0, size; TEST_ASSERT(sockfd, "Server is not responding"); - expect = pkg_build_auth(&size, 1, 0); + expect = pkg_build_auth_ack(&size, 1, 0); ret = malloc(2048); r_n = read(sockfd, ret, 2048); diff --git a/src/package.c b/src/package.c @@ -14,3 +14,20 @@ void *pkg_build_auth(size_t *size, int major_version, int minor_version) { list_add(pkg->payload, auth, sizeof(auth_t)); return write_package(pkg, size); } + +void *pkg_build_auth_ack(size_t *size, int major_version, int minor_version) { + auth_t *auth; + package_t *pkg; + void *ret; + + auth = malloc(sizeof(auth_t)); + auth->mpm_major_version = major_version; + auth->mpm_minor_version = minor_version; + pkg = malloc(sizeof(package_t)); + pkg->type = PKG_TYPE_AUTH_ACK; + pkg->payload = NULL; + pkg->number = 1; + list_add(pkg->payload, auth, sizeof(auth_t)); + ret = write_package(pkg, size); + return ret; +} diff --git a/src/read_package.c b/src/read_package.c @@ -4,6 +4,7 @@ static size_t read_header(package_t *pkg, void *data) { size_t count = 0; read_member(pkg->type); + pkg->type--; read_member(pkg->size); read_member(pkg->next_pkg_len); diff --git a/src/write_package.c b/src/write_package.c @@ -2,6 +2,7 @@ static void *write_header(package_t *pkg, size_t *count) { void *header; + u8_t tmp; *count = 0; header = malloc(sizeof(pkg->type) + @@ -11,7 +12,8 @@ static void *write_header(package_t *pkg, size_t *count) { pkg->next_pkg_len); assert(header != NULL); - write_member(pkg->type, header, *count); + tmp = pkg->type + 1; + write_member(tmp, header, *count); write_member(pkg->size, header, *count); write_member(pkg->next_pkg_len, header, *count); if (pkg->next_pkg_len != 0) {