How to set the ip_option_information in IcmpSendEcho

  • Thread starter Milosz - [playseven.com]
  • Start date
M

Milosz - [playseven.com]

If i am right, this should be the structure for ip_option_information in the
IcmpSendEcho function

Public Structure ip_option_information
Dim TTL As Byte
Dim Tos As Byte
Dim flags As Byte
Dim OptionsSize As Byte
Dim OptionsData As Long
End Structure

<DllImport("iphlpapi")> Private Shared Function IcmpSendEcho(ByVal
IcmpHandle As IntPtr, ByVal DestinationAddress As Integer, ByVal
RequestData() As Byte, ByVal RequestSize As Integer, ByVal RequestOptions As
ip_option_information, ByVal ReplyBuffer() As Byte, ByVal ReplySize As
Int32, ByVal Timeout As Int32) As System.UInt32

but how to put it in the function ?
..Net does not support pointers.

i am a little confused. should i havet to write a wrapper in C++ to do this
?

regards

--
-> Milosz Weckowski
www.playseven.com

mailto:[email protected]
ICQ Number: 84867613

Get the enhanced Progressbar and a fine Colorpicker for the Compact Framwork
for free:
http://www.playseven.com/11620/p7_Controls.html
 
A

Alex Feinman [MVP]

Public Clas ip_option_information
Inherits IDisposasble

Dim _Data as new Byte(8)

Public Property Data as Byte()
Get
Return _Data
End Get
End Property

Public Property TTL as Byte
Get
Return _Data(0)
End Get
End Property

Public Property Tos as Byte
Get
Return _Data(1)
End Get
End Property

Public Property Flag as Byte
Get
Return _Data(2)
End Get
End Property

Public Property OptionSize as Byte
Get
Return _Data(3)
End Get
End Property

Public Property [Options] as IntPtr
Get
Return CType(BitConverter.ToInt32(_Data, 4), IntPtr)
End Get
End Property

Public Sub New(OptSize as Integer)
Dim pOpt as IntPtr = LocalAlloc(&H40, OptSize)
Data(3) = CType(OptSize, Byte)
BitConverter.GetBytes(pOpt.ToInt32()).Copy(_Data, 4, 4)
End Sub

Public Sub Dispose()
LocalFree([Options])
End Sub

End Class


Then pass IP_OPTIONS_INFORMATION.Data to the function
 
M

Milosz - [playseven.com]

your GREAT alex !

THX !


Alex Feinman said:
Public Clas ip_option_information
Inherits IDisposasble

Dim _Data as new Byte(8)

Public Property Data as Byte()
Get
Return _Data
End Get
End Property

Public Property TTL as Byte
Get
Return _Data(0)
End Get
End Property

Public Property Tos as Byte
Get
Return _Data(1)
End Get
End Property

Public Property Flag as Byte
Get
Return _Data(2)
End Get
End Property

Public Property OptionSize as Byte
Get
Return _Data(3)
End Get
End Property

Public Property [Options] as IntPtr
Get
Return CType(BitConverter.ToInt32(_Data, 4), IntPtr)
End Get
End Property

Public Sub New(OptSize as Integer)
Dim pOpt as IntPtr = LocalAlloc(&H40, OptSize)
Data(3) = CType(OptSize, Byte)
BitConverter.GetBytes(pOpt.ToInt32()).Copy(_Data, 4, 4)
End Sub

Public Sub Dispose()
LocalFree([Options])
End Sub

End Class


Then pass IP_OPTIONS_INFORMATION.Data to the function

--
Alex Feinman
Coming to MDC? make sure to stop by the session CLI345
on Thursday for OpenNETCF talk

Milosz - said:
If i am right, this should be the structure for ip_option_information in the
IcmpSendEcho function

Public Structure ip_option_information
Dim TTL As Byte
Dim Tos As Byte
Dim flags As Byte
Dim OptionsSize As Byte
Dim OptionsData As Long
End Structure

<DllImport("iphlpapi")> Private Shared Function IcmpSendEcho(ByVal
IcmpHandle As IntPtr, ByVal DestinationAddress As Integer, ByVal
RequestData() As Byte, ByVal RequestSize As Integer, ByVal
RequestOptions
As
ip_option_information, ByVal ReplyBuffer() As Byte, ByVal ReplySize As
Int32, ByVal Timeout As Int32) As System.UInt32

but how to put it in the function ?
.Net does not support pointers.

i am a little confused. should i havet to write a wrapper in C++ to do this
?

regards

--
-> Milosz Weckowski
www.playseven.com

mailto:[email protected]
ICQ Number: 84867613

Get the enhanced Progressbar and a fine Colorpicker for the Compact Framwork
for free:
http://www.playseven.com/11620/p7_Controls.html
 
M

Milosz - [playseven.com]

I was about trying this:



Private Const LMEM_ZEROINIT As Integer = &H40

Private Const LMEM_FIXED As Integer = &H0

Private Const LPTR = (LMEM_FIXED Or LMEM_ZEROINIT)

......

Dim OPPointer As IntPtr = IntPtr.Zero

If opt.TTL > 0 Then

Dim PingOpt As New ip_option_information

PingOpt.TTL = opt.TTL

OPPointer = LocalAlloc(LPTR, 12)

Marshal.StructureToPtr(PingOpt, OPPointer, True)

End If

Dim ret As System.UInt32

ret = IcmpSendEcho(h, ipaddr, RequestData, CInt(RequestData.Length),
OPPointer, reply._Data, reply._Data.Length, opt.TimeOUT)

Dim dwErr As Integer

.....
LocalFree(...)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top