Big Willy has asked for the wisdom of the Perl Monks concerning the following question:

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?

Replies are listed 'Best First'.
Re: XS Question: Problem with implementing a C struct representation in Perl
by c-era (Curate) on May 03, 2001 at 16:43 UTC
    I've only been playing with XS, but I think you need to create a typemap. Since I'm not an expert I'll give you a link to a good artical. I hope this helps.
      Way ahead of you my friend...