Skip to Content.
Sympa Menu

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

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "James K. Lowden" <james.k.lowden AT icloud.com>
  • To: freetds AT lists.ibiblio.org
  • Subject: Re: [freetds] Looking up hostname from IP address and connection problem MS SQL Server from php
  • Date: Sun, 01 Mar 2015 17:25:12 -0500

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

> Server is "192.168.1.32"
> looking up hostname for ip address 192.168.1.32
> osql: warning: no DNS hostname found for "192.168.1.32"
> Usage: host [-aCdlriTwv] [-c class] [-N ndots] [-t type] [-W time]
> [-R number] [-m flag] hostname [server]
[etc.]
> -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]*//')" ]
then
ADDRESS=${HOST}
echo 'looking up hostname for ip address' ${ADDRESS}
HOST=$(host ${HOST} | awk '/domain/ {print $5}' | sed 's/\.$//')
if [ -z "${HOST}" ]
then
echo "$(basename $0): warning: \
no DNS hostname found for \"${ADDRESS}\""
HOST=${ADDRESS} # restore host address string
fi
fi

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 "192.168.1.32"

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
wrong.

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....

--jkl




Archive powered by MHonArc 2.6.24.

Top of Page