/*							-- DO NOT EDIT --
 * This file has been generated by smidump
 * version 0.3.1 for the scli package.
 *
 * Derived from IP-FORWARD-MIB:
 *   The MIB module for the display of CIDR multipath IP Routes.
 *
 * Revision 1996-09-19 00:00:
 *   Revisions made by the OSPF WG.
 *
 * $Id: ip-forward-mib.c,v 1.16 2002/03/27 13:48:21 schoenw Exp $
 */

#include "ip-forward-mib.h"

GSnmpEnum const ip_forward_mib_enums_ipForwardType[] = {
    { IP_FORWARD_MIB_IPFORWARDTYPE_OTHER,   "other" },
    { IP_FORWARD_MIB_IPFORWARDTYPE_INVALID, "invalid" },
    { IP_FORWARD_MIB_IPFORWARDTYPE_LOCAL,   "local" },
    { IP_FORWARD_MIB_IPFORWARDTYPE_REMOTE,  "remote" },
    { 0, NULL }
};

GSnmpEnum const ip_forward_mib_enums_ipForwardProto[] = {
    { IP_FORWARD_MIB_IPFORWARDPROTO_OTHER,     "other" },
    { IP_FORWARD_MIB_IPFORWARDPROTO_LOCAL,     "local" },
    { IP_FORWARD_MIB_IPFORWARDPROTO_NETMGMT,   "netmgmt" },
    { IP_FORWARD_MIB_IPFORWARDPROTO_ICMP,      "icmp" },
    { IP_FORWARD_MIB_IPFORWARDPROTO_EGP,       "egp" },
    { IP_FORWARD_MIB_IPFORWARDPROTO_GGP,       "ggp" },
    { IP_FORWARD_MIB_IPFORWARDPROTO_HELLO,     "hello" },
    { IP_FORWARD_MIB_IPFORWARDPROTO_RIP,       "rip" },
    { IP_FORWARD_MIB_IPFORWARDPROTO_IS_IS,     "is-is" },
    { IP_FORWARD_MIB_IPFORWARDPROTO_ES_IS,     "es-is" },
    { IP_FORWARD_MIB_IPFORWARDPROTO_CISCOIGRP, "ciscoIgrp" },
    { IP_FORWARD_MIB_IPFORWARDPROTO_BBNSPFIGP, "bbnSpfIgp" },
    { IP_FORWARD_MIB_IPFORWARDPROTO_OSPF,      "ospf" },
    { IP_FORWARD_MIB_IPFORWARDPROTO_BGP,       "bgp" },
    { IP_FORWARD_MIB_IPFORWARDPROTO_IDPR,      "idpr" },
    { 0, NULL }
};

GSnmpEnum const ip_forward_mib_enums_ipCidrRouteType[] = {
    { IP_FORWARD_MIB_IPCIDRROUTETYPE_OTHER,  "other" },
    { IP_FORWARD_MIB_IPCIDRROUTETYPE_REJECT, "reject" },
    { IP_FORWARD_MIB_IPCIDRROUTETYPE_LOCAL,  "local" },
    { IP_FORWARD_MIB_IPCIDRROUTETYPE_REMOTE, "remote" },
    { 0, NULL }
};

GSnmpEnum const ip_forward_mib_enums_ipCidrRouteProto[] = {
    { IP_FORWARD_MIB_IPCIDRROUTEPROTO_OTHER,      "other" },
    { IP_FORWARD_MIB_IPCIDRROUTEPROTO_LOCAL,      "local" },
    { IP_FORWARD_MIB_IPCIDRROUTEPROTO_NETMGMT,    "netmgmt" },
    { IP_FORWARD_MIB_IPCIDRROUTEPROTO_ICMP,       "icmp" },
    { IP_FORWARD_MIB_IPCIDRROUTEPROTO_EGP,        "egp" },
    { IP_FORWARD_MIB_IPCIDRROUTEPROTO_GGP,        "ggp" },
    { IP_FORWARD_MIB_IPCIDRROUTEPROTO_HELLO,      "hello" },
    { IP_FORWARD_MIB_IPCIDRROUTEPROTO_RIP,        "rip" },
    { IP_FORWARD_MIB_IPCIDRROUTEPROTO_ISIS,       "isIs" },
    { IP_FORWARD_MIB_IPCIDRROUTEPROTO_ESIS,       "esIs" },
    { IP_FORWARD_MIB_IPCIDRROUTEPROTO_CISCOIGRP,  "ciscoIgrp" },
    { IP_FORWARD_MIB_IPCIDRROUTEPROTO_BBNSPFIGP,  "bbnSpfIgp" },
    { IP_FORWARD_MIB_IPCIDRROUTEPROTO_OSPF,       "ospf" },
    { IP_FORWARD_MIB_IPCIDRROUTEPROTO_BGP,        "bgp" },
    { IP_FORWARD_MIB_IPCIDRROUTEPROTO_IDPR,       "idpr" },
    { IP_FORWARD_MIB_IPCIDRROUTEPROTO_CISCOEIGRP, "ciscoEigrp" },
    { 0, NULL }
};

