[Mono-list] IPAddress.GetAddressBytes
Dan Smithers
dsmithers at talktalk.net
Wed Feb 20 04:20:02 EST 2008
Thanks for the response Chris,
I have been using the code described on many websites to get the local
IP address
string hostname = Dns.GetHostName();
IPHostEntry ip_entry = Dns.GetHostEntry(hostname);
and then had been taking ip_entry.AddressList[0] to be the address I
need. I have now spotted that this list has changed with the IPv6
address being listed before the IPv4 one.
I have now added tests for AddressFamily.InterNetworkV6 and Is
Loopback(addr) which has solved the problem. I guess it highlights a
weakness in my design which will only get worse if I need to add a
second network card.
dan
Chris Howie wrote:
> On Feb 19, 2008 9:13 AM, Dan Smithers <dsmithers at talktalk.net> wrote:
>> I have a messaging application that was working until recently using
>> IPv4 addresses. I now seem to be getting IPv6 addresses from
>> GetAddressBytes.
>>
>> Is this something in mono that has changed recently?
>
> I don't think that Mono would present an IPv4 address as an IPv6
> address unless your host OS was doing this itself. In order to
> diagnose this we'll need to know how you are obtaining the IPAddress
> instance.
>
>> Is there a way of forcing IPv4 address format?
>
> Not if the object represents an IPv6 address. You can check the
> IPAddress.AddressFamily property to see which version of address it
> represents.
>
More information about the Mono-list
mailing list