My problem is the same: I have two functions, print_ip(const char* buf,
size_t buflen), and save_ip(const char* buf, size_t buflen). In the
print_ip the value is cast correctly, but in save_ip not.

void print_ip(const char* buf, size_t buflen) {
    unsigned const char* bp = (unsigned const char*) buf;
    if (buflen > 0) {
        cout << static_cast<int> (*bp++);
        for (size_t i = 1; i < buflen; ++i)
            cout << "." << static_cast<int> (*bp++);
    }
}

string save_ip(const char* buf, size_t buflen) {
    unsigned const char* bp = (unsigned const char*) buf;
    string returned("test:");
    if (buflen > 0) {
        returned += static_cast<int> (*bp++);
        for (size_t i = 1; i < buflen; ++i) {
            returned += '.';
            returned += static_cast<int> (*bp++);
        }
    }
    return returned;
}

What am I doing wrong?


2013/10/30 Rafael Ratacheski <rafaelratache...@gmail.com>

> Sorry Walter and Magnus. I didnt expose my quest properly. The input of
> function is a variable with the value of the oid "netdotmediaipadress" and
> the size of this value. This function make two things: save the input value
> in a string in the standard ip adress format. And print the input value at
> the same format. The print is ok, then my problem is save the value in a
> formatted string. Thanks
> Em 30/10/2013 06:39, "Schmoll Walter" <walter.schm...@andritz.com>
> escreveu:
>
>  Hi Rafael!****
>>
>> ** **
>>
>> I’m having the same problems as Magnus: I don’t have an idea what your
>> code should do. From ****
>>
>> “the oid value in a string”****
>>
>> and****
>>
>> cout << static_cast<long> (*bp++)<<”.“;****
>>
>> I guess you are trying to format an OID from its binary form in a text
>> like 1.3.6.345.67.8. If this is so, then one of your problems is that the
>> binary form doesn’t use 8bit integers (unsigned char), the value range
>> would be too small. Net-snmp uses the type oid which is normally a a few
>> bits wider J. Use this type instead of void * or unsigned char *.****
>>
>> And by the way: Why don’t you use a function like snprint_objid, which is
>> part of net-snmp lib?****
>>
>> I haven’t read your code in detail, so maybe I’m wrong.****
>>
>> ** **
>>
>> Walter****
>>
>> ** **
>>
>> *From:* Rafael Ratacheski [mailto:rafaelratache...@gmail.com]
>> *Sent:* Dienstag, 29. Oktober 2013 19:51
>> *To:* net-snmp-coders@lists.sourceforge.net
>> *Subject:* Trouble in concatenate a value to a string****
>>
>> ** **
>>
>> Hello, I'm having problem in concatenate the oid value in a string. I've
>> tried several possible ways, but all unsuccessfully.  Can you help me?
>> My code is
>>
>> string print_ip(const void* buf, size_t buflen) {
>>     unsigned const char* bp = (unsigned const char*) buf;
>>     string returned("test:");
>>     string sp("");
>>     while (buflen--) {
>>         if (buflen == 0) {
>>             cout << static_cast<long> (*bp++);
>>             bp--;
>>             sp=static_cast<int> (*bp++);
>>             returned += sp;
>>         } else {
>>             cout << static_cast<long> (*bp++) << ".";
>>             bp--;
>>             sp=static_cast<int> (*bp++);
>>             returned += sp;
>>             returned += ".";
>>         }
>>     }
>>     puts("");
>>     cout << returned;
>>     return returned;
>> }****
>>   ------------------------------
>>
>> *This message and any attachments are solely for the use of the intended
>> recipients. They may contain privileged and/or confidential information or
>> other information protected from disclosure. If you are not an intended
>> recipient, you are hereby notified that you received this email in error
>> and that any review, dissemination, distribution or copying of this email
>> and any attachment is strictly prohibited. If you have received this email
>> in error, please contact the sender and delete the message and any
>> attachment from your system.*
>>
>> *Thank You.*
>> ------------------------------
>>
>
------------------------------------------------------------------------------
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to