GSnmpEnum const ip_forward_mib_enums_ipCidrRouteStatus[] = {
    { IP_FORWARD_MIB_IPCIDRROUTESTATUS_ACTIVE,        "active" },
    { IP_FORWARD_MIB_IPCIDRROUTESTATUS_NOTINSERVICE,  "notInService" },
    { IP_FORWARD_MIB_IPCIDRROUTESTATUS_NOTREADY,      "notReady" },
    { IP_FORWARD_MIB_IPCIDRROUTESTATUS_CREATEANDGO,   "createAndGo" },
    { IP_FORWARD_MIB_IPCIDRROUTESTATUS_CREATEANDWAIT, "createAndWait" },
    { IP_FORWARD_MIB_IPCIDRROUTESTATUS_DESTROY,       "destroy" },
    { 0, NULL }
};


static guint16 ipForwardMask_constraints[] = {4, 4, 0, 0};


static guint32 const ipForward_oid[] = {1, 3, 6, 1, 2, 1, 4, 24};

static GSnmpAttribute ipForward_attr[] = {
    { 1, G_SNMP_UNSIGNED32,
      IP_FORWARD_MIB_IPFORWARDNUMBER, "ipForwardNumber",
       NULL,
      G_STRUCT_OFFSET(ip_forward_mib_ipForward_t, ipForwardNumber),
      0,
      0 },
    { 3, G_SNMP_UNSIGNED32,
      IP_FORWARD_MIB_IPCIDRROUTENUMBER, "ipCidrRouteNumber",
       NULL,
      G_STRUCT_OFFSET(ip_forward_mib_ipForward_t, ipCidrRouteNumber),
      0,
      0 },
    { 0, 0, 0, NULL }
};

static guint32 const ipForwardEntry_oid[] = {1, 3, 6, 1, 2, 1, 4, 24, 2, 1};

