On Fri, 2013-10-04 at 18:13 +0000, Rafael Ratacheski wrote:
> 
> Your solution resolve my problem partially, I have success to print
> the value but my real objective is save the value in a buffer, and
> when i try do this, with your method, i don't have success. The printf
> line is just to verify the saved value.
> 
> About the memory allocated, i think this resolve 


> size_t test = 64;
>             int *sp = malloc(test);
>             memcpy(sp, vars->val.string, vars->val_len);

Kind of. You are allocating 64 bytes to store a 6-byte value.

>             int *teste = htonl(*sp);

Why are you insisting on byteswapping the first four bytes of the value?
Why are you insisting on storing them in a pointer??? (not in the
pointed to value, in the pointer!)

>             printf("value #%d is a string: %x \n", count++, teste);

Here you are only trying to print the first four bytes of the value. I
suppose that is the reason for the last two bytes to not be visible.

>             free(sp);


void printbuf(const void* buf, size_t buflen)
{
  const unsigned char* bp = (const unsigned char*)buf;
  while (buflen--)
    printf("%02x", *bp++);
}


...

printfbuf(vars->val.string, vars->val_len);
puts("");
char *sp = malloc(vars->val_len);
memcpy(sp, vars->val.string, vars->val_len);
printbuf(sp, vars->val_len);
puts("");
free(sp);


/MF



------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134791&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