www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - how to use raw sockets

reply maarten van damme <maartenvd1994 gmail.com> writes:
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
next sibling parent reply David <d dav1d.de> writes:
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,
 maarten
Hello, 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
next sibling parent maarten van damme <maartenvd1994 gmail.com> writes:
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
prev sibling next sibling parent James Miller <james aatch.net> writes:
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
prev sibling next sibling parent maarten van damme <maartenvd1994 gmail.com> writes:
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
prev sibling next sibling parent maarten van damme <maartenvd1994 gmail.com> writes:
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
prev sibling next sibling parent maarten van damme <maartenvd1994 gmail.com> writes:
and why on earth is timeval declared in std.socket instead of std.time?
Mar 04 2012
prev sibling parent maarten van damme <maartenvd1994 gmail.com> writes:
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
prev sibling next sibling parent Jonathan M Davis <jmdavisProg gmx.com> writes:
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
prev sibling next sibling parent maarten van damme <maartenvd1994 gmail.com> writes:
2012/3/4 Jonathan M Davis <jmdavisProg gmx.com>

 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
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 :)
Mar 04 2012
prev sibling next sibling parent maarten van damme <maartenvd1994 gmail.com> writes:
Thank you, now only have to understand the access violation error.
I didn't knew to!targettype was so powerful.
Mar 04 2012
prev sibling next sibling parent maarten van damme <maartenvd1994 gmail.com> writes:
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
prev sibling parent maarten van damme <maartenvd1994 gmail.com> writes:
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