[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ICMP socket with Gambas - working


Le 29/06/2025 à 17:17, Lee a écrit :
On 6/29/25 9:59 AM, vuott@xxxxxxxxxxxx wrote:
Hello Lee,
...and now ?

Wow, great minds think alike, eh?

I haven't tried your code yet, but I see it does something very similar to what I did to finally get my code working.

I abandoned the use of structures because, for whatever reason, extraneous bytes were being added in. The two Short members of Struct Sockaddr (sin_family and sin_port) took 4 bytes total and then there were 4 extra bytes in the structure which put sin_addr at offset 8 when it should have been at offset 4. Likewise, the single Integer member of Struct In_addr comprised 8 bytes when it should have been only 4. Perhaps that is due to structure field alignment, but that doesn't make sense to me as two Shorts align well with one Integer.


It's because you used "Long" for SinAddr, whereas it must be "Integer". "Long" in Gambas is a 64-bit integer.

Every structure field is aligned to a memory address that is a multiple of the field size, but as the fields order is kept, some extra padding may be added between misaligned fields.

Moreover, the structure you must declare is actually "SockAddr_In", not "SockAddr". So:

Public Struct SockAddr_In
  SinFamily As Short
  SinPort As Short
  SinAddr As Integer
  _Padding[8] As Byte
End Struct

Because you have SockAddr_In6 too for IPV6, which is different, but both can be aliased to SockAddr which is declared that way:

Public Struct SockAddr_In
  SinFamily As Short
  _Padding[14] As Byte
End Struct

Regards,

--
Benoît Minisini.


Follow-Ups:
Re: ICMP socket with Gambas - workingBenoît Minisini <benoit.minisini@xxxxxxxxxxxxxxxx>
Re: ICMP socket with Gambas - workingLee <t.lee.davidson@xxxxxxxxx>
References:
Re: ICMP socket with GambasLee <t.lee.davidson@xxxxxxxxx>
Re: ICMP socket with GambasLinus <olivier.cruilles@xxxxxxxx>
Re: ICMP socket with GambasLee <t.lee.davidson@xxxxxxxxx>
Re: ICMP socket with Gambasvuott@xxxxxxxxxxxx
Re: ICMP socket with GambasLee <t.lee.davidson@xxxxxxxxx>
Re: ICMP socket with Gambasvuott@xxxxxxxxxxxx
Re: ICMP socket with Gambas - workingLee <t.lee.davidson@xxxxxxxxx>