digitalmars.D.learn - how to use raw sockets
- maarten van damme (7/7) Feb 29 2012 hello,
- David (5/12) Feb 29 2012 Hello,
- maarten van damme (2/2) Feb 29 2012 I've tried porting libcap once but I failed miserably. If I'd succeed in
- James Miller (17/19) Feb 29 2012 Not porting, writing bindings for it. Its pretty easy. just convert
- maarten van damme (4/4) Feb 29 2012 thank you, I'll give it a try.
- maarten van damme (9/9) Mar 04 2012 I have created some bindings. I'm pretty sure they're not really good (I
- maarten van damme (1/1) Mar 04 2012 and why on earth is timeval declared in std.socket instead of std.time?
- maarten van damme (3/3) Mar 04 2012 I started testing my bindings a bit and when using this program
- Jonathan M Davis (5/6) Mar 04 2012 std.socket is an old module and predates all of Phobos' current time stu...
- maarten van damme (9/16) Mar 04 2012 that was a bit confusing, the casting part from me with timeval was wron...
- maarten van damme (2/2) Mar 04 2012 Thank you, now only have to understand the access violation error.
- maarten van damme (4/4) Mar 05 2012 hehe, had to make my callback function extern(C). Can circumvent this or...
- maarten van damme (4/4) Mar 05 2012 If anyone wants to help with my bindings (maybe they'll ever make it int...
hello, I want to use raw sockets but there is a lack of documentation on how to use them in D. Is there somewhere I can read more about them or has someone succesfully used them? Thank you, maarten
Feb 29 2012
Am 29.02.2012 20:44, schrieb maarten van damme:hello, I want to use raw sockets but there is a lack of documentation on how to use them in D. Is there somewhere I can read more about them or has someone succesfully used them? Thank you, maartenHello, I would use libpcap for that, since this is C you can interface it from D. Bu there are no bindings for it yet, you would have to make them first (you can submit them to https://github.com/D-Programming-Deimos ).
Feb 29 2012
I've tried porting libcap once but I failed miserably. If I'd succeed in porting they wouldn't be of good quality.
Feb 29 2012
On 1 March 2012 10:05, maarten van damme <maartenvd1994 gmail.com> wrote:I've tried porting libcap once but I failed miserably. If I'd succeed in porting they wouldn't be of good quality.Not porting, writing bindings for it. Its pretty easy. just convert the declarations into D extern (C) { declarations. By the looks of it, you'll want to do bindings for https://github.com/mcr/libpcap/blob/master/pcap/pcap.h and possibly https://github.com/mcr/libpcap/blob/master/pcap/bpf.h. The man page here, http://www.tcpdump.org/pcap3_man.html can also give you a good starting point, and you could just write the bindings straight from that if you want. There is documentation to help people write C bindings here: http://dlang.org/interfaceToC.html Also if you submit it to Deimos, and if it happens to be a little rough-around-the-edges or incomplete, somebody else can fill in the gaps. Obviously you need to do a reasonable job, but it is only writing function prototypes, so there's not much that can go wrong. -- James Miller
Feb 29 2012
thank you, I'll give it a try. One of my previous attempts failed because I didn't know what was really needed to include in the bindings and what was excess. I'm going to post what I have in a week, hope it works out.
Feb 29 2012
I have created some bindings. I'm pretty sure they're not really good (I didn't port micros and certain other files) but if I have time I'm going to post them on github. A pretty annoying problem is that I have to use toStringz and that I can't write C strings with std.stdio (have to use std.c.stdio). is there a way around that? anyway, here are the bindings http://pastebin.com/MpGtxMi0 http://pastebin.com/RMRxb3FZ
Mar 04 2012
and why on earth is timeval declared in std.socket instead of std.time?
Mar 04 2012
I started testing my bindings a bit and when using this program http://pastebin.com/3j0YzeAm I get an access violation after the callback has returned...
Mar 04 2012
On Sunday, March 04, 2012 18:10:57 maarten van damme wrote:and why on earth is timeval declared in std.socket instead of std.time?std.socket is an old module and predates all of Phobos' current time stuff. It should probably use a core.time.Duration, but it hasn't been changed to do that. - Jonathan M Davis
Mar 04 2012
2012/3/4 Jonathan M Davis <jmdavisProg gmx.com>On Sunday, March 04, 2012 18:10:57 maarten van damme wrote:that was a bit confusing, the casting part from me with timeval was wrong anyway. Does anyone has any ideas on -how I got that access violation without changing a thing in my callback -how to track it down -how to convert c strings to d strings -how to avoid having to call tostringz all the time thank you :)and why on earth is timeval declared in std.socket instead of std.time?std.socket is an old module and predates all of Phobos' current time stuff. It should probably use a core.time.Duration, but it hasn't been changed to do that. - Jonathan M Davis
Mar 04 2012
Thank you, now only have to understand the access violation error. I didn't knew to!targettype was so powerful.
Mar 04 2012
hehe, had to make my callback function extern(C). Can circumvent this or do I have to keep using extern(C) callback functions? is there somebody willing to D'ify my bindings? or how should I go about doing that myself?
Mar 05 2012
If anyone wants to help with my bindings (maybe they'll ever make it into deimos) You can check them out here: https://github.com/maartenvd/d-libcap-bindings any help/suggestions are welcome.
Mar 05 2012