static GSnmpAttribute ipForwardEntry_attr[] = {
    { 2, G_SNMP_IPADDRESS,
      IP_FORWARD_MIB_IPFORWARDMASK, "ipForwardMask",
       ipForwardMask_constraints,
      G_STRUCT_OFFSET(ip_forward_mib_ipForwardEntry_t, ipForwardMask),
      0,
      GSNMP_ATTR_FLAG_WRITABLE },
    { 5, G_SNMP_INTEGER32,
      IP_FORWARD_MIB_IPFORWARDIFINDEX, "ipForwardIfIndex",
       NULL,
      G_STRUCT_OFFSET(ip_forward_mib_ipForwardEntry_t, ipForwardIfIndex),
      0,
      GSNMP_ATTR_FLAG_WRITABLE },
    { 6, G_SNMP_INTEGER32,
      IP_FORWARD_MIB_IPFORWARDTYPE, "ipForwardType",
       NULL,
      G_STRUCT_OFFSET(ip_forward_mib_ipForwardEntry_t, ipForwardType),
      0,
      GSNMP_ATTR_FLAG_WRITABLE },
    { 8, G_SNMP_INTEGER32,
      IP_FORWARD_MIB_IPFORWARDAGE, "ipForwardAge",
       NULL,
      G_STRUCT_OFFSET(ip_forward_mib_ipForwardEntry_t, ipForwardAge),
      0,
      0 },
    { 9, G_SNMP_OBJECTID,
      IP_FORWARD_MIB_IPFORWARDINFO, "ipForwardInfo",
       NULL,
      G_STRUCT_OFFSET(ip_forward_mib_ipForwardEntry_t, ipForwardInfo),
      G_STRUCT_OFFSET(ip_forward_mib_ipForwardEntry_t, _ipForwardInfoLength),
      GSNMP_ATTR_FLAG_WRITABLE },
    { 10, G_SNMP_INTEGER32,
      IP_FORWARD_MIB_IPFORWARDNEXTHOPAS, "ipForwardNextHopAS",
       NULL,
      G_STRUCT_OFFSET(ip_forward_mib_ipForwardEntry_t, ipForwardNextHopAS),
      0,
      GSNMP_ATTR_FLAG_WRITABLE },
    { 11, G_SNMP_INTEGER32,
      IP_FORWARD_MIB_IPFORWARDMETRIC1, "ipForwardMetric1",
       NULL,
      G_STRUCT_OFFSET(ip_forward_mib_ipForwardEntry_t, ipForwardMetric1),
      0,
      GSNMP_ATTR_FLAG_WRITABLE },
    { 12, G_SNMP_INTEGER32,
      IP_FORWARD_MIB_IPFORWARDMETRIC2, "ipForwardMetric2",
       NULL,
      G_STRUCT_OFFSET(ip_forward_mib_ipForwardEntry_t, ipForwardMetric2),
      0,
      GSNMP_ATTR_FLAG_WRITABLE },
    { 13, G_SNMP_INTEGER32,
      IP_FORWARD_MIB_IPFORWARDMETRIC3, "ipForwardMetric3",
       NULL,
      G_STRUCT_OFFSET(ip_forward_mib_ipForwardEntry_t, ipForwardMetric3),
      0,
      GSNMP_ATTR_FLAG_WRITABLE },
    { 14, G_SNMP_INTEGER32,
      IP_FORWARD_MIB_IPFORWARDMETRIC4, "ipForwardMetric4",
       NULL,
      G_STRUCT_OFFSET(ip_forward_mib_ipForwardEntry_t, ipForwardMetric4),
      0,
      GSNMP_ATTR_FLAG_WRITABLE },
    { 15, G_SNMP_INTEGER32,
      IP_FORWARD_MIB_IPFORWARDMETRIC5, "ipForwardMetric5",
       NULL,
      G_STRUCT_OFFSET(ip_forward_mib_ipForwardEntry_t, ipForwardMetric5),
      0,
      GSNMP_ATTR_FLAG_WRITABLE },
    { 0, 0, 0, NULL }
};

static guint32 const ipCidrRouteEntry_oid[] = {1, 3, 6, 1, 2, 1, 4, 24, 4, 1};

