C# Raw IP Address
-
Hi, Can anyone tell me the C# equivalent ofthe following java code? address = InetAddress.getLocalHost().getAddress(); I've not done anything with networking in C# before but from an admittedly quick inspection it does appear that the java implementation makes more intuitive sense. I'd say it's more feature rich too but I haven't ben able to make complete sense yet of what C# has to offer. Regards, Dave
Regards, Dave
-
Hi, Can anyone tell me the C# equivalent ofthe following java code? address = InetAddress.getLocalHost().getAddress(); I've not done anything with networking in C# before but from an admittedly quick inspection it does appear that the java implementation makes more intuitive sense. I'd say it's more feature rich too but I haven't ben able to make complete sense yet of what C# has to offer. Regards, Dave
Regards, Dave
DwR wrote:
Can anyone tell me the C# equivalent ofthe following java code? address = InetAddress.getLocalHost().getAddress();
IPAddress address = Dns.Resolve("localhost");
Deja View - the feeling that you've seen this post before.
-
DwR wrote:
Can anyone tell me the C# equivalent ofthe following java code? address = InetAddress.getLocalHost().getAddress();
IPAddress address = Dns.Resolve("localhost");
Deja View - the feeling that you've seen this post before.
Hi, Thanks for that. A couple of questions / observations: 1. The C# documentation refers to the resolve method as being obsolete. 2. The java type of "address" is byte[]. The method returns a "raw" ip address. The C# equivalents, including Dns.resolve return an IPAddress[] type which i assume isn't raw. Can C# return raw addresses? I assume the type to use is c# byte[]... Additionally, I'm unclear as to what the java documentation means by a raw ip address. Can you clarify? I'm expecting that it means that I the IPAddress[] type is not the correct type for this operation.
Regards, Dave
-
Hi, Thanks for that. A couple of questions / observations: 1. The C# documentation refers to the resolve method as being obsolete. 2. The java type of "address" is byte[]. The method returns a "raw" ip address. The C# equivalents, including Dns.resolve return an IPAddress[] type which i assume isn't raw. Can C# return raw addresses? I assume the type to use is c# byte[]... Additionally, I'm unclear as to what the java documentation means by a raw ip address. Can you clarify? I'm expecting that it means that I the IPAddress[] type is not the correct type for this operation.
Regards, Dave
DwR wrote:
I'm unclear as to what the java documentation means by a raw ip address
One would presume that the raw IP Address is just the bytes that make up the IP Address - as it would normally be with anything described as raw.
DwR wrote:
I'm expecting that it means that I the IPAddress[] type is not the correct type for this operation
What operation?
Recent blog posts: * Event Organisation (Feedback) * LINQ to XML (part 4) * Scottish Developers June Newsletter My Blog
-
DwR wrote:
I'm unclear as to what the java documentation means by a raw ip address
One would presume that the raw IP Address is just the bytes that make up the IP Address - as it would normally be with anything described as raw.
DwR wrote:
I'm expecting that it means that I the IPAddress[] type is not the correct type for this operation
What operation?
Recent blog posts: * Event Organisation (Feedback) * LINQ to XML (part 4) * Scottish Developers June Newsletter My Blog
Hi, I think I've resolved this. By setting the type as IPAddress the member "GetAddressBytes" can be used to convert the address to bytes matching the type of the variable "address". Thanks for your tip, it pointed me in the right directions. That said, I've hit another problem which seems to be a bit trickier. I need to determine the IP addresses associated with the network interfaces of the multi-homed host the code is running on. I am capturing the available interfaces as follows: NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces(); I then want to loop through the entries and for each one load it's associated IP Addresses into an IPHostEntry instance (or similar). However, I don't see any way to determine the list of ip addresses associated with a particular network interface returned by the foreach loop as it iterates through "interfaces". How is this done?
Regards, Dave