Quick Unix question: How do I find out what the IP address for eth0/eth1 is? I thought NetNameResolver>>localHostAddress was supposed to return this but it returns consistently 127.0.0.1 which is fine from a purity point of view but utterly useless from any practical perspective ;-) Is there any way of finding out the IP address for eth0 that doesn't involve OS process, sed, and grep? Thanks, - Andreas |
On 26-Aug-09, at 11:50 AM, Andreas Raab wrote: > NetNameResolver Well if you have the ipv6 new socket aware VM plus smalltalk code and aren't running as useOldNetwork then the network api deep down uses the class SocketAddressInformation and returns an order collection of which the first entry is choosen as a *best* guess. an OrderedCollection( fe80::21c:42ff:fe00:8%en4(Otter-2), 0(0)-inet6-stream-tcp fe80::21c:42ff:fe00:9%en4(fe80::21c: 42ff:fe00:9%en4), 0(0)-inet6-stream-tcp fe80::21b:63ff:fe02:d2db%en4(fe80::21b: 63ff:fe02:d2db%en4), 0(0)-inet6-stream-tcp 10.211.55.2(10.211.55.2), 0(0)-inet4-stream-tcp 10.37.129.2(10.37.129.2), 0(0)-inet4-stream-tcp 192.168.1.139(192.168.1.139), 0(0)-inet4-stream-tcp) Obviously you want to look deeper than *best guess* The code appears to call getnameinfo() But appears to be broken (I think) since en4: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500 inet6 fe80::21c:42ff:fe00:8%en4 prefixlen 64 scopeid 0x8 inet 10.211.55.2 netmask 0xffffff00 broadcast 10.211.55.255 ether 00:1c:42:00:00:08 media: autoselect status: active supported media: autoselect but I have a line 0(0)-inet6-stream-tcp 10.211.55.2(10.211.55.2), saying inet6 yet the inet6 address is fe80::21c:42ff:fe00:8%en4 Unhelpfully the code doesn't return the interface id (in this case en4) for IPV4 addresses. Maybe Ian could fix the bug above if it's a bug, and add the interface data for ipv4, well or interface data for ipv4 & 6 if a seperate field is needed. Also I think the results above don't relate much to the actual ifconfig -a See http://bugs.squeak.org/view.php?id=7392 -- = = = ======================================================================== John M. McIntosh <[hidden email]> Twitter: squeaker68882 Corporate Smalltalk Consulting Ltd. http://www.smalltalkconsulting.com = = = ======================================================================== |
In reply to this post by Andreas.Raab
Grrr commas in data and in printing the order collection screw the interpretation an OrderedCollection(fe80::21c:42ff:fe00:8%en4(Otter-2),0(0)-inet6- stream-tcp fe80::21c:42ff:fe00:9%en4(fe80::21c:42ff:fe00:9%en4),0(0)- inet6-stream-tcp fe80::21b:63ff:fe02:d2db%en4(fe80::21b:63ff:fe02:d2db %en4),0(0)-inet6-stream-tcp 10.211.55.2(10.211.55.2),0(0)-inet4-stream- tcp 10.37.129.2(10.37.129.2),0(0)-inet4-stream-tcp 192.168.1.139(192.168.1.139),0(0)-inet4-stream-tcp) is really fe80::21c:42ff:fe00:8%en4(Otter-2),0(0)-inet6-stream-tcp 10.211.55.2(10.211.55.2),0(0)-inet4-stream-tcp fe80::21b:63ff:fe02:d2db%en4(fe80::21b:63ff:fe02:d2db%en4),0(0)-inet6- stream-tcp 10.211.55.2(10.211.55.2),0(0)-inet4-stream-tcp 10.37.129.2(10.37.129.2),0(0)-inet4-stream-tcp 192.168.1.139(192.168.1.139),0(0)-inet4-stream-tcp Still fe80::21b:63ff:fe02:d2db%en4(fe80::21b:63ff:fe02:d2db%en4),0(0)-inet6- stream-tcp is hung off en1 not en4 and shows in ifconfig as fe80::21b: 63ff:fe02:d2db%en1 On 26-Aug-09, at 11:50 AM, Andreas Raab wrote: > Quick Unix question: How do I find out what the IP address for eth0/ > eth1 is? I thought NetNameResolver>>localHostAddress was supposed to > return this but it returns consistently 127.0.0.1 which is fine from > a purity point of view but utterly useless from any practical > perspective ;-) > > Is there any way of finding out the IP address for eth0 that doesn't > involve OS process, sed, and grep? > > Thanks, > - Andreas > -- = = = ======================================================================== John M. McIntosh <[hidden email]> Twitter: squeaker68882 Corporate Smalltalk Consulting Ltd. http://www.smalltalkconsulting.com = = = ======================================================================== |
In reply to this post by Andreas.Raab
On 26-Aug-09, at 11:50 AM, Andreas Raab wrote: > NetNameResolver>>localHostAddress was supposed to return this but it > returns consistently 127.0.0.1 which is fine from a purity point of > view but utterly useless from any practical perspective ;-) PS lucky you because the best guess code here gives NetNameResolver>>localHostAddress fe80::21c:42ff:fe00:8%en4(Otter-2),0(0) expecting an IPV4 address? Tsk... -- = = = ======================================================================== John M. McIntosh <[hidden email]> Twitter: squeaker68882 Corporate Smalltalk Consulting Ltd. http://www.smalltalkconsulting.com = = = ======================================================================== |
In reply to this post by Andreas.Raab
2009/8/26 Andreas Raab <[hidden email]>: > > Quick Unix question: How do I find out what the IP address for eth0/eth1 is? > I thought NetNameResolver>>localHostAddress was supposed to return this but > it returns consistently 127.0.0.1 which is fine from a purity point of view > but utterly useless from any practical perspective ;-) I reported exactly this a while ago and was told that the problem is with me and not the code. Then I suggested that the code would be changed to directly return 127.0.0.1. That would achieve the same result more efficiently. Somehow that never got implemented though. Cheers Philipe |
Philippe Marschall wrote: > 2009/8/26 Andreas Raab <[hidden email]>: >> Quick Unix question: How do I find out what the IP address for eth0/eth1 is? >> I thought NetNameResolver>>localHostAddress was supposed to return this but >> it returns consistently 127.0.0.1 which is fine from a purity point of view >> but utterly useless from any practical perspective ;-) > > I reported exactly this a while ago and was told that the problem is > with me and not the code. What was the argument? I'm not trying to find out how a client is ultimately connecting to the host - I'm trying to make a "best guess" for a zero configuration environment (concretely: a VMware image with a single network interface running in a bridged environment). The only thing that I know for sure is that 127.0.0.1 won't work because clients won't connect from localhost. Cheers, - Andreas > Then I suggested that the code would be > changed to directly return 127.0.0.1. That would achieve the same > result more efficiently. Somehow that never got implemented though. > > Cheers > Philipe > |
In reply to this post by Philippe Marschall
On 26.08.2009, at 22:05, Philippe Marschall wrote: > > 2009/8/26 Andreas Raab <[hidden email]>: >> >> Quick Unix question: How do I find out what the IP address for eth0/ >> eth1 is? >> I thought NetNameResolver>>localHostAddress was supposed to return >> this but >> it returns consistently 127.0.0.1 which is fine from a purity point >> of view >> but utterly useless from any practical perspective ;-) > > I reported exactly this a while ago and was told that the problem is > with me and not the code. Then I suggested that the code would be > changed to directly return 127.0.0.1. That would achieve the same > result more efficiently. Somehow that never got implemented though. What got implemented though is a primitive to list all interfaces that are available. Hosts do not have IP addresses, interfaces do. And since hosts typically have multiple interfaces, it's not really up to the VM to pick one, but the application. - Bert - |
Bert Freudenberg wrote: > What got implemented though is a primitive to list all interfaces that > are available. Hosts do not have IP addresses, interfaces do. And since > hosts typically have multiple interfaces, it's not really up to the VM > to pick one, but the application. What's the primitive? How do I use it? Any examples? Thanks, - Andreas |
On 26.08.2009, at 22:27, Andreas Raab wrote: > Bert Freudenberg wrote: >> What got implemented though is a primitive to list all interfaces >> that are available. Hosts do not have IP addresses, interfaces do. >> And since hosts typically have multiple interfaces, it's not really >> up to the VM to pick one, but the application. > > What's the primitive? How do I use it? Any examples? There are examples and tests in the image ... it's part of the IPv6 work, which did not only add IPv6 support but generalized the Socket support. Not sure exactly which method it would be. - Bert - |
In reply to this post by Andreas.Raab
NetNameResolver addressesForName: self localHostName but that gives back a list of three address like 10.37.129.2(10.37.129.2),0(0)-inet4-stream-tcp but lacking is information about WHICH one is actually usable, the 192.168.1.139 is the correct one for my office subnet but 10.211.55.2, and 10.37.129.2 have been setup by Parallels for os- x, If I pick 10.211.55.2, or 10.37.129 then things just won't work since computer B elsewhere in the office doesn't see the 10.*.*.* addresses. Obviously the data coming back has to be a bit more helpful to let the smalltalk code pick the right answer. ifconfig shows en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 inet6 fe80::21b:63ff:fe02:d2db%en1 prefixlen 64 scopeid 0x6 inet 192.168.1.139 netmask 0xffffff00 broadcast 192.168.1.255 ether 00:1b:63:02:d2:db media: autoselect status: active supported media: autoselect en4: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500 inet6 fe80::21c:42ff:fe00:8%en4 prefixlen 64 scopeid 0x8 inet 10.211.55.2 netmask 0xffffff00 broadcast 10.211.55.255 ether 00:1c:42:00:00:08 media: autoselect status: active supported media: autoselect en5: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500 inet6 fe80::21c:42ff:fe00:9%en5 prefixlen 64 scopeid 0x9 inet 10.37.129.2 netmask 0xffffff00 broadcast 10.37.129.255 ether 00:1c:42:00:00:09 media: autoselect status: active supported media: autoselect On 26-Aug-09, at 1:27 PM, Andreas Raab wrote: > Bert Freudenberg wrote: >> What got implemented though is a primitive to list all interfaces >> that are available. Hosts do not have IP addresses, interfaces do. >> And since hosts typically have multiple interfaces, it's not really >> up to the VM to pick one, but the application. > > What's the primitive? How do I use it? Any examples? > > Thanks, > - Andreas -- = = = ======================================================================== John M. McIntosh <[hidden email]> Twitter: squeaker68882 Corporate Smalltalk Consulting Ltd. http://www.smalltalkconsulting.com = = = ======================================================================== |
In reply to this post by Bert Freudenberg
Bert Freudenberg wrote: > On 26.08.2009, at 22:27, Andreas Raab wrote: >> Bert Freudenberg wrote: >>> What got implemented though is a primitive to list all interfaces >>> that are available. Hosts do not have IP addresses, interfaces do. >>> And since hosts typically have multiple interfaces, it's not really >>> up to the VM to pick one, but the application. >> >> What's the primitive? How do I use it? Any examples? > > There are examples and tests in the image ... it's part of the IPv6 > work, which did not only add IPv6 support but generalized the Socket > support. Not sure exactly which method it would be. Bummer. I thought you were saying that there was "one" primitive that would do it, not two dozen ;-) Unfortunately, adding the whole IPv6 stuff is not an option at this point; we're too close to release for that. I think I'll go through the code and try to see how to fold this into an isolated function - does it work in the OLPC image? Cheers, - Andreas |
In reply to this post by johnmci
John M McIntosh wrote: > NetNameResolver addressesForName: self localHostName This doesn't work at all for me. In fact it's not even asking the right question ;-) Using the 3.10-6 VM with an Etoys-dev image I get this: NetNameResolver localHostName => 'localhost.localdomain' NetNameResolver addressesForName: NetNameResolver localHostName => 127.0.0.1(localhost),0(0)-inet4-stream-tcp I'm not surprised with the result because you are asking DNS to resolve localhost.localdomain which is different from asking the question of what IP addresses are assigned to the various interfaces in your system. I thought Bert said that there is a way to enumerate the IP addresses of the interfaces? Cheers, - Andreas |
On 26.08.2009, at 23:57, Andreas Raab wrote: > John M McIntosh wrote: >> NetNameResolver addressesForName: self localHostName > > This doesn't work at all for me. In fact it's not even asking the > right question ;-) Using the 3.10-6 VM with an Etoys-dev image I get > this: > > NetNameResolver localHostName > => 'localhost.localdomain' > > NetNameResolver addressesForName: NetNameResolver localHostName > => 127.0.0.1(localhost),0(0)-inet4-stream-tcp > > I'm not surprised with the result because you are asking DNS to > resolve localhost.localdomain which is different from asking the > question of what IP addresses are assigned to the various interfaces > in your system. > > I thought Bert said that there is a way to enumerate the IP > addresses of the interfaces? I thought it did, but I never had to use it yet ... grmph, I'm sure there is a way. Ian? - Bert - |
In reply to this post by Andreas.Raab
On Wed, Aug 26, 2009 at 11:50:12AM -0700, Andreas Raab wrote: > > Is there any way of finding out the IP address for eth0 that doesn't > involve OS process, sed, and grep? Assuming that you're not looking for an elegant solution, you could figure it out in the start script and pass it to Squeak as a command line parameter. #!/bin/sh INTERFACE=eth0 IPV4_ADDR=`/sbin/ifconfig $INTERFACE | grep 'inet addr' | cut -c21-34` echo the IP address on interface $INTERFACE is $IPV4_ADDR /usr/local/bin/squeak myimage.image $IPV4_ADDR Dave |
David T. Lewis wrote: > Assuming that you're not looking for an elegant solution, you could > figure it out in the start script and pass it to Squeak as a command > line parameter. > > #!/bin/sh > INTERFACE=eth0 > IPV4_ADDR=`/sbin/ifconfig $INTERFACE | grep 'inet addr' | cut -c21-34` > echo the IP address on interface $INTERFACE is $IPV4_ADDR > /usr/local/bin/squeak myimage.image $IPV4_ADDR Wow, without sed? I'm impressed ;-) And you know what, that's just what I'll do. Thanks for the snippet. Cheers, - Andreas |
In reply to this post by Andreas.Raab
Sure well NetNameResolver localHostName gives me 'Otter-2.local' then NetNameResolver addressesForName: 'Otter-2.local' gives me back a collection with 6 addresses, but you are saying for your machine you only get back 1 address? Lucky you, but will your production machine give back one address, or 23? I think here the problem is your machine is returning 'localhost.localdomain' Oddly on os-x asking for NetNameResolver addressForName: 'localhost.localdomain' gives you a primitive failure. Also as you saw, my localHostName is 'Otter-2.local' which is the boujour name http://support.apple.com/kb/TA20999?viewlocale=en_US Maybe the question is does your computer have a DNS assigned name? In Pharo Ian's code is below, note how the SocketAddressInformation>>forHost:... iterates to get all the socket info. addressesForName: hostName "NetNameResolver addressesForName: 'impara.de' " | adresses | adresses := SocketAddressInformation forHost: hostName service: '' flags: 0 addressFamily: 0 socketType: SocketAddressInformation socketTypeStream protocol: SocketAddressInformation protocolTCP. ^adresses SocketAddressInformation >>forHost: hostName service: servName flags: flags addressFamily: family socketType: type protocol: protocol | result addr | NetNameResolver initializeNetwork. NetNameResolver primGetAddressInfoHost: hostName service: servName flags: flags family: family type: type protocol: protocol. result := OrderedCollection new. [(addr := NetNameResolver nextSocketAddressInformation) notNil] whileTrue: [result add: addr]. ^result On 26-Aug-09, at 2:57 PM, Andreas Raab wrote: > John M McIntosh wrote: >> NetNameResolver addressesForName: self localHostName > > This doesn't work at all for me. In fact it's not even asking the > right question ;-) Using the 3.10-6 VM with an Etoys-dev image I get > this: > > NetNameResolver localHostName > => 'localhost.localdomain' > > NetNameResolver addressesForName: NetNameResolver localHostName > => 127.0.0.1(localhost),0(0)-inet4-stream-tcp > > I'm not surprised with the result because you are asking DNS to > resolve localhost.localdomain which is different from asking the > question of what IP addresses are assigned to the various interfaces > in your system. > > I thought Bert said that there is a way to enumerate the IP > addresses of the interfaces? > > Cheers, > - Andreas > -- = = = ======================================================================== John M. McIntosh <[hidden email]> Twitter: squeaker68882 Corporate Smalltalk Consulting Ltd. http://www.smalltalkconsulting.com = = = ======================================================================== |
In reply to this post by Andreas.Raab
On 27.08.2009, at 00:15, Andreas Raab wrote: > David T. Lewis wrote: >> Assuming that you're not looking for an elegant solution, you could >> figure it out in the start script and pass it to Squeak as a command >> line parameter. >> #!/bin/sh >> INTERFACE=eth0 >> IPV4_ADDR=`/sbin/ifconfig $INTERFACE | grep 'inet addr' | cut - >> c21-34` >> echo the IP address on interface $INTERFACE is $IPV4_ADDR >> /usr/local/bin/squeak myimage.image $IPV4_ADDR > > Wow, without sed? I'm impressed ;-) And you know what, that's just > what I'll do. Thanks for the snippet. You might want to set LANG=C in the script. Or be surprised when running this on a localized machine. - Bert - |
In reply to this post by Andreas.Raab
Careful, on my macbook pro, the ethernet port is en0, which is rarely used. But en1 is wireless and mostly used so the INTERFACE=eth0 is going to be machine dependent On 26-Aug-09, at 3:15 PM, Andreas Raab wrote: > David T. Lewis wrote: >> Assuming that you're not looking for an elegant solution, you could >> figure it out in the start script and pass it to Squeak as a command >> line parameter. >> #!/bin/sh >> INTERFACE=eth0 >> IPV4_ADDR=`/sbin/ifconfig $INTERFACE | grep 'inet addr' | cut - >> c21-34` >> echo the IP address on interface $INTERFACE is $IPV4_ADDR >> /usr/local/bin/squeak myimage.image $IPV4_ADDR > > Wow, without sed? I'm impressed ;-) And you know what, that's just > what I'll do. Thanks for the snippet. > > Cheers, > - Andreas -- = = = ======================================================================== John M. McIntosh <[hidden email]> Twitter: squeaker68882 Corporate Smalltalk Consulting Ltd. http://www.smalltalkconsulting.com = = = ======================================================================== |
In reply to this post by johnmci
On 27.08.2009, at 00:18, John M McIntosh wrote: > Sure well > > NetNameResolver localHostName > gives me > 'Otter-2.local' > > then > > NetNameResolver addressesForName: 'Otter-2.local' > gives me back a collection with 6 addresses, but you are saying for > your machine you only get back 1 address? Lucky you, but will your > production machine > give back one address, or 23? > > I think here the problem is your machine is returning > 'localhost.localdomain' > Oddly on os-x asking for NetNameResolver addressForName: > 'localhost.localdomain' > gives you a primitive failure. > > Also as you saw, my localHostName is 'Otter-2.local' which is the > boujour name http://support.apple.com/kb/TA20999?viewlocale=en_US > > Maybe the question is does your computer have a DNS assigned name? This machine has two interfaces (see below). NetNameResolver localHostName gives 'fedora10' but NetNameResolver addressesForName: NetNameResolver localHostName still only yields an OrderedCollection(127.0.0.1(fedora10),0(spr-itunes)-inet4-stream- tcp) That does not sound right indeed. - Bert - [bert@fedora10 ~]$ ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:BF:6D:A7 inet addr:172.16.22.154 Bcast:172.16.22.255 Mask: 255.255.255.0 inet6 addr: fe80::20c:29ff:febf:6da7/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:223095 errors:194711 dropped:0 overruns:0 frame:0 TX packets:108938 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:179764576 (171.4 MiB) TX bytes:76413825 (72.8 MiB) Interrupt:19 Base address:0x2024 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:38 errors:0 dropped:0 overruns:0 frame:0 TX packets:38 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:6908 (6.7 KiB) TX bytes:6908 (6.7 KiB) |
In reply to this post by johnmci
Thanks but this is not an issue for us. We're talking about an appliance here, a VMware image that we ship to customers. So by definition LANG=C and eth0 is the default interface. Cheers, - Andreas John M McIntosh wrote: > > Careful, on my macbook pro, the ethernet port is en0, which is rarely used. > But en1 is wireless and mostly used > so the INTERFACE=eth0 is going to be machine dependent > > > On 26-Aug-09, at 3:15 PM, Andreas Raab wrote: > >> David T. Lewis wrote: >>> Assuming that you're not looking for an elegant solution, you could >>> figure it out in the start script and pass it to Squeak as a command >>> line parameter. >>> #!/bin/sh >>> INTERFACE=eth0 >>> IPV4_ADDR=`/sbin/ifconfig $INTERFACE | grep 'inet addr' | cut -c21-34` >>> echo the IP address on interface $INTERFACE is $IPV4_ADDR >>> /usr/local/bin/squeak myimage.image $IPV4_ADDR >> >> Wow, without sed? I'm impressed ;-) And you know what, that's just >> what I'll do. Thanks for the snippet. >> >> Cheers, >> - Andreas > > -- > =========================================================================== > John M. McIntosh <[hidden email]> Twitter: > squeaker68882 > Corporate Smalltalk Consulting Ltd. http://www.smalltalkconsulting.com > =========================================================================== > > > > |
Free forum by Nabble | Edit this page |