static GSnmpAttribute ipCidrRouteEntry_attr[] = {
    { 5, G_SNMP_INTEGER32,
      IP_FORWARD_MIB_IPCIDRROUTEIFINDEX, "ipCidrRouteIfIndex",
       NULL,
      G_STRUCT_OFFSET(ip_forward_mib_ipCidrRouteEntry_t, ipCidrRouteIfIndex),
      0,
      GSNMP_ATTR_FLAG_WRITABLE },
    { 6, G_SNMP_INTEGER32,
      IP_FORWARD_MIB_IPCIDRROUTETYPE, "ipCidrRouteType",
       NULL,
      G_STRUCT_OFFSET(ip_forward_mib_ipCidrRouteEntry_t, ipCidrRouteType),
      0,
      GSNMP_ATTR_FLAG_WRITABLE },
    { 7, G_SNMP_INTEGER32,
      IP_FORWARD_MIB_IPCIDRROUTEPROTO, "ipCidrRouteProto",
       NULL,
      G_STRUCT_OFFSET(ip_forward_mib_ipCidrRouteEntry_t, ipCidrRouteProto),
      0,
      0 },
    { 8, G_SNMP_INTEGER32,
      IP_FORWARD_MIB_IPCIDRROUTEAGE, "ipCidrRouteAge",
       NULL,
      G_STRUCT_OFFSET(ip_forward_mib_ipCidrRouteEntry_t, ipCidrRouteAge),
      0,
      0 },
    { 9, G_SNMP_OBJECTID,
      IP_FORWARD_MIB_IPCIDRROUTEINFO, "ipCidrRouteInfo",
       NULL,
      G_STRUCT_OFFSET(ip_forward_mib_ipCidrRouteEntry_t, ipCidrRouteInfo),
      G_STRUCT_OFFSET(ip_forward_mib_ipCidrRouteEntry_t, _ipCidrRouteInfoLength),
      GSNMP_ATTR_FLAG_WRITABLE },
    { 10, G_SNMP_INTEGER32,
      IP_FORWARD_MIB_IPCIDRROUTENEXTHOPAS, "ipCidrRouteNextHopAS",
       NULL,
      G_STRUCT_OFFSET(ip_forward_mib_ipCidrRouteEntry_t, ipCidrRouteNextHopAS),
      0,
      GSNMP_ATTR_FLAG_WRITABLE },
    { 11, G_SNMP_INTEGER32,
      IP_FORWARD_MIB_IPCIDRROUTEMETRIC1, "ipCidrRouteMetric1",
       NULL,
      G_STRUCT_OFFSET(ip_forward_mib_ipCidrRouteEntry_t, ipCidrRouteMetric1),
      0,
      GSNMP_ATTR_FLAG_WRITABLE },
    { 12, G_SNMP_INTEGER32,
      IP_FORWARD_MIB_IPCIDRROUTEMETRIC2, "ipCidrRouteMetric2",
       NULL,
      G_STRUCT_OFFSET(ip_forward_mib_ipCidrRouteEntry_t, ipCidrRouteMetric2),
      0,
      GSNMP_ATTR_FLAG_WRITABLE },
    { 13, G_SNMP_INTEGER32,
      IP_FORWARD_MIB_IPCIDRROUTEMETRIC3, "ipCidrRouteMetric3",
       NULL,
      G_STRUCT_OFFSET(ip_forward_mib_ipCidrRouteEntry_t, ipCidrRouteMetric3),
      0,
      GSNMP_ATTR_FLAG_WRITABLE },
    { 14, G_SNMP_INTEGER32,
      IP_FORWARD_MIB_IPCIDRROUTEMETRIC4, "ipCidrRouteMetric4",
       NULL,
      G_STRUCT_OFFSET(ip_forward_mib_ipCidrRouteEntry_t, ipCidrRouteMetric4),
      0,
      GSNMP_ATTR_FLAG_WRITABLE },
    { 15, G_SNMP_INTEGER32,
      IP_FORWARD_MIB_IPCIDRROUTEMETRIC5, "ipCidrRouteMetric5",
       NULL,
      G_STRUCT_OFFSET(ip_forward_mib_ipCidrRouteEntry_t, ipCidrRouteMetric5),
      0,
      GSNMP_ATTR_FLAG_WRITABLE },
    { 16, G_SNMP_INTEGER32,
      IP_FORWARD_MIB_IPCIDRROUTESTATUS, "ipCidrRouteStatus",
       NULL,
      G_STRUCT_OFFSET(ip_forward_mib_ipCidrRouteEntry_t, ipCidrRouteStatus),
      0,
      GSNMP_ATTR_FLAG_WRITABLE },
    { 0, 0, 0, NULL }
};


ip_forward_mib_ipForward_t *
ip_forward_mib_new_ipForward()
{
    ip_forward_mib_ipForward_t *ipForward;

    ipForward = (ip_forward_mib_ipForward_t *) g_malloc0(sizeof(ip_forward_mib_ipForward_t) + sizeof(gpointer));
    return ipForward;
}

static ip_forward_mib_ipForward_t *
assign_ipForward(GSList *vbl)
{
    ip_forward_mib_ipForward_t *ipForward;
    char *p;

    ipForward = ip_forward_mib_new_ipForward();
    if (! ipForward) {
        return NULL;
    }

    p = (char *) ipForward + sizeof(ip_forward_mib_ipForward_t);
    * (GSList **) p = vbl;

    gsnmp_attr_assign(vbl, ipForward_oid, sizeof(ipForward_oid)/sizeof(guint32),
                      ipForward_attr, ipForward);

    return ipForward;
}

