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

Re: ICMP socket with Gambas


On 6/28/25 10:26 AM, vuott@xxxxxxxxxxxx wrote:
Uhmmm... sorry, correct structure is:

Public Struct SockAddr
   SinFamily As SHORT
   SinPort As SHORT
   SinAddr As Pointer
End Struct

(with SHORT, not Integer)

Thank you. I tried it, and that doesn't work just a my code didn't work. No address number gets stuffed into the structure.

I made a few changes in my own code, and with the following (including only the pertinent snippets):
[code]

Public Struct In_addr
  s_addr As Integer
End Struct

Public Struct Sockaddr_in
  sin_family As Short
  sin_port As Short
  sin_addr As Struct In_addr
End Struct

' Now to Main() and,
' Of course create the socket already, then...

  DestAddr = New Sockaddr_in
  DestAddr.sin_family = AF_INET
  DestAddr.sin_port = 4096
  rc = inet_pton(AF_INET, "127.0.0.1", DestAddr.sin_addr)

  For p As Integer = 0 To Object.SizeOf(DestAddr) - 1
    Print "Offset:";; p, Byte@(Object.Data(DestAddr) + p), Hex(Byte@(Object.Data(DestAddr) + p))
  Next

[/code]

This is the output:
Offset: 0       2       2
Offset: 1       0       0
Offset: 2       0       0
Offset: 3       16      10
Offset: 4       0       0
Offset: 5       0       0
Offset: 6       0       0
Offset: 7       0       0
Offset: 8       127     7F
Offset: 9       0       0
Offset: 10      0       0
Offset: 11      1       1
Offset: 12      0       0
Offset: 13      0       0
Offset: 14      0       0
Offset: 15      0       0

Data at offsets 4-7 and 12-15 are extraneous bytes that seem to come from the ether. The ICMP message gets sent to "0.0.0.0" (offsets 4-7), which is nowhere, because that is where `sendto` looks for the address.

If I comment out the "sin_addr" member in the Sockaddr_in structure, DestAddr is 8 bytes in size when, it seems to me, it should be only 4. Perhaps Object.SizeOf() is seeing the object as a pointer (8 bytes) instead of reporting the size of its structured data.


--
Lee

--- Gambas User List Netiquette [https://gambaswiki.org/wiki/doc/netiquette] ----
--- Gambas User List Archive [https://lists.gambas-basic.org/archive/user] ----


Follow-Ups:
Re: ICMP socket with Gambasvuott@xxxxxxxxxxxx
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