From ckeen at pestilenz.org Fri Feb 4 08:56:38 2022 From: ckeen at pestilenz.org (Christian Kellermann) Date: Fri, 4 Feb 2022 09:56:38 +0100 Subject: [Newbies] Sending UDP broadcasts Message-ID: Dear List, I am trying to send a UDP broadcast on a Linux host with the following code: ``` s := Socket newUDP. s setOption: 'SO_BROADCAST' value: 1. [[(Delay forSeconds: numberOfSeconds) wait. s sendUDPData: shoutout toHost: '255.255.255.255' port: (self portNumber) ] repeat] fork. ``` I always get a Primitive Failed error for the sendUDPData message. shoutout is a string in this case. What am I missing for this example? Versions used are: Squeak5.3 latest update: #19470 unix linux-gnu x86_64 Open Smalltalk Cog[Spur] VM [CoInterpreterPrimitives VMMaker.oscog-eem.3142] Unix built on Feb 4 2022 08:41:04 Compiler: Clang 13.0.0 platform sources revision VM: 202201220125 Kind regards, Christian -- May you be peaceful, may you live in safety, may you be free from suffering, and may you live with ease. Also encrypt mails to me: gpg key 0x068757350D0328634B833B65C537678F6BC627B5 From ckeen at pestilenz.org Fri Feb 4 09:10:36 2022 From: ckeen at pestilenz.org (Christian Kellermann) Date: Fri, 4 Feb 2022 10:10:36 +0100 Subject: [Newbies] Help with FFI In-Reply-To: <20210210160900.GL41298@pestilenz.org> References: <20210210160900.GL41298@pestilenz.org> Message-ID: * Christian Kellermann [210210 17:09]: > I want to find my way around the FFI module and how to use it in squeak. > No let's step back. I want to use a a binding to libsodium form Tony > (https://www.eighty-twenty.org/2013/06/11/nacl-for-squeak-and-pharo) > and ended up using the Crypto-Nacl-HernanMoralesDurand.13.mcz package > as the most recent one from Tony seemed to be Pharo's FFI syntax, as Tobias suggested to me. > > However each of the supplied tests return a 'module not found error' on my > 64 bit Linux Squeak 5.3+updates with the bundled VM. > > So I tried the Unix examples there and none of those work either, so > before I dig deeper into this I'd like to get some kind of re-assurance > of what I should expect to work on this particular setup. > > The FFI Tests from the bundled package all pass though. > > So my questions are: > > 1. Are the Unix FFI examples supposed to work? > 2. Is the Crypto-Nacl package I want to use recent enough for the FFI? > 3. Is the documentation in swiki still up to date for squeak 5.3? > 4. What's the logic for searching and loading the shared object to bind to > and where do I have to look in the opensmalltalk-vm code? Dear future C-Keen and archive googlers, To answer my own question here using my own build opensmalltalk-vm solved the issue, since the FFI plugin that came with the release bundle did not seem to work. Kind regards, Present C-Keen... -- May you be peaceful, may you live in safety, may you be free from suffering, and may you live with ease. Also encrypt mails to me: gpg key 0x068757350D0328634B833B65C537678F6BC627B5 From Das.Linux at gmx.de Fri Feb 4 13:01:48 2022 From: Das.Linux at gmx.de (Tobias Pape) Date: Fri, 4 Feb 2022 14:01:48 +0100 Subject: [Newbies] Help with FFI In-Reply-To: References: <20210210160900.GL41298@pestilenz.org> Message-ID: <91E442C3-E38D-404B-BD3A-624289EDC017@gmx.de> Dear any-time ckeen > On 4. Feb 2022, at 10:10, Christian Kellermann wrote: > > * Christian Kellermann [210210 17:09]: >> I want to find my way around the FFI module and how to use it in squeak. >> No let's step back. I want to use a a binding to libsodium form Tony >> (https://www.eighty-twenty.org/2013/06/11/nacl-for-squeak-and-pharo) >> and ended up using the Crypto-Nacl-HernanMoralesDurand.13.mcz package >> as the most recent one from Tony seemed to be Pharo's FFI syntax, as Tobias suggested to me. >> >> However each of the supplied tests return a 'module not found error' on my >> 64 bit Linux Squeak 5.3+updates with the bundled VM. >> >> So I tried the Unix examples there and none of those work either, so >> before I dig deeper into this I'd like to get some kind of re-assurance >> of what I should expect to work on this particular setup. >> >> The FFI Tests from the bundled package all pass though. >> >> So my questions are: >> >> 1. Are the Unix FFI examples supposed to work? >> 2. Is the Crypto-Nacl package I want to use recent enough for the FFI? >> 3. Is the documentation in swiki still up to date for squeak 5.3? >> 4. What's the logic for searching and loading the shared object to bind to >> and where do I have to look in the opensmalltalk-vm code? > > Dear future C-Keen and archive googlers, > > To answer my own question here using my own build opensmalltalk-vm solved the issue, since > the FFI plugin that came with the release bundle did not seem to work. Thanks for the info! and Thanks for sharing, even after this time :D. Could you share which vm bundled the non-working FFI plugin? Best regards -Tobias [cc squeak-dev/vm-dev] From Das.Linux at gmx.de Fri Feb 4 13:46:36 2022 From: Das.Linux at gmx.de (Tobias Pape) Date: Fri, 4 Feb 2022 14:46:36 +0100 Subject: [Newbies] Sending UDP broadcasts In-Reply-To: References: Message-ID: <5FC1775E-C12C-482D-8221-0D0CBA337516@gmx.de> Hi Christian > On 4. Feb 2022, at 09:56, Christian Kellermann wrote: > > Dear List, > > I am trying to send a UDP broadcast on a Linux host with the following code: > > ``` > s := Socket newUDP. > > s setOption: 'SO_BROADCAST' value: 1. > [[(Delay forSeconds: numberOfSeconds) wait. > s sendUDPData: shoutout toHost: '255.255.255.255' port: (self portNumber) ] > repeat] fork. > ``` > > I always get a Primitive Failed error for the sendUDPData message. > shoutout is a string in this case. > > What am I missing for this example? The host is not a string but rather an address. Try this: ``` addr := NetNameResolver addressForName: '255.255.255.255' timeout: 10. s := Socket newUDP. s setOption: 'SO_BROADCAST' value: 1. [[(Delay forSeconds: numberOfSeconds) wait. s sendUDPData: shoutout toHost: addr port: (self portNumber) ] repeat] fork. ``` see also the lone sender of #sendUDPData:toHost:port: and subsequently #sendData:toHost:port: in Socket>>timeTestUDP: ``` "..." serverAddr := NetNameResolver addressForName: serverName timeout: 10. serverAddr = nil ifTrue: [self error: 'Could not find the address for ' , serverName]. s := self newUDP. "a 'random' port number will be allocated by the system" "..." s sendData: '!' toHost: serverAddr port: 13. "13 is the daytime service" Transcript show: 'the time server reports: ' , s receiveData. ``` Best regards -Tobias > > Versions used are: > > Squeak5.3 > latest update: #19470 > unix linux-gnu x86_64 > > Open Smalltalk Cog[Spur] VM [CoInterpreterPrimitives VMMaker.oscog-eem.3142] > Unix built on Feb 4 2022 08:41:04 Compiler: Clang 13.0.0 > platform sources revision VM: 202201220125 > > Kind regards, > > Christian From ckeen at pestilenz.org Fri Feb 4 16:32:03 2022 From: ckeen at pestilenz.org (Christian Kellermann) Date: Fri, 4 Feb 2022 17:32:03 +0100 Subject: [Newbies] Sending UDP broadcasts In-Reply-To: <5FC1775E-C12C-482D-8221-0D0CBA337516@gmx.de> References: <5FC1775E-C12C-482D-8221-0D0CBA337516@gmx.de> Message-ID: Hey Tobias! * Tobias Pape [220204 14:46]: > The host is not a string but rather an address. Try this: > > ``` > addr := NetNameResolver addressForName: '255.255.255.255' timeout: 10. > s := Socket newUDP. > > s setOption: 'SO_BROADCAST' value: 1. > [[(Delay forSeconds: numberOfSeconds) wait. > s sendUDPData: shoutout toHost: addr port: (self portNumber) ] > repeat] fork. > ``` Oh, duh! Yes of course. I stopped at the call pragma, I should have gone deeper. I somehow missed the example in the code. Another error state for invalid parameters might have helped here in general though. Thanks for your patience explaining all this. Cheers, Christian -- May you be peaceful, may you live in safety, may you be free from suffering, and may you live with ease. Also encrypt mails to me: gpg key 0x068757350D0328634B833B65C537678F6BC627B5 From Das.Linux at gmx.de Fri Feb 4 16:54:36 2022 From: Das.Linux at gmx.de (Tobias Pape) Date: Fri, 4 Feb 2022 17:54:36 +0100 Subject: [Newbies] Sending UDP broadcasts In-Reply-To: References: <5FC1775E-C12C-482D-8221-0D0CBA337516@gmx.de> Message-ID: <3FCF68C9-D776-4C3B-8030-51E515E200E9@gmx.de> Hey > On 4. Feb 2022, at 17:32, Christian Kellermann wrote: > > Hey Tobias! > > * Tobias Pape [220204 14:46]: >> The host is not a string but rather an address. Try this: >> >> ``` >> addr := NetNameResolver addressForName: '255.255.255.255' timeout: 10. >> s := Socket newUDP. >> >> s setOption: 'SO_BROADCAST' value: 1. >> [[(Delay forSeconds: numberOfSeconds) wait. >> s sendUDPData: shoutout toHost: addr port: (self portNumber) ] >> repeat] fork. >> ``` > > Oh, duh! Yes of course. I stopped at the call pragma, I should have gone deeper. > I somehow missed the example in the code. No worries! > > Another error state for invalid parameters might have helped here in general though. Funnily enough, the primitive does this for all sort of things: (c code generated from SLANG: https://github.com/OpenSmalltalk/opensmalltalk-vm/blob/Cog/src/plugins/SocketPlugin/SocketPlugin.c#L2053 ) but not the host. This might be because things changed over time, and, indeed, there used to be a variant to pass a host in a different manner. > > Thanks for your patience explaining all this. No, no worries at all. I actually debugged the VM until i reached here: https://github.com/OpenSmalltalk/opensmalltalk-vm/blob/Cog/src/plugins/SocketPlugin/SocketPlugin.c#L2108 and, yes, sz was not 4, and yes, primitiveFail should probably be primitiveFailFor(PrimErrBadArgument) :D Best regards -Tobias > > Cheers, > > Christian