void
ip_forward_mib_get_ipForward(GSnmpSession *s, ip_forward_mib_ipForward_t **ipForward, gint mask)
{
    GSList *in = NULL, *out = NULL;
    static guint32 base[] = {1, 3, 6, 1, 2, 1, 4, 24, 0};

    *ipForward = NULL;

    gsnmp_attr_get(s, &in, base, 9, 8, ipForward_attr, mask);

    out = g_snmp_session_sync_getnext(s, in);
    g_snmp_vbl_free(in);
    if (out) {
        if (s->error_status != G_SNMP_ERR_NOERROR) {
            g_snmp_vbl_free(out);
            return;
        }
        *ipForward = assign_ipForward(out);
    }
}

void
ip_forward_mib_free_ipForward(ip_forward_mib_ipForward_t *ipForward)
{
    GSList *vbl;
    char *p;

    if (ipForward) {
        p = (char *) ipForward + sizeof(ip_forward_mib_ipForward_t);
        vbl = * (GSList **) p;
        g_snmp_vbl_free(vbl);
        g_free(ipForward);
    }
}

ip_forward_mib_ipForwardEntry_t *
ip_forward_mib_new_ipForwardEntry()
{
    ip_forward_mib_ipForwardEntry_t *ipForwardEntry;

    ipForwardEntry = (ip_forward_mib_ipForwardEntry_t *) g_malloc0(sizeof(ip_forward_mib_ipForwardEntry_t) + sizeof(gpointer));
    return ipForwardEntry;
}

static int
unpack_ipForwardEntry(GSnmpVarBind *vb, ip_forward_mib_ipForwardEntry_t *ipForwardEntry)
{
    guint8 idx = 11;
    guint16 i, len;

    len = 4;
    if (vb->id_len < idx + len) return -1;
    if (len != 4) return -1;
    if (vb->id_len < idx + len) return -1;
    for (i = 0; i < len; i++) {
        ipForwardEntry->ipForwardDest[i] = vb->id[idx++];
    }
    if (vb->id_len < idx) return -1;
    ipForwardEntry->ipForwardProto = vb->id[idx++];
    if (vb->id_len < idx) return -1;
    ipForwardEntry->ipForwardPolicy = vb->id[idx++];
    len = 4;
    if (vb->id_len < idx + len) return -1;
    if (len != 4) return -1;
    if (vb->id_len < idx + len) return -1;
    for (i = 0; i < len; i++) {
        ipForwardEntry->ipForwardNextHop[i] = vb->id[idx++];
    }
    if (vb->id_len > idx) return -1;
    return 0;
}

static int
pack_ipForwardEntry(guint32 *base, guchar *ipForwardDest, gint32 ipForwardProto, gint32 ipForwardPolicy, guchar *ipForwardNextHop)
{
    guint8 idx = 11;
    guint16 i, len;

    len = 4;
    if (len != 4) return -1;
    for (i = 0; i < len; i++) {
        base[idx++] = ipForwardDest[i];
        if (idx >= 128) return -1;
    }
    base[idx++] = ipForwardProto;
    base[idx++] = ipForwardPolicy;
    len = 4;
    if (len != 4) return -1;
    for (i = 0; i < len; i++) {
        base[idx++] = ipForwardNextHop[i];
        if (idx >= 128) return -1;
    }
    return idx;
}

static ip_forward_mib_ipForwardEntry_t *
assign_ipForwardEntry(GSList *vbl)
{
    ip_forward_mib_ipForwardEntry_t *ipForwardEntry;
    char *p;

    ipForwardEntry = ip_forward_mib_new_ipForwardEntry();
    if (! ipForwardEntry) {
        return NULL;
    }

    p = (char *) ipForwardEntry + sizeof(ip_forward_mib_ipForwardEntry_t);
    * (GSList **) p = vbl;

    if (unpack_ipForwardEntry((GSnmpVarBind *) vbl->data, ipForwardEntry) < 0) {
        g_warning("%s: invalid instance identifier", "ipForwardEntry");
        g_free(ipForwardEntry);
        return NULL;
    }

    gsnmp_attr_assign(vbl, ipForwardEntry_oid, sizeof(ipForwardEntry_oid)/sizeof(guint32),
                      ipForwardEntry_attr, ipForwardEntry);

    return ipForwardEntry;
}

