Are there interfaces for IP ports at least raw sockets?

55 views
Skip to first unread message

David Storrs

unread,
Apr 2, 2020, 11:13:32 AM4/2/20
to Racket Users
The Reference lists TCP and UDP but nothing else. I'd like to be able
to implement ICMP, since there doesn't seem to be such a thing at the
moment, and I'm trying to figure out how to do that.

In an ideal world I'd have something like ip-in and ip-out ports as
the complement to tcp-in and tcp-out ports and then I could simply
hand the ip-out port some bytes that constitute an ICMP or etc packet
and away it goes. Failing that, if I can get a raw socket then I
could do the IP stuff on top of it; with that in hand it would be
(more) straightforward to implement other protocols.

Is there a way to do this in Racket?

George Neuner

unread,
Apr 2, 2020, 12:37:57 PM4/2/20
to racket...@googlegroups.com
Windows historically placed a lot of limitations on the use of raw sockets.
https://docs.microsoft.com/en-us/windows/win32/winsock/tcp-ip-raw-sockets-2

There doesn't seem to be any updated information on Win10, so you might
conclude that it has the same limitations as Win7.


Re: ICMP, I think it should be possible to implement at least some of
the functions (not sure about all of them) ... but it will have to be
done via FFI.

George

David Storrs

unread,
Apr 2, 2020, 1:00:44 PM4/2/20
to George Neuner, Racket Users
On Thu, Apr 2, 2020 at 12:37 PM George Neuner <gneu...@comcast.net> wrote:
>
>
> On 4/2/2020 11:13 AM, David Storrs wrote:
> > The Reference lists TCP and UDP but nothing else. I'd like to be able
> > to implement ICMP, since there doesn't seem to be such a thing at the
> > moment, and I'm trying to figure out how to do that.
> >
> > In an ideal world I'd have something like ip-in and ip-out ports as
> > the complement to tcp-in and tcp-out ports and then I could simply
> > hand the ip-out port some bytes that constitute an ICMP or etc packet
> > and away it goes. Failing that, if I can get a raw socket then I
> > could do the IP stuff on top of it; with that in hand it would be
> > (more) straightforward to implement other protocols.
> >
> > Is there a way to do this in Racket?
>
> Windows historically placed a lot of limitations on the use of raw sockets.
> https://docs.microsoft.com/en-us/windows/win32/winsock/tcp-ip-raw-sockets-2
>
> There doesn't seem to be any updated information on Win10, so you might
> conclude that it has the same limitations as Win7.

Doesn't surprise me. Fortunately, I don't need it for Windows, at
least right now.

> Re: ICMP, I think it should be possible to implement at least some of
> the functions (not sure about all of them) ... but it will have to be
> done via FFI.

Cool thanks. Do you happen to know what library I should be FFI'ing
into, ideally for macOS? Trying to find information on using ICMP
programmatically tends to result in things like: return
subprocess("ping hostname")

>
> George
>
> --
> You received this message because you are subscribed to the Google Groups "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/bc77f87f-378c-6d5c-3875-3270cb25134b%40comcast.net.

Sam Tobin-Hochstadt

unread,
Apr 2, 2020, 1:15:12 PM4/2/20
to David Storrs, George Neuner, Racket Users
Here's some C source code which should point to the right functions:
https://www.geeksforgeeks.org/ping-in-c/

I think you can just use `#f` for the library -- all the functions
should be from libc.

Sam
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CAE8gKodjbeVWqdJRKKYEvYspg%3DDtDTk4GbWQeqHCk4kQ%2BPahZA%40mail.gmail.com.

George Neuner

unread,
Apr 2, 2020, 1:32:09 PM4/2/20
to David Storrs, racket users

On 4/2/2020 1:00 PM, David Storrs wrote:
> On Thu, Apr 2, 2020 at 12:37 PM George Neuner <gneu...@comcast.net> wrote:
> >
> > Windows historically placed a lot of limitations on the use of raw sockets.
> > https://docs.microsoft.com/en-us/windows/win32/winsock/tcp-ip-raw-sockets-2
> >
> > There doesn't seem to be any updated information on Win10, so you might
> > conclude that it has the same limitations as Win7.
>
> Doesn't surprise me. Fortunately, I don't need it for Windows, at
> least right now.

But it is because of Windows that Racket doesn't provide raw (or Unix)
sockets.  Racket tries to support all of its features across all target
platforms.


> > Re: ICMP, I think it should be possible to implement at least some of
> > the functions (not sure about all of them) ... but it will have to be
> > done via FFI.
>
> Cool thanks. Do you happen to know what library I should be FFI'ing
> into, ideally for macOS?

Sorry, I don't know MacOS.  In Unix it would be libsocket, and if you
are using GCC then glibc transitively links libsocket and re-exports the
entire socket API.

George

David Storrs

