[freetds] Looking up hostname from IP address and connection problem MS SQL Server from php

James K. Lowden james.k.lowden at icloud.com
Sun Mar 1 17:25:12 EST 2015

On Fri, 27 Feb 2015 15:14:52 +0100
Marc-André Legrand <legrandmarc20 at hotmail.com> wrote:

> Server is ""
> looking up hostname for ip address
> osql: warning: no DNS hostname found for ""
> Usage: host [-aCdlriTwv] [-c class] [-N ndots] [-t type] [-W time]
>             [-R number] [-m flag] hostname [server]
>        -m set memory debugging flag (trace|record|usage)
> osql: no IP address found for ""

There is an odd error in osql that I don't see.  I would run it as

	$ sh -x $(which osql) -S MyMSSQLServerName -U user -P password

to watch for the last assignment to the HOST variable.  The relevant
lines start at line 340:

if [ "${HOST}" = "$(echo ${HOST} | sed 's/[^.0-9]*//')" ]
	echo 'looking up hostname for ip address' ${ADDRESS}
	HOST=$(host ${HOST} | awk '/domain/ {print $5}' | sed 's/\.$//')
	if [ -z "${HOST}" ]
		echo "$(basename $0): warning: \
			no DNS hostname found for \"${ADDRESS}\"" 
		HOST=${ADDRESS}	# restore host address string

In English:

	if host is all numeric characters
		addr = host # save name
		look for hostname of address with host->awk->sed
		if no hostname found (host is "")
			issue message
			host = addr # restore name

I don't see how that can fail.  Logically, it seems that 

		if [ -z "${HOST}" ]

evaluates to False even though HOST is in fact a zero-length string.
We know it's numeric going in because we see the message 

	osql: warning: no DNS hostname found for ""

and zero-length coming out because we see

	osql: no IP address found for ""

Running the script with the -x option should reveal where it goes

BTW, this test might be improved: 

	[ "${HOST}" = "$(echo ${HOST} | sed 's/[^.0-9]*//')" ]

written as 

	[ ${HOST} -a -z ${HOST%%[.0-9]*} ]

The first version tests if HOST is the same after non-digits (and '.')
are removed.  The second tests if HOST comprises only digits and '.'.  

The things you learn....


More information about the FreeTDS mailing list