473,509 Members | 2,946 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pcap_if structure in C#( urgent )

Hello friends,

i am doing a project in C# which involves accessing funtions and
structres from winpcap. so i would like some one to please help me to
access the pcap_if structure in my C# program. i have tried doing it by
DllImport but i am not able to do it.

Please help me its very urgent.

thank u all.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
3 2879
Vineet,

From what I can tell, this would be the definitions that you need:

[StructLayout(LayoutKind.Sequential)]
public struct in_addr
{
public byte s_b1;
public byte s_b2;
public byte s_b3;
public byte s_b4;
}

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public struct sockaddr_in
{
public short sin_family;
[MarshalAs(UnmanagedType.U2)]
public short sin_port;
public in_addr sin_addr;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=8)]
public string sin_zero;
}

[StructLayout(LayoutKind.Sequential)]
public struct pcap_addr
{
public IntPtr next;
public IntPtr addr;
public IntPtr netmask;
public IntPtr broadaddr;
public IntPtr dstaddr;
}

[StructLayout(LayoutKind.Sequential)]
public struct pcap_if
{
public IntPtr next;
public IntPtr name;
public IntPtr description;
public IntPtr addresses
[MarshalAs(UnmanagedType.U4)]
public int flags;
}

Now, you will have to marshal most of the information yourself
(basically, anything with an IntPtr type in the field). You might have some
better luck using some unsafe code, but all in all, this will be quite the
pain to use. You might want to create a C++ implementation which will
simplify the process, and then expose that to managed code.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Vineet S" <vi****@yahoo.co.uk> wrote in message
news:Oc**************@TK2MSFTNGP10.phx.gbl...
Hello friends,

i am doing a project in C# which involves accessing funtions and
structres from winpcap. so i would like some one to please help me to
access the pcap_if structure in my C# program. i have tried doing it by
DllImport but i am not able to do it.

Please help me its very urgent.

thank u all.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #2
Vineet,

From what I can tell, this would be the definitions that you need:

[StructLayout(LayoutKind.Sequential)]
public struct in_addr
{
public byte s_b1;
public byte s_b2;
public byte s_b3;
public byte s_b4;
}

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public struct sockaddr_in
{
public short sin_family;
[MarshalAs(UnmanagedType.U2)]
public short sin_port;
public in_addr sin_addr;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=8)]
public string sin_zero;
}

[StructLayout(LayoutKind.Sequential)]
public struct pcap_addr
{
public IntPtr next;
public IntPtr addr;
public IntPtr netmask;
public IntPtr broadaddr;
public IntPtr dstaddr;
}

[StructLayout(LayoutKind.Sequential)]
public struct pcap_if
{
public IntPtr next;
public IntPtr name;
public IntPtr description;
public IntPtr addresses
[MarshalAs(UnmanagedType.U4)]
public int flags;
}

Now, you will have to marshal most of the information yourself
(basically, anything with an IntPtr type in the field). You might have some
better luck using some unsafe code, but all in all, this will be quite the
pain to use. You might want to create a C++ implementation which will
simplify the process, and then expose that to managed code.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Vineet S" <vi****@yahoo.co.uk> wrote in message
news:Oc**************@TK2MSFTNGP10.phx.gbl...
Hello friends,

i am doing a project in C# which involves accessing funtions and
structres from winpcap. so i would like some one to please help me to
access the pcap_if structure in my C# program. i have tried doing it by
DllImport but i am not able to do it.

Please help me its very urgent.

thank u all.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #3
Hello Nick,

I got the code u sent for the pcap_if structure. But i am really finding
it painful to Marshal the structure members.

the pcap_if structure contains members like next, description. so when i
call the function
pcap_findalldevs(ref IntPtr alldevs,
StringBuilder errbuf );

then i am not able to access each of the member items.

Please let me know how to do it.

Regards,
Vineet

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
249
by: Vineet S | last post by:
Hello friends, i am doing a project in C# which involves accessing funtions and structres from winpcap. so i would like some one to please help me to access the pcap_if structure in my C#...
0
235
by: vijaya | last post by:
I've to invoke a unmanaged dll fucntion in C# which uses a callback fucntion.The unmanaged dll fucntion is as follows **************************************** The Original Fucntion in the dll...
3
1501
by: avy31 | last post by:
Hy, I have a problem at which I can not find the solution: I have this: Declare Sub VRB_IO_StdInstel Lib "TWVRB408.DLL" Alias "_VRB_IO_StdInstel@12" (ByVal Mode As Integer, ByVal szIniFile As...
0
1612
by: IT Recruiter | last post by:
*Very Urgent Rek - SQL Server DBA from Direct Client: Full time* @ New Jersey ***Please send your resumes IMMEDIATELY to nslakshmi@eprocorp.com*** Job Title: SQL Server Developer with...
0
1342
by: Miguel Dias Moura | last post by:
Hello, I am working on an Asp.Net 2.0 / SQL 2005 web site. I am using profile to save the users info on the database. For example, I have the following structure: Public Structure Name...
14
8611
by: zoltan | last post by:
Hi, Consider a structure as follows : struct dummy { int a; int b; int c; };
3
6434
by: N. Spiker | last post by:
I am attempting to receive a single TCP packet with some text ending with carriage return and line feed characters. When the text is send and the packet has the urgent flag set, the text read from...
3
7822
by: victorporton | last post by:
D.K. is traveling from City A to City B. He can stop at some designated spots only. I am trying to use Dijkstra’s algorithm to determine the “spot-to-spot” path that will get D.K. from City A to...
1
1560
by: toskg | last post by:
I am seeking an Urgent Help from all my seniors and experts to complete my assignment. I am doing a Project for Multi-Level Marketing(MLM) Co. Website using ASP (DreamWeaver 8.0) and MS-Access as...
0
7344
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7412
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5060
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3216
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
441
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.