unread,
Apr 2, 2020, 1:45:25 PM4/2/20
to George Neuner, racket users
On Thu, Apr 2, 2020 at 1:32 PM George Neuner <gneu...@comcast.net> wrote:
>
>
> On 4/2/2020 1:00 PM, David Storrs wrote:
> > On Thu, Apr 2, 2020 at 12:37 PM George Neuner <gneu...@comcast.net> wrote:
> > >
> > > Windows historically placed a lot of limitations on the use of raw sockets.
> > > https://docs.microsoft.com/en-us/windows/win32/winsock/tcp-ip-raw-sockets-2
> > >
> > > There doesn't seem to be any updated information on Win10, so you might
> > > conclude that it has the same limitations as Win7.
> >
> > Doesn't surprise me. Fortunately, I don't need it for Windows, at
> > least right now.
>
> But it is because of Windows that Racket doesn't provide raw (or Unix)
> sockets. Racket tries to support all of its features across all target
> platforms.

I mean...Racket tries to be memory-safe etc, but it also has libraries
like 'unsafe/foo'. There's already a unix-sockets library
(https://docs.racket-lang.org/unix-socket/index.html) that is
Unix-only, which I found after starting this thread. Why not have
core modules like unix/sockets and windows/thing-that-only-windows-has
? Seems more useful than simply not having the functionality at all.

>
>
> > > Re: ICMP, I think it should be possible to implement at least some of
> > > the functions (not sure about all of them) ... but it will have to be
> > > done via FFI.
> >
> > Cool thanks. Do you happen to know what library I should be FFI'ing
> > into, ideally for macOS?
>
> Sorry, I don't know MacOS. In Unix it would be libsocket, and if you
> are using GCC then glibc transitively links libsocket and re-exports the
> entire socket API.

Great, thanks.

David Storrs

unread,
Apr 2, 2020, 1:45:43 PM4/2/20
to Sam Tobin-Hochstadt, Racket Users
On Thu, Apr 2, 2020 at 1:15 PM Sam Tobin-Hochstadt <sa...@cs.indiana.edu> wrote:
>
> Here's some C source code which should point to the right functions:
> https://www.geeksforgeeks.org/ping-in-c/
>
> I think you can just use `#f` for the library -- all the functions
> should be from libc.

Much appreciated.

George Neuner

unread,
Apr 2, 2020, 10:56:21 PM4/2/20
to David Storrs, racket users

On 4/2/2020 1:45 PM, David Storrs wrote:
> On Thu, Apr 2, 2020 at 1:32 PM George Neuner <gneu...@comcast.net> wrote:
> >
> > ... it is because of Windows that Racket doesn't provide raw (or Unix)
> > sockets. Racket tries to support all of its features across all target
> > platforms.
>
> I mean...Racket tries to be memory-safe etc, but it also has libraries
> like 'unsafe/foo'. There's already a unix-sockets library
> (https://docs.racket-lang.org/unix-socket/index.html) that is
> Unix-only, which I found after starting this thread. Why not have
> core modules like unix/sockets and windows/thing-that-only-windows-has
> ? Seems more useful than simply not having the functionality at all.

Well, I'm not on the development team, so I can't speak for them. But,
IMO, things which don't work everywhere do not belong in the core - 
they belong in contributed libraries ... which is where you found the
*nix-only library.

However, since (IIRC) 1803, Windows 10 does have a partial
implementation of Unix sockets which provides SOCK_STREAM service only
(no DGRAM or SEQPACKET) ... but there is no mention of this in the
platform docs (docs.microsoft.com), and AFAIHS only a few developer
blogs have described how to get at it: e.g.,
https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/
https://devblogs.microsoft.com/commandline/windowswsl-interop-with-af_unix/
https://github.com/MicrosoftDocs/WSL/tree/live/wsl-samples/afunix-wsl-interop/windows_server


I haven't tried to use Unix sockets on Windows, but I did check that the
"afunix.sys" driver is present on my 1903 system.  [And yes, I know 2003
is due imminently ... as Scooby would say "rotsa ruck".]

Presumably the existing library could be extended to work on recent
versions of Windows 10, but that wouldn't help anyone still running
older versions.  Or Windows 8.1.  Windows 7 is EOL'd, but Windows 8.1
will be supported until 2023, so excluding it might pose a problem.

YMMV,
George




Tony Garnock-Jones

unread,
Apr 9, 2020, 4:52:31 PM4/9/20
to Racket Users
If you've not already seen and considered it, https://github.com/tonyg/racket-packet-socket might be worth a look.

Regards,
Tony

Ray Racine

unread,
Apr 10, 2020, 1:34:37 PM4/10/20
to Racket Users
Appropriate moment to give Syndicate some of the attention level it deserves Racket land, if you have ever wondered "gee what would an entire network stack look like in Racket" spending some COVID-19 down time scanning through Tony's implementation in Syndicate is worthwhile.

Reply all
Reply to author
Forward
0 new messages