void
ip_forward_mib_get_ipForwardTable(GSnmpSession *s, ip_forward_mib_ipForwardEntry_t ***ipForwardEntry, gint mask)
{
    GSList *in = NULL, *out = NULL;
    GSList *row;
    int i;
    static guint32 base[] = {1, 3, 6, 1, 2, 1, 4, 24, 2, 1, 0};

    *ipForwardEntry = NULL;

    gsnmp_attr_get(s, &in, base, 11, 10, ipForwardEntry_attr, mask);

    out = gsnmp_gettable(s, in);
    /* g_snmp_vbl_free(in); */

    if (out) {
        *ipForwardEntry = (ip_forward_mib_ipForwardEntry_t **) g_malloc0((g_slist_length(out) + 1) * sizeof(ip_forward_mib_ipForwardEntry_t *));
        if (! *ipForwardEntry) {
            s->error_status = G_SNMP_ERR_INTERNAL;
            g_snmp_vbl_free(out);
            return;
        }
        for (row = out, i = 0; row; row = g_slist_next(row), i++) {
            (*ipForwardEntry)[i] = assign_ipForwardEntry(row->data);
        }
    }
}

void
ip_forward_mib_get_ipForwardEntry(GSnmpSession *s, ip_forward_mib_ipForwardEntry_t **ipForwardEntry, guchar *ipForwardDest, gint32 ipForwardProto, gint32 ipForwardPolicy, guchar *ipForwardNextHop, gint mask)
{
    GSList *in = NULL, *out = NULL;
    guint32 base[128];
    gint8 len;

    memset(base, 0, sizeof(base));
    memcpy(base, ipForwardEntry_oid, sizeof(ipForwardEntry_oid));
    len = pack_ipForwardEntry(base, ipForwardDest, ipForwardProto, ipForwardPolicy, ipForwardNextHop);
    if (len < 0) {
        g_warning("%s: invalid index values", "ipForwardEntry");
        s->error_status = G_SNMP_ERR_INTERNAL;
        return;
    }

    *ipForwardEntry = NULL;

    gsnmp_attr_get(s, &in, base, len, 10, ipForwardEntry_attr, mask);

    out = g_snmp_session_sync_get(s, in);
    g_snmp_vbl_free(in);
    if (out) {
        if (s->error_status != G_SNMP_ERR_NOERROR) {
            g_snmp_vbl_free(out);
            return;
        }
        *ipForwardEntry = assign_ipForwardEntry(out);
    }
}

void
ip_forward_mib_set_ipForwardEntry(GSnmpSession *s, ip_forward_mib_ipForwardEntry_t *ipForwardEntry, gint mask)
{
    GSList *in = NULL, *out = NULL;
    guint32 base[128];
    gint8 len;

    memset(base, 0, sizeof(base));
    memcpy(base, ipForwardEntry_oid, sizeof(ipForwardEntry_oid));
    len = pack_ipForwardEntry(base, ipForwardEntry->ipForwardDest, ipForwardEntry->ipForwardProto, ipForwardEntry->ipForwardPolicy, ipForwardEntry->ipForwardNextHop);
    if (len < 0) {
        g_warning("%s: invalid index values", "ipForwardEntry");
        s->error_status = G_SNMP_ERR_INTERNAL;
        return;
    }

    gsnmp_attr_set(s, &in, base, len, 10, ipForwardEntry_attr, mask, ipForwardEntry);

    out = g_snmp_session_sync_set(s, in);
    g_snmp_vbl_free(in);
    if (out) {
        g_snmp_vbl_free(out);
    }
}

void
ip_forward_mib_free_ipForwardEntry(ip_forward_mib_ipForwardEntry_t *ipForwardEntry)
{
    GSList *vbl;
    char *p;

    if (ipForwardEntry) {
        p = (char *) ipForwardEntry + sizeof(ip_forward_mib_ipForwardEntry_t);
        vbl = * (GSList **) p;
        g_snmp_vbl_free(vbl);
        g_free(ipForwardEntry);
    }
}

void
ip_forward_mib_free_ipForwardTable(ip_forward_mib_ipForwardEntry_t **ipForwardEntry)
{
    int i;

    if (ipForwardEntry) {
        for (i = 0; ipForwardEntry[i]; i++) {
            ip_forward_mib_free_ipForwardEntry(ipForwardEntry[i]);
        }
        g_free(ipForwardEntry);
    }
}

