473,396 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 2877
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
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
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
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
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
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
by: zoltan | last post by:
Hi, Consider a structure as follows : struct dummy { int a; int b; int c; };
3
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.