comp.lang.ada
 help / color / mirror / Atom feed
From: Kim Rostgaard Christensen <krc@greenpc.dk>
Subject: Re: C chars_ptr STORAGE_ERROR in Imported function
Date: Fri, 22 Aug 2008 11:55:37 +0200
Date: 2008-08-22T11:55:37+02:00	[thread overview]
Message-ID: <g8m2fv$enl$1@jacob-sparre.dk> (raw)
In-Reply-To: <48ae803f$0$23588$4f793bc4@news.tdc.fi>

Niklas Holsti wrote:
> Kim Rostgaard Christensen wrote:
>> Hello there
>>
>> I am in progress of binding the pcap c library to ada, it is a part of a
>> school project. And for that i need a funtion that modifies a 
>> parameter to a function like so:
>>
>> char    *pcap_lookupdev(char *);
>>
> ...
>>
>> Do I need to declare the buffer and then then pass its c pointer to 
>> the function?
> 
> That is certainly my interpretation of the "man" text:
> 
>    char *pcap_lookupdev(char *errbuf)
> 
>    pcap_lookupdev() returns a pointer to a network device
>    suitable for use with pcap_open_live() and pcap_lookupnet().
>    If there is an error, NULL is returned and errbuf is filled
>    in with an appropriate error message.
> 
> There is no hint that pcap_lookupdev() itself allocates the errbuf; it 
> just puts something in the caller-provided errbuf. And no doubt places a 
> NUL terminator after the message.
> 
> HTH
> 

the following gives me
*** glibc detected *** double free or corruption (out): 0x0804d830 ***

raised PROGRAM_ERROR : unhandled signal

    procedure Lookup_Device is
       function pcap_lookupdev(ebuff : Interfaces.C.Strings.Chars_Ptr) 
return Interfaces.C.Strings.Chars_Ptr;
       pragma Import (C, pcap_lookupdev, "pcap_lookupdev");

       Device : Interfaces.C.Strings.Chars_Ptr;
       Errbuf_ptr  : Interfaces.C.Strings.Chars_Ptr;
       Errbuf : Char_Array(1 .. 256);  -- the defined buffer size
    begin
       Errbuf_Ptr := New_Char_Array(Errbuf);
       Device := pcap_lookupdev(Errbuf_ptr);

       Ada.Text_IO.Put_Line(Value(Device));
    end Lookup_Device;



  reply	other threads:[~2008-08-22  9:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-22  8:36 C chars_ptr STORAGE_ERROR in Imported function Kim Rostgaard Christensen
2008-08-22  9:03 ` Niklas Holsti
2008-08-22  9:55   ` Kim Rostgaard Christensen [this message]
2008-08-22 11:43     ` Niklas Holsti
2008-08-22 22:54       ` Kim Rostgaard Christensen
2008-08-22 18:48 ` anon
2008-08-22 21:55   ` tmoran
2008-08-23 10:11   ` Niklas Holsti
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox