[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] How to get the TCP/IP host name



>I think you have your answer by now, but I got a little interested and

Yes, and since the responses were so fast and efficient, I'll go on to the next question in a new thread :-)...

>>>>gethostbyname('localhost'); # OK on Win32, not Linux
>>Used it in array context on Win32, and it gives the full host name in
>>first element. What does it give in array context on a Mac? (On Linux, it
>>just stupidly gives 'localhost.localdomain')
>
>1) Note that what you are calling the "first" element of the array is
>critical.  Element 0 is a hostname on both Mac and Linux.  Element 1 is
>described in the Camel book as $aliases, and gives something different from
>Element 0 under Linux, and nothing on a Mac.

Yes, I meant [0] by "first". I don't get any $aliases either, whether on Win or on Linux, even though I feel I should.

>2) I'm not sure I am convinced what Linux returns is "wrong" vs Mac and
>Windows.  On my Linux box, localhost is an entirely different thing than
>biomedcomp.com.  Note that they correspond to different IP addresses which
>could be connected to different hardware, could offer different services,
>etc.  On a Mac (and I am infering, Windows), localhost is just another name
>for the same IP address.

The Linux answer 'localhost.localdomain' indeed seems to come from the hosts file, as Paul suggested. Windows does not get it from there.

I agree there is no reason to consider it "wrong".

>>>>`hostname` # OK on Linux, not Win32
>>>Works in a Mac.
>>Really? Sounds great. On any Mac (with Perl)? Or just on some Macs which
>>have installed some additional Unix tools or such?
>
>As previously noted on this group, no additional tools required.  However,
>according to "MacPerl: Power and Ease", TCP/IP must be running for this to
>work, but that is certainly reasonable.

Not only reasonable, but definitely "the right thing": if there is no TCP/IP, there should not be a hostname. (Even though there may be a Mac specific computer name like Windows (and Novell?) have their own names unrelated to Internet names)

Changed line 15:

>$a = pack('C4', 206, 109, 105, 70);

to

$a = pack('C4', split(/\./, $a));

and this time, on Win95, got the hostname from the hosts file.

As for aliases, I suppose they also just come from the hosts file.

I would conclude that Perl lives up to it's reputation of "doing the right thing". All these results make sense.

M.

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org