Ok, I think you are bit confused about the calls. A couple of posts ago, you wrote:

Now for the source of your problem (I think):
XS(XS_Net__LibnetRaw_libnet_init_packet) [...] u_char * buf = (u_char *)SvPV(ST(1),PL_ +na); [...] RETVAL = libnet_init_packet(p_size, &buf); sv_setpv((SV*)ST(1), buf);
This function seems to have used a different typemap for buf which is trying to extract the '\0'-terminated string that it is supposed to point to. I think all you need to do is fix this typemap to be like the other functions. I'm going to check some other things I noticed and I'll reply separately if I detect any problems.
It seems that you are under the impression that libnet_init_packet() and functions like libnet_do_checksum() have the same prototype for buf. They don't. As per my original post, the prototype for libnet_init_packet() is<
int libnet_init_packet(size_t p_size, u_char **buf);
This function asks for a pointer to a pointer. So the pointed-to pointer (confusing, I know...) is being altered. This is how the function gets the pointer returns from malloc() back to the program. The other functions are prototyped like this:
int libnet_build_ip([...], u_char *buf);
The pointer itself is not being modified so the pointer to a pointer is unnecessasry. But the data being pointed to is. If I understand correctly, you thought that this was the way in wich libnet_init_packet() and libnet_destroy_packet() were also prototyped.

So my feeling is that, like a C program would using this library, the value stored in the top level of the program in $buf should be a pointer. In C, I usually do something like this:
u_char *buf; libnet_init_packet(IP_H + TCP_H, &buf); /* This calls malloc() and set +s buf as a pointer to that new memory */ [...] libnet_build_ip([...], buf); /* The pointer value is the same, but dat +a pointed to is altered */
So essentially I am attempt to make the perl calls the same. I did try it some others ways, based on your suggestions and my own tinkering. In the past couple of days, I have tried a few things. Not being experience with XS, I am obviously confused on some issues. The unary & was one example.

For now, though, I don't have a lot of time to devote to contemplating this problem. I still have some ideas that I might attempt to bounce off this thread in the future.

In reply to Re: (tye)Re5: XS question: typemap for a pointer to a pointer? by Big Willy
in thread XS question: typemap for a pointer to a pointer? by Big Willy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.