ip_forward_mib_ipCidrRouteEntry_t *
ip_forward_mib_new_ipCidrRouteEntry()
{
    ip_forward_mib_ipCidrRouteEntry_t *ipCidrRouteEntry;

    ipCidrRouteEntry = (ip_forward_mib_ipCidrRouteEntry_t *) g_malloc0(sizeof(ip_forward_mib_ipCidrRouteEntry_t) + sizeof(gpointer));
    return ipCidrRouteEntry;
}

static int
unpack_ipCidrRouteEntry(GSnmpVarBind *vb, ip_forward_mib_ipCidrRouteEntry_t *ipCidrRouteEntry)
{
    guint8 idx = 11;
    guint16 i, len;

    len = 4;
    if (vb->id_len < idx + len) return -1;
    if (len != 4) return -1;
    if (vb->id_len < idx + len) return -1;
    for (i = 0; i < len; i++) {
        ipCidrRouteEntry->ipCidrRouteDest[i] = vb->id[idx++];
    }
    len = 4;
    if (vb->id_len < idx + len) return -1;
    if (len != 4) return -1;
    if (vb->id_len < idx + len) return -1;
    for (i = 0; i < len; i++) {
        ipCidrRouteEntry->ipCidrRouteMask[i] = vb->id[idx++];
    }
    if (vb->id_len < idx) return -1;
    ipCidrRouteEntry->ipCidrRouteTos = vb->id[idx++];
    len = 4;
    if (vb->id_len < idx + len) return -1;
    if (len != 4) return -1;
    if (vb->id_len < idx + len) return -1;
    for (i = 0; i < len; i++) {
        ipCidrRouteEntry->ipCidrRouteNextHop[i] = vb->id[idx++];
    }
    if (vb->id_len > idx) return -1;
    return 0;
}

static int
pack_ipCidrRouteEntry(guint32 *base, guchar *ipCidrRouteDest, guchar *ipCidrRouteMask, gint32 ipCidrRouteTos, guchar *ipCidrRouteNextHop)
{
    guint8 idx = 11;
    guint16 i, len;

    len = 4;
    if (len != 4) return -1;
    for (i = 0; i < len; i++) {
        base[idx++] = ipCidrRouteDest[i];
        if (idx >= 128) return -1;
    }
    len = 4;
    if (len != 4) return -1;
    for (i = 0; i < len; i++) {
        base[idx++] = ipCidrRouteMask[i];
        if (idx >= 128) return -1;
    }
    base[idx++] = ipCidrRouteTos;
    len = 4;
    if (len != 4) return -1;
    for (i = 0; i < len; i++) {
        base[idx++] = ipCidrRouteNextHop[i];
        if (idx >= 128) return -1;
    }
    return idx;
}

static ip_forward_mib_ipCidrRouteEntry_t *
assign_ipCidrRouteEntry(GSList *vbl)
{
    ip_forward_mib_ipCidrRouteEntry_t *ipCidrRouteEntry;
    char *p;

    ipCidrRouteEntry = ip_forward_mib_new_ipCidrRouteEntry();
    if (! ipCidrRouteEntry) {
        return NULL;
    }

    p = (char *) ipCidrRouteEntry + sizeof(ip_forward_mib_ipCidrRouteEntry_t);
    * (GSList **) p = vbl;

    if (unpack_ipCidrRouteEntry((GSnmpVarBind *) vbl->data, ipCidrRouteEntry) < 0) {
        g_warning("%s: invalid instance identifier", "ipCidrRouteEntry");
        g_free(ipCidrRouteEntry);
        return NULL;
    }

    gsnmp_attr_assign(vbl, ipCidrRouteEntry_oid, sizeof(ipCidrRouteEntry_oid)/sizeof(guint32),
                      ipCidrRouteEntry_attr, ipCidrRouteEntry);

    return ipCidrRouteEntry;
}

