Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!newsfeed.pitt.edu!gatech!newsfeed.internetmci.com!csn!nntp-xfer-1.csn.net!csn!nntp-xfer-2.csn.net!stortek!news
From: Yueming Xu <yxu@bronze.stortek.com>
Subject: Re: (VW 2.5) IP Host Name Resolution
Content-Type: text/plain; charset=gb2312
Message-ID: <31922ECE.4B76@bronze.stortek.com>
Sender: news@stortek.com
Content-Transfer-Encoding: 7bit
Organization: Field Automation
References: <3190DB71.2F94@overlord.com>
Mime-Version: 1.0
Date: Thu, 9 May 1996 17:43:42 GMT
X-Mailer: Mozilla 2.01 (X11; I; SunOS 5.4 sun4m)
Lines: 65

David,

You are absolutely right that it is not necessary to go through
primHostAddressByName: if the name you provided is an ip address.
In fact, what's worse is that the primitive can cause unnecessary 
problems.  When the IPClient runs on Window for Workgroups, opening 
a socket connection to an ip address may cause a win32s system error.
We got around the problem by bypassing this primtive as follows:

!IPSocketAddress class methodsFor: 'naming utilities'!

hostAddressByName: aString
	"Answer the host address for the named host."

	| address |
	aString = '-thishost-' ifTrue: [^self thisHost].
	address := (aString at: 1) isDigit 
		ifFalse: [ self primHostAddressByName: (IOAccessor
convertSimpleStringForPlatform: aString) ]
		ifTrue: [ self stringToBytes: aString ].
	^address isNil 
		ifTrue: [OSErrorHolder inaccessibleSignal raiseWith:aString]
		ifFalse: [address]! !

It is assumed in the above method that no host name starts with a digit.
You may want to make it more robust.

Yueming
StorageTek
Louiseville, CO



David Coe wrote:
> 
> I'm asking this here because I'm not fluent in TCP/IP talk, and can give the
> example directly in (VW 2.5) Smalltalk.  If you know of a better place to get
> the answer, please refer me...
> 
> VW's SocketAccessor newTCPclientToHost:port: accepts a string containing either
> a host name or "canonical" host number, e.g. either 'somewhere.overlord.com'
> or '204.192.118.22' to identify the host.
> 
> It uses IPSocketAddress>>hostAddressByName: to find the four-byte IP address
> that corresponds to the text in that string.  The meat of that method does:
> 
>         address := self primHostAddressByName:
>                 (IOAccessor convertSimpleStringForPlatform: aString).
>         address isNil ifTrue: [address := self stringToBytes: aString].
> 
> which apparently passes the string through the local host's name
> resolver (which may also access a DNS server), and then if it hasn't been
> resolved (primHostAddressByName: answered nil), attempts to interpret
> it as a canonical number.
> 
> I think I'd like to do it the other way around, i.e. if the user wants to
> access host '204.192.118.22', or any string that represents a valid 4-byte
> canonical address, don't bothher with the attempted name resolution first.
> 
> Is there a good reason it tries to look it up as a name first?
> 
> --
> David Coe         mailto:dcoe@overlord.com  http://www.overlord.com/~dcoe
> Overlord, Inc.    mailto:info@overlord.com  http://www.overlord.com
> R & D and Support +1-410-489-9521, fax +1-410-489-9512
