String indices::OID to string conversion - SNMP

This is a discussion on String indices::OID to string conversion - SNMP ; I recently learned that string indices have to be converted to the OID format, character by character. Are there any standard C/C++ functions for converting strings to OIDs and vice-versa? I have written my own functions to affect this conversion, ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: String indices::OID to string conversion

  1. String indices::OID to string conversion

    I recently learned that string indices have to be converted to the OID
    format, character by character. Are there any standard C/C++ functions
    for converting strings to OIDs and vice-versa? I have written my own
    functions to affect this conversion, but I would rather go with the
    standard versions, if available.

    Thanks,
    Gus

    ////////////////////string-to-oid////////////////////////////
    #include
    #include

    using namespace std;

    #define OID_DELIM_CHAR '.'

    void
    str2oid(const char* inbuf)
    {
    size_t strsize = strlen(inbuf);

    for(int i = 0; i < strsize; i++)
    {
    cout << (int)inbuf[i];
    if(i < strsize-1)
    cout << OID_DELIM_CHAR;
    }
    }


    main(int argc, char* argv[])
    {
    int retVal = 1;
    if(argc > 1)
    {
    str2oid(argv[1]);
    cout << endl;
    retVal = 0;
    }

    return retVal;
    }


    ////////////////////oid-2-string////////////////////////////
    #include
    #include

    using namespace std;

    #define OID_DELIM_STR "."

    void
    oid2str(const char* oid)
    {
    size_t strsize = strlen(oid);

    char *cpyStr = new char[strsize+1];
    strcpy(cpyStr, oid);
    char* tmp = cpyStr;
    char* tok;

    for(;
    {
    if(!(tok=strtok(tmp, OID_DELIM_STR)))
    break;
    tmp = NULL;
    cout << (char)atoi(tok);
    }

    delete [] cpyStr;
    }


    main(int argc, char* argv[])
    {
    int retVal = 1;
    if(argc > 1)
    {
    oid2str(argv[1]);
    cout << endl;
    retVal = 0;
    }

    return retVal;
    }


  2. Re: String indices::OID to string conversion

    >>>>> On 11 May 2005 11:36:20 -0700, usenet@sta.samsung.com said:

    usenet> I recently learned that string indices have to be converted to
    usenet> the OID format, character by character. Are there any
    usenet> standard C/C++ functions for converting strings to OIDs and
    usenet> vice-versa? I have written my own functions to affect this
    usenet> conversion, but I would rather go with the standard versions,
    usenet> if available.

    There are libraries you can use. EG, net-snmp is a popular C-based
    library that lets you do things like that (www.net-snmp.org)

    --
    Wes Hardaker
    Sparta, Inc.

+ Reply to Thread