void
ip_forward_mib_get_ipCidrRouteTable(GSnmpSession *s, ip_forward_mib_ipCidrRouteEntry_t ***ipCidrRouteEntry, gint mask)
{
    GSList *in = NULL, *out = NULL;
    GSList *row;
    int i;
    static guint32 base[] = {1, 3, 6, 1, 2, 1, 4, 24, 4, 1, 0};

    *ipCidrRouteEntry = NULL;

    gsnmp_attr_get(s, &in, base, 11, 10, ipCidrRouteEntry_attr, mask);

    out = gsnmp_gettable(s, in);
    /* g_snmp_vbl_free(in); */

    if (out) {
        *ipCidrRouteEntry = (ip_forward_mib_ipCidrRouteEntry_t **) g_malloc0((g_slist_length(out) + 1) * sizeof(ip_forward_mib_ipCidrRouteEntry_t *));
        if (! *ipCidrRouteEntry) {
            s->error_status = G_SNMP_ERR_INTERNAL;
            g_snmp_vbl_free(out);
            return;
        }
        for (row = out, i = 0; row; row = g_slist_next(row), i++) {
            (*ipCidrRouteEntry)[i] = assign_ipCidrRouteEntry(row->data);
        }
    }
}

void
ip_forward_mib_get_ipCidrRouteEntry(GSnmpSession *s, ip_forward_mib_ipCidrRouteEntry_t **ipCidrRouteEntry, guchar *ipCidrRouteDest, guchar *ipCidrRouteMask, gint32 ipCidrRouteTos, guchar *ipCidrRouteNextHop, gint mask)
{
    GSList *in = NULL, *out = NULL;
    guint32 base[128];
    gint8 len;

    memset(base, 0, sizeof(base));
    memcpy(base, ipCidrRouteEntry_oid, sizeof(ipCidrRouteEntry_oid));
    len = pack_ipCidrRouteEntry(base, ipCidrRouteDest, ipCidrRouteMask, ipCidrRouteTos, ipCidrRouteNextHop);
    if (len < 0) {
        g_warning("%s: invalid index values", "ipCidrRouteEntry");
        s->error_status = G_SNMP_ERR_INTERNAL;
        return;
    }

    *ipCidrRouteEntry = NULL;

    gsnmp_attr_get(s, &in, base, len, 10, ipCidrRouteEntry_attr, mask);

    out = g_snmp_session_sync_get(s, in);
    g_snmp_vbl_free(in);
    if (out) {
        if (s->error_status != G_SNMP_ERR_NOERROR) {
            g_snmp_vbl_free(out);
            return;
        }
        *ipCidrRouteEntry = assign_ipCidrRouteEntry(out);
    }
}

void
ip_forward_mib_set_ipCidrRouteEntry(GSnmpSession *s, ip_forward_mib_ipCidrRouteEntry_t *ipCidrRouteEntry, gint mask)
{
    GSList *in = NULL, *out = NULL;
    guint32 base[128];
    gint8 len;

    memset(base, 0, sizeof(base));
    memcpy(base, ipCidrRouteEntry_oid, sizeof(ipCidrRouteEntry_oid));
    len = pack_ipCidrRouteEntry(base, ipCidrRouteEntry->ipCidrRouteDest, ipCidrRouteEntry->ipCidrRouteMask, ipCidrRouteEntry->ipCidrRouteTos, ipCidrRouteEntry->ipCidrRouteNextHop);
    if (len < 0) {
        g_warning("%s: invalid index values", "ipCidrRouteEntry");
        s->error_status = G_SNMP_ERR_INTERNAL;
        return;
    }

    gsnmp_attr_set(s, &in, base, len, 10, ipCidrRouteEntry_attr, mask, ipCidrRouteEntry);

    out = g_snmp_session_sync_set(s, in);
    g_snmp_vbl_free(in);
    if (out) {
        g_snmp_vbl_free(out);
    }
}

void
ip_forward_mib_free_ipCidrRouteEntry(ip_forward_mib_ipCidrRouteEntry_t *ipCidrRouteEntry)
{
    GSList *vbl;
    char *p;

    if (ipCidrRouteEntry) {
        p = (char *) ipCidrRouteEntry + sizeof(ip_forward_mib_ipCidrRouteEntry_t);
        vbl = * (GSList **) p;
        g_snmp_vbl_free(vbl);
        g_free(ipCidrRouteEntry);
    }
}

void
ip_forward_mib_free_ipCidrRouteTable(ip_forward_mib_ipCidrRouteEntry_t **ipCidrRouteEntry)
{
    int i;

    if (ipCidrRouteEntry) {
        for (i = 0; ipCidrRouteEntry[i]; i++) {
            ip_forward_mib_free_ipCidrRouteEntry(ipCidrRouteEntry[i]);
        }
        g_free(ipCidrRouteEntry);
    }
}


