static int SFTP_GetHeader(WOLFSSH* ssh, word32* reqId, byte* type,
        WS_SFTP_BUFFER* buffer)
{
    int    ret;
    word32 len;
    WLOG(WS_LOG_SFTP, "Entering SFTP_GetHeader()");

    if (type == NULL || reqId == NULL || ssh == NULL) {
        WLOG(WS_LOG_SFTP, "NULL argument error");
        return WS_BAD_ARGUMENT;
    }

    ret = wolfSSH_SFTP_buffer_read(ssh, buffer, WOLFSSH_SFTP_HEADER);
    if (ret < 0) {
        return WS_FATAL_ERROR;
    }

    if (ret < WOLFSSH_SFTP_HEADER) {
        WLOG(WS_LOG_SFTP, "Unable to read SFTP header");
        return WS_FATAL_ERROR;
    }

    ato32(buffer->data, &len);
    *type = buffer->data[LENGTH_SZ];
    ato32(buffer->data + UINT32_SZ + MSG_ID_SZ, reqId);

    wolfSSH_SFTP_buffer_free(ssh, buffer);
    WLOG(WS_LOG_SFTP, "Leaving SFTP_GetHeader(), packet length = %d id = %d"
           " type = %d", len - UINT32_SZ - MSG_ID_SZ, *reqId, *type);
    return len - UINT32_SZ - MSG_ID_SZ;
}
static int SFTP_GetHeader(WOLFSSH* ssh, word32* reqId, byte* type,
        WS_SFTP_BUFFER* buffer)
{
    int    ret;
    word32 len;
    WLOG(WS_LOG_SFTP, "Entering SFTP_GetHeader()");

    if (type == NULL || reqId == NULL || ssh == NULL) {
        WLOG(WS_LOG_SFTP, "NULL argument error");
        return WS_BAD_ARGUMENT;
    }

    ret = wolfSSH_SFTP_buffer_read(ssh, buffer, WOLFSSH_SFTP_HEADER);
    if (ret < 0) {
        return WS_FATAL_ERROR;
    }

    if (ret < WOLFSSH_SFTP_HEADER) {
        WLOG(WS_LOG_SFTP, "Unable to read SFTP header");
        return WS_FATAL_ERROR;
    }

    ato32(buffer->data, &len);
    *type = buffer->data[LENGTH_SZ];
    ato32(buffer->data + UINT32_SZ + MSG_ID_SZ, reqId);

    wolfSSH_SFTP_buffer_free(ssh, buffer);
    WLOG(WS_LOG_SFTP, "Leaving SFTP_GetHeader(), packet length = %d id = %d"
           " type = %d", len - UINT32_SZ - MSG_ID_SZ, *reqId, *type);
    return len - UINT32_SZ - MSG_ID_SZ;
}