Click here to Skip to main content
15,887,294 members
Home / Discussions / C#
   

C#

 
GeneralRe: a problem about string Pin
harold aptroot7-Jan-10 3:45
harold aptroot7-Jan-10 3:45 
AnswerRe: a problem about string Pin
Ben Fair7-Jan-10 2:58
Ben Fair7-Jan-10 2:58 
GeneralRe: a problem about string Pin
Erdinc277-Jan-10 3:25
Erdinc277-Jan-10 3:25 
GeneralRe: a problem about string Pin
Ben Fair7-Jan-10 4:25
Ben Fair7-Jan-10 4:25 
QuestionDoes the IPv6 protocol deal with UDP datagrams ??? Pin
3bood.ghzawi7-Jan-10 2:08
3bood.ghzawi7-Jan-10 2:08 
AnswerRe: Does the IPv6 protocol deal with UDP datagrams ??? Pin
Dimitri Witkowski7-Jan-10 2:21
Dimitri Witkowski7-Jan-10 2:21 
AnswerRe: Does the IPv6 protocol deal with UDP datagrams ??? Pin
harold aptroot7-Jan-10 2:25
harold aptroot7-Jan-10 2:25 
QuestionGetting invalid IP address............. Pin
3bood.ghzawi7-Jan-10 1:51
3bood.ghzawi7-Jan-10 1:51 
Hi all...

As calling an 'ipAddress' from class 'Sockaddr' to find the local IP address of my PC, it always return an IP address 255.255.255.255 for IPv4, and ffff.ffff.ffff.ffff for IPv6.

the class 'Sockaddr' belongs to 'SharpPcap-2.1.1', the implementation of the class is as follwo:

using System;
using System.Runtime.InteropServices;
using System.Net.NetworkInformation;

namespace SharpPcap.Containers
{
public class Sockaddr
{
public enum Type
{
AF_INET_AF_INET6,
HARDWARE,
UNKNOWN
}
public Type type;

static public System.Net.IPAddress ipAddress; // if type == AF_INET_AF_INET6
public PhysicalAddress hardwareAddress; // if type == HARDWARE

private int _sa_family;
public int sa_family
{
get { return _sa_family; }
}

public Sockaddr(PhysicalAddress hardwareAddress)
{
this.type = Type.HARDWARE;
this.hardwareAddress = hardwareAddress;
}

public Sockaddr(IntPtr sockaddrPtr)
{
// A sockaddr struct. We use this to determine the address family
PcapUnmanagedStructures.sockaddr saddr;

// Marshal memory pointer into a struct
saddr = (PcapUnmanagedStructures.sockaddr)Marshal.PtrToStructure(sockaddrPtr,
typeof(PcapUnmanagedStructures.sockaddr));

// record the sa_family for informational purposes
_sa_family = saddr.sa_family;

byte[] addressBytes;
if(saddr.sa_family == Pcap.AF_INET)
{
type = Type.AF_INET_AF_INET6;
PcapUnmanagedStructures.sockaddr_in saddr_in =
(PcapUnmanagedStructures.sockaddr_in)Marshal.PtrToStructure(sockaddrPtr,
typeof(PcapUnmanagedStructures.sockaddr_in));
ipAddress = new System.Net.IPAddress(saddr_in.sin_addr.s_addr);
} else if(saddr.sa_family == Pcap.AF_INET6)
{
type = Type.AF_INET_AF_INET6;
addressBytes = new byte[16];
PcapUnmanagedStructures.sockaddr_in6 sin6 =
(PcapUnmanagedStructures.sockaddr_in6)Marshal.PtrToStructure(sockaddrPtr,
typeof(PcapUnmanagedStructures.sockaddr_in6));
Array.Copy(sin6.sin6_addr, addressBytes, addressBytes.Length);
ipAddress = new System.Net.IPAddress(addressBytes);
} else if(saddr.sa_family == Pcap.AF_PACKET)
{
type = Type.HARDWARE;

PcapUnmanagedStructures.sockaddr_ll saddr_ll =
(PcapUnmanagedStructures.sockaddr_ll)Marshal.PtrToStructure(sockaddrPtr,
typeof(PcapUnmanagedStructures.sockaddr_ll));

byte[] hardwareAddressBytes = new byte[saddr_ll.sll_halen];
for(int x = 0; x < saddr_ll.sll_halen; x++)
{
hardwareAddressBytes[x] = saddr_ll.sll_addr[x];
}
hardwareAddress = new PhysicalAddress(hardwareAddressBytes); // copy into the PhysicalAddress class
} else
{
type = Type.UNKNOWN;

// place the sockaddr.sa_data into the hardware address just in case
// someone wants access to the bytes
byte[] hardwareAddressBytes = new byte[saddr.sa_data.Length];
for(int x = 0; x < saddr.sa_data.Length; x++)
{
hardwareAddressBytes[x] = saddr.sa_data[x];
}
hardwareAddress = new PhysicalAddress(hardwareAddressBytes);
}
}
}
}

Do anyone can help me ???

Thanks.................
AnswerRe: Getting invalid IP address............. Pin
SeMartens7-Jan-10 2:46
SeMartens7-Jan-10 2:46 
GeneralRe: Getting invalid IP address............. Pin
Luc Pattyn7-Jan-10 3:51
sitebuilderLuc Pattyn7-Jan-10 3:51 
Question.net event in Excel Pin
zecodela7-Jan-10 0:08
zecodela7-Jan-10 0:08 
AnswerRe: .net event in Excel Pin
Dave Kreskowiak7-Jan-10 0:42
mveDave Kreskowiak7-Jan-10 0:42 
GeneralRe: .net event in Excel Pin
zecodela7-Jan-10 1:02
zecodela7-Jan-10 1:02 
GeneralRe: .net event in Excel Pin
dojohansen7-Jan-10 1:45
dojohansen7-Jan-10 1:45 
QuestionReading File From Network drive Pin
Lijo Rajan6-Jan-10 23:56
Lijo Rajan6-Jan-10 23:56 
AnswerRe: Reading File From Network drive Pin
Dimitri Witkowski7-Jan-10 0:15
Dimitri Witkowski7-Jan-10 0:15 
GeneralRe: Reading File From Network drive Pin
Lijo Rajan7-Jan-10 0:18
Lijo Rajan7-Jan-10 0:18 
GeneralRe: Reading File From Network drive Pin
Dimitri Witkowski7-Jan-10 0:35
Dimitri Witkowski7-Jan-10 0:35 
GeneralRe: Reading File From Network drive Pin
Dimitri Witkowski7-Jan-10 1:47
Dimitri Witkowski7-Jan-10 1:47 
AnswerRe: Reading File From Network drive Pin
#realJSOP7-Jan-10 0:19
mve#realJSOP7-Jan-10 0:19 
QuestionVisio Org Chart Wizard Pin
adi.rusu6-Jan-10 22:20
adi.rusu6-Jan-10 22:20 
AnswerRe: Visio Org Chart Wizard Pin
george982328-Apr-11 7:04
george982328-Apr-11 7:04 
QuestionC# Resource Help !!!!! Pin
jojoba20106-Jan-10 21:17
jojoba20106-Jan-10 21:17 
AnswerRe: C# Resource Help !!!!! Pin
SeMartens6-Jan-10 22:37
SeMartens6-Jan-10 22:37 
Questionsoap extensions? Pin
Member 44084976-Jan-10 20:57
Member 44084976-Jan-10 20:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.