diff options
Diffstat (limited to 'src/irmd/ipcp.c')
-rw-r--r-- | src/irmd/ipcp.c | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/src/irmd/ipcp.c b/src/irmd/ipcp.c index f3f97811..e1689b91 100644 --- a/src/irmd/ipcp.c +++ b/src/irmd/ipcp.c @@ -20,9 +20,12 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ +#define _POSIX_C_SOURCE 199309L + +#include "config.h" + #define OUROBOROS_PREFIX "irmd/ipcp" -#include <ouroboros/config.h> #include <ouroboros/logs.h> #include <ouroboros/errno.h> #include <ouroboros/utils.h> @@ -49,9 +52,9 @@ ipcp_msg_t * send_recv_ipcp_msg(pid_t api, ipcp_msg_t * msg) { int sockfd = 0; - buffer_t buf; + uint8_t buf[IPCP_MSG_BUF_SIZE]; char * sock_path = NULL; - ssize_t count = 0; + ssize_t len; ipcp_msg_t * recv_msg = NULL; struct timeval tv; @@ -70,14 +73,8 @@ ipcp_msg_t * send_recv_ipcp_msg(pid_t api, free(sock_path); - buf.len = ipcp_msg__get_packed_size(msg); - if (buf.len == 0) { - close(sockfd); - return NULL; - } - - buf.data = malloc(IPCP_MSG_BUF_SIZE); - if (buf.data == NULL) { + len = ipcp_msg__get_packed_size(msg); + if (len == 0) { close(sockfd); return NULL; } @@ -110,18 +107,16 @@ ipcp_msg_t * send_recv_ipcp_msg(pid_t api, log_warn("Failed to set timeout on socket."); pthread_cleanup_push(close_ptr, (void *) &sockfd); - pthread_cleanup_push((void (*)(void *)) free, (void *) buf.data); - ipcp_msg__pack(msg, buf.data); + ipcp_msg__pack(msg, buf); - if (write(sockfd, buf.data, buf.len) != -1) - count = read(sockfd, buf.data, IPCP_MSG_BUF_SIZE); + if (write(sockfd, buf, len) != -1) + len = read(sockfd, buf, IPCP_MSG_BUF_SIZE); - if (count > 0) - recv_msg = ipcp_msg__unpack(NULL, count, buf.data); + if (len > 0) + recv_msg = ipcp_msg__unpack(NULL, len, buf); pthread_cleanup_pop(true); - pthread_cleanup_pop(true); return recv_msg; } |