[erlang-questions] inet:ifget("eth0", [broadaddr])
Raimo Niskanen
raimo+erlang-questions@REDACTED
Wed Mar 2 09:17:12 CET 2011
On Tue, Mar 01, 2011 at 09:47:45PM +0000, Bob Cowdery wrote:
> I've found another function inet:getifaddrs/0 which returns a host of
> information:
>
> {ok,[{"\\DEVICE\\TCPIP_{821E4055-EB4F-4E8A-B7F2-30FF9F055679}",
> [{flags,[up,broadcast,running,multicast]},
> {addr,{65152,0,0,0,13375,30402,12581,1246}},
> {netmask,{65535,65535,65535,65535,0,0,0,0}},
> {addr,{192,168,1,65}},
> {netmask,{255,255,255,0}},
> {broadaddr,{192,168,1,255}},
> {hwaddr,[0,25,209,164,163,180]}]},
> {"\\DEVICE\\TCPIP_{0D3F6CDF-8C9C-441B-AE00-70C76036CE1B}",
> [{flags,[up,broadcast,running,multicast]},
> {addr,{65152,0,0,0,6586,36203,15466,30550}},
> {netmask,{65535,65535,65535,65535,0,0,0,0}},
> {addr,{192,168,56,1}},
> {netmask,{255,255,255,0}},
> {broadaddr,{192,168,56,255}},
> {hwaddr,[8,0,39,0,24,23]}]},
> {"\\DEVICE\\TCPIP_{E29AC6C2-7037-11DE-816D-806E6F6E6963}",
> [{flags,[up,loopback,running]},
> {addr,{0,0,0,0,0,0,0,1}},
> {netmask,{65535,65535,65535,65535,65535,65535,65535,65535}},
> {addr,{127,0,0,1}},
> {netmask,{255,0,0,0}}]},
> {"\\DEVICE\\TCPIP_{D492CD99-E0DE-41CE-9872-FE16A171110D}",
> [{flags,[up]},
> {addr,{65152,0,0,0,0,24318,49320,321}},
> {netmask,{65535,65535,65535,65535,65535,65535,65535,65535}},
> {hwaddr,[0,0,0,0,0,0,0,224]}]},
> {"\\DEVICE\\TCPIP_{CDBD6FCC-4871-4D01-8B5D-E1EC67B4D776}",
> [{flags,[up,running]},
> {addr,{8193,0,24309,31229,6352,13625,11104,54066}},
> {netmask,{0,0,0,0,0,0,0,0}},
> {addr,{65152,0,0,0,6352,13625,11104,54066}},
> {netmask,{0,0,0,0,0,0,0,0}},
> {hwaddr,[0,0,0,0,0,0,0,224]}]},
> {"\\DEVICE\\TCPIP_{24F809A3-F9E8-4A77-83AE-3D00133FDC71}",
> [{flags,[up]},{hwaddr,[0,0,0,0,0,0,0,224]}]}]}
>
> Plugging those somewhat ridiculous names into inet:ifget/0 still gives
> einval but at least I can extract the broadaddr from the above structure.
See the documentation for inet:getifaddrs/0 and notice that it is
actually documented, while inet:ifget/0,1 is not. The latter and
its associate inet:getiflist/0 are legacy functions that front
Unixish IOCtls. These have been abandoned by the Unixish
communities in favour of getifaddrs()-like interfaces where
you get all info in one call and they are the way to get IPv6 info.
On Windows, OS version specific interfaces are used to mimic getifaddrs(),
so you get a bit different info on e.g Windows XP; you seem to be
running Vista or 7 with all that IPv6 info.
To make Erlang's legacy function work better was to complicated
and would mean having to call a getifaddrs()-like function and
filter out the item asked for for every call, so they are left
as they are and used internally by inet:getifaddrs/0 as a fallback.
inet:getifaddrs/0 is the only reliable and reasonably portable
function to use for network interface information retrieval,
and not very hard to parse.
>
> Bob
>
> On 01/03/2011 19:46, Bob Cowdery wrote:
> > I'm trying to get hold of the broadcast address on a Windows box but
> > inet:ifget() just returns einval. Anyone know of a way to do this.
> >
> > Thanks
> > Bob
> >
> > ________________________________________________________________
> > erlang-questions (at) erlang.org mailing list.
> > See http://www.erlang.org/faq.html
> > To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
> >
>
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
--
/ Raimo Niskanen, Erlang/OTP, Ericsson AB
More information about the erlang-questions
mailing list