I am building an XS interface to a library called libnet. In the library, one call works like this:
libnet_select_device(&sin, &device, ebuf);
So were a passing in a pointer to function for sin. sin is a sockaddr_in struct. So, to develop analogosly in Perl, it should work through passing by ref something like
libnet_select_device($sin, $device, $ebuf);
My XS setup should be like this then:
int
libnet_select_device(sin, device, ebuf)
SockAddrIn & sin = NO_INIT
u_char * & device = (u_char *) SvPV_nolen(ST(1));
u_char & ebuf
OUTPUT:
sin
device
ebuf
The problem, however, is that since I pass by reference $sin would actualyl be holding struct data, to a pointer to it. I tried it with a typemap of T_UV to no avail. It gives me compiling issues about conversion to non-scalar type (a struct) which is a nono. I also tried this:
int
libnet_select_device(sin, device, ebuf)
SockAddrIn * sin = NO_INIT
u_char * & device = (u_char *) SvPV_nolen(ST(1));
u_char & ebuf
OUTPUT:
sin
device
ebuf
SockAddrIn pointers are of type T_PTROBJ (I tried T_PTRREF too). This gives me another problem. It says that sin is not of type SockAddrInPtr. When I typemap to T_PTRREF, it core dumps. As $sin is actually only there to accept what is passed back into it from the function, I suppose I need to initialize it somehow. How can I do that or do whatever it is that will solve my problem?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.