root/usr.sbin/snmpd/engine.c
/*      $OpenBSD: engine.c,v 1.1 2025/12/24 14:59:41 martijn Exp $      */

/*
 * Copyright (c) 2025 Martijn van Duren <martijn@openbsd.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <string.h>

#include "snmpd.h"

int
engineid_cmp(struct engineid *e1, struct engineid *e2)
{
        size_t min;
        int r;

        min = e1->length < e2->length ? e1->length : e2->length;
        if ((r = memcmp(e1->value, e2->value, min)) != 0)
                return r;
        if (e1->length == e2->length)
                return 0;
        return e1->length < e2->length ? -1 : 1;
}