www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - how to use raw sockets

reply maarten van damme <maartenvd1994 gmail.com> writes:
--e89a8ffbaca322c3b304ba1f922d
Content-Type: text/plain; charset=ISO-8859-1

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

--e89a8ffbaca322c3b304ba1f922d
Content-Type: text/html; charset=ISO-8859-1

hello,<div>I want to use raw sockets but there is a lack of documentation on
how to use them in D.</div><div>Is there somewhere I can read more about them
or has someone succesfully used them?</div><div><br></div><div>Thank you,</div>
<div>maarten</div>

--e89a8ffbaca322c3b304ba1f922d--
Feb 29 2012
next sibling parent 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
prev sibling next sibling parent maarten van damme <maartenvd1994 gmail.com> writes:
--047d7b10d07de30fbd04ba20b423
Content-Type: text/plain; charset=ISO-8859-1

I've tried porting libcap once but I failed miserably. If I'd succeed in
porting they wouldn't be of good quality.

--047d7b10d07de30fbd04ba20b423
Content-Type: text/html; charset=ISO-8859-1

I&#39;ve tried porting libcap once but I failed miserably. If I&#39;d succeed
in porting they wouldn&#39;t be of good quality.

--047d7b10d07de30fbd04ba20b423--
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:
--047d7b10cef5434ee404ba21bc59
Content-Type: text/plain; charset=ISO-8859-1

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.

--047d7b10cef5434ee404ba21bc59
Content-Type: text/html; charset=ISO-8859-1

thank you, I&#39;ll give it a try.<div>One of my previous attempts failed
because I didn&#39;t know what was really needed to include in the bindings and
what was excess. I&#39;m going to post what I have in a week, hope it works
out.</div>
<div><br></div><div><br></div>

--047d7b10cef5434ee404ba21bc59--
Feb 29 2012
prev sibling next sibling parent maarten van damme <maartenvd1994 gmail.com> writes:
--047d7b10c961a4eb8404ba68e45f
Content-Type: text/plain; charset=ISO-8859-1

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

--047d7b10c961a4eb8404ba68e45f
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

I have created some bindings. I&#39;m pretty sure they&#39;re not really go=
od (I didn&#39;t port micros and certain other files) but if I have time I&=
#39;m going to post them on github.<div>A pretty annoying problem is that I=
 have to use toStringz and that I can&#39;t write C strings with std.stdio =
(have to use std.c.stdio). is there a way around that?</div>
<div>anyway, here are the bindings</div><div><a href=3D"http://pastebin.com=
/MpGtxMi0">http://pastebin.com/MpGtxMi0</a>
</div><div><a href=3D"http://pastebin.com/RMRxb3FZ">http://pastebin.com/RMR=
xb3FZ</a>
</div>

--047d7b10c961a4eb8404ba68e45f--
Mar 04 2012
prev sibling next sibling parent maarten van damme <maartenvd1994 gmail.com> writes:
--047d7b10d07da718b604ba6de415
Content-Type: text/plain; charset=ISO-8859-1

and why on earth is timeval declared in std.socket instead of std.time?

--047d7b10d07da718b604ba6de415
Content-Type: text/html; charset=ISO-8859-1

and why on earth is timeval declared in std.socket instead of std.time?

--047d7b10d07da718b604ba6de415--
Mar 04 2012
prev sibling next sibling parent maarten van damme <maartenvd1994 gmail.com> writes:
--047d7b10cef5a0980104ba6e3243
Content-Type: text/plain; charset=ISO-8859-1

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...

--047d7b10cef5a0980104ba6e3243
Content-Type: text/html; charset=ISO-8859-1

I started testing my bindings a bit and when using this program<div><a
href="http://pastebin.com/3j0YzeAm">http://pastebin.com/3j0YzeAm</a>
</div><div>I get an access violation after the callback has returned...</div>

--047d7b10cef5a0980104ba6e3243--
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:
--047d7b10d07dc0446b04ba71e75f
Content-Type: text/plain; charset=ISO-8859-1

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

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 :) --047d7b10d07dc0446b04ba71e75f Content-Type: text/html; charset=ISO-8859-1 <div class="gmail_quote">2012/3/4 Jonathan M Davis <span dir="ltr">&lt;<a href="mailto:jmdavisProg gmx.com">jmdavisProg gmx.com</a>&gt;</ pan><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <div class="im">On Sunday, March 04, 2012 18:10:57 maarten van damme wrote:<br> &gt; and why on earth is timeval declared in std.socket instead of std.time?<br> <br> </div>std.socket is an old module and predates all of Phobos&#39; current time stuff. It<br> should probably use a core.time.Duration, but it hasn&#39;t been changed to do<br> that.<br> <span class="HOEnZb"><font color="#888888"><br> - Jonathan M Davis<br> </font></span></blockquote></div>that was a bit confusing, the casting part from me with timeval was wrong anyway.<div>Does anyone has any ideas on</div><div>-how I got that access violation without changing a thing in my callback</div> <div>-how to track it down</div><div>-how to convert c strings to d strings</div><div>-how to avoid having to call tostringz all the time</div><div><br></div><div>thank you :)</div> --047d7b10d07dc0446b04ba71e75f--
Mar 04 2012
prev sibling next sibling parent maarten van damme <maartenvd1994 gmail.com> writes:
--047d7b2ee0034973da04ba79f551
Content-Type: text/plain; charset=ISO-8859-1

Thank you, now only have to understand the access violation error.
I didn't knew to!targettype was so powerful.

--047d7b2ee0034973da04ba79f551
Content-Type: text/html; charset=ISO-8859-1

Thank you, now only have to understand the access violation error.<div>I
didn&#39;t knew to!targettype was so powerful.</div>

--047d7b2ee0034973da04ba79f551--
Mar 04 2012
prev sibling next sibling parent maarten van damme <maartenvd1994 gmail.com> writes:
--047d7b33db5063e6a704ba82cd9d
Content-Type: text/plain; charset=ISO-8859-1

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?

--047d7b33db5063e6a704ba82cd9d
Content-Type: text/html; charset=ISO-8859-1

hehe, had to make my callback function extern(C). Can circumvent this or do I
have to keep using extern(C) callback functions?<div>is there somebody willing
to D&#39;ify my bindings? or how should I go about doing that myself?</div>

--047d7b33db5063e6a704ba82cd9d--
Mar 05 2012
prev sibling parent maarten van damme <maartenvd1994 gmail.com> writes:
--047d7b10c9612513a804ba863e70
Content-Type: text/plain; charset=ISO-8859-1

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.

--047d7b10c9612513a804ba863e70
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

If anyone wants to help with my bindings (maybe they&#39;ll ever make it in=
to deimos) You can check them out here:
<a href=3D"https://github.com/maartenvd/d-libcap-bindings">https://github.c=
om/maartenvd/d-libcap-bindings</a>=A0any help/suggestions are welcome.

--047d7b10c9612513a804ba863e70--
Mar 05 2012