diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/include/initsock.h | 7 | ||||
-rw-r--r-- | lib/init/init_socket_recv_status.c | 22 |
2 files changed, 16 insertions, 13 deletions
diff --git a/lib/include/initsock.h b/lib/include/initsock.h index 04b8ffd..ef8b9e3 100644 --- a/lib/include/initsock.h +++ b/lib/include/initsock.h @@ -40,6 +40,13 @@ typedef struct { } init_request_t; typedef struct { + uint8_t state; + uint8_t exit_status; + uint8_t padd[2]; + int32_t id; +} init_response_status_t; + +typedef struct { E_SERVICE_STATE state; int exit_status; int id; diff --git a/lib/init/init_socket_recv_status.c b/lib/init/init_socket_recv_status.c index d5ca2e6..996f8de 100644 --- a/lib/init/init_socket_recv_status.c +++ b/lib/init/init_socket_recv_status.c @@ -31,18 +31,17 @@ retry: static char *read_string(int fd) { - uint8_t size_raw[2]; + uint16_t len; char *buffer; - size_t len; int ret; - ret = read_retry(fd, size_raw, 2); + ret = read_retry(fd, &len, sizeof(len)); if (ret <= 0) return NULL; - len = (((size_t)size_raw[0]) << 8) | (size_t)size_raw[1]; + len = be16toh(len); - buffer = malloc(len + 1); + buffer = calloc(1, len + 1); if (buffer == NULL) return NULL; @@ -57,24 +56,21 @@ static char *read_string(int fd) } } - buffer[len] = '\0'; return buffer; } int init_socket_recv_status(int fd, init_status_t *resp) { - uint8_t info[8]; + init_response_status_t info; memset(resp, 0, sizeof(*resp)); - if (read_retry(fd, info, sizeof(info)) <= 0) + if (read_retry(fd, &info, sizeof(info)) <= 0) return -1; - resp->state = info[0]; - resp->exit_status = info[1]; - - resp->id = ((int)info[4] << 24) | ((int)info[5] << 16) | - ((int)info[6] << 8) | (int)info[7]; + resp->state = info.state; + resp->exit_status = info.exit_status; + resp->id = be32toh(info.id); if (resp->state == ESS_NONE) return 0; |