pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Re: [INTERFACES] Win32 interface
12+ messages / 6 participants
[nested] [flat]

* Re: [INTERFACES] Win32 interface
@ 1999-09-02 20:42  Ken J. Wright <ken@ori-ind.com>
  0 siblings, 1 reply; 12+ messages in thread

From: Ken J. Wright @ 1999-09-02 20:42 UTC (permalink / raw)
  To: David Giffin <david@agent911.com>; pgsql-interfaces

At 14:02 09/02/1999 -0700, David Giffin wrote:
>
>I'm trying to use the postgresql win32 interface to connect ot a UNIX
>host. I'm using PQconnectDB() to get the connection. Each time I try to
>connect it says unknown host name:
>
>connectDB() --  unknown hostname: mobile
>
>reguardless of specifying the ip address or the complete host name. Any
>ideas??

are you using the proper parameter string? 
PQconnectDB('host=hostname dbname=databasename user=username')

Otherwise maybe send code snippet to look at?

Ken




^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: [INTERFACES] Win32 interface
@ 1999-09-02 21:02  David Giffin <david@agent911.com>
  1 sibling, 0 replies; 12+ messages in thread

From: David Giffin @ 1999-09-02 21:02 UTC (permalink / raw)
  To: pgsql-interfaces


I'm trying to use the postgresql win32 interface to connect ot a UNIX
host. I'm using PQconnectDB() to get the connection. Each time I try to
connect it says unknown host name:

connectDB() --  unknown hostname: mobile

reguardless of specifying the ip address or the complete host name. Any
ideas??

David






^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: [INTERFACES] Win32 interface
@ 1999-09-02 21:57  David Giffin <david@agent911.com>
  parent: Ken J. Wright <ken@ori-ind.com>
  0 siblings, 1 reply; 12+ messages in thread

From: David Giffin @ 1999-09-02 21:57 UTC (permalink / raw)
  To: Ken J. Wright <ken@ori-ind.com>; +Cc: pgsql-interfaces



Yep I'm using the PQconnectDB("host=blah user=blah dbname=blah");

I noticed that psql.c uses the PQsetdbLogin maybe I should switch to that
function if this one is broken? Would have to parse a little extra but..

Here is the snippet... my char *dbname comes in the form of:
 host=hostname;dbname=database;port=portnum


int
pg_login(struct dbi *dbi, char *dbname, char *user, char *pass)
{
	char *connect;
	char *source;
	char *dest;
	char *src;
	int mem;
	int sourcelen;
	mem    = strlen(dbname);
	source = malloc(mem + 10);
	if (user && pass) {
		mem += strlen(user) + strlen(pass);
	} else if (user) {
		mem += strlen(user);
	}
	src =	dbname;
	dest = source;  
	while (*src) {
		if (*src != ';') {
			*dest++ = *src++;
			continue;		
		}
		*dest++ = ' ';
		src++;
	}
  	*dest = '\0';
  	if (LOG_LEVEL >= 3) {
		fprintf(stderr,"pg_login: source -> %s\n",source);
	}
	sourcelen = strlen(source); 
	if (user && pass) {
		connect = malloc(sourcelen+strlen(user)+strlen(pass)+13);
		sprintf(connect,"%s user=%s pass=%s",source, user, pass);
	} else if (user) {
		connect = malloc(sourcelen+strlen(user) + 7);
		sprintf(connect,"%s user=%s",source, user);
	} else {
	connect = malloc(sourcelen + 1);
	sprintf(connect,"%s",source);	}
  	if (LOG_LEVEL >= 2) {
		fprintf(stderr,"pg_login: %s\n",connect);
	}
	dbi->conn = PQconnectdb(connect);
<SNIP>


On Thu, 2 Sep 1999, Ken J. Wright wrote:

> At 14:02 09/02/1999 -0700, David Giffin wrote:
> >
> >I'm trying to use the postgresql win32 interface to connect ot a UNIX
> >host. I'm using PQconnectDB() to get the connection. Each time I try to
> >connect it says unknown host name:
> >
> >connectDB() --  unknown hostname: mobile
> >
> >reguardless of specifying the ip address or the complete host name. Any
> >ideas??
> 
> are you using the proper parameter string? 
> PQconnectDB('host=hostname dbname=databasename user=username')
> 
> Otherwise maybe send code snippet to look at?
> 
> Ken
> 




^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: [INTERFACES] Win32 interface
@ 1999-09-03 14:40  Tom Lane <tgl@sss.pgh.pa.us>
  parent: David Giffin <david@agent911.com>
  0 siblings, 1 reply; 12+ messages in thread

From: Tom Lane @ 1999-09-03 14:40 UTC (permalink / raw)
  To: David Giffin <david@agent911.com>; +Cc: Ken J. Wright <ken@ori-ind.com>; pgsql-interfaces

David Giffin <david@agent911.com> writes:
> Yep I'm using the PQconnectDB("host=blah user=blah dbname=blah");
> I noticed that psql.c uses the PQsetdbLogin maybe I should switch to that
> function if this one is broken? Would have to parse a little extra but..
>>>> 
>>>> connectDB() --  unknown hostname: mobile

Assuming that "mobile" is the hostname you gave it, then parsing the
connectinfo string is not the problem.

The error message is coming out because gethostbyname() is failing ---
cf. connectDB() in interfaces/libpq/fe-connect.c.  (Or, perchance,
it is succeeding but delivering a non-INET address?  Seems unlikely
but if your LAN runs on non-TCP protocols then that's possible.)

My guess is that there is something broken with DNS name resolution
on your setup.  Hard to tell what from this much info.  You might
try making a one-liner program that just calls gethostbyname, and
work on debugging that simpler situation.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: [INTERFACES] Win32 interface
@ 1999-09-03 20:26  David Giffin <david@agent911.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 12+ messages in thread

From: David Giffin @ 1999-09-03 20:26 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Ken J. Wright <ken@ori-ind.com>; pgsql-interfaces


I figured out what was happening... Or at least what seem to happen. When
I linked in lipq.lib it would return unknown hostname. I switched it to
the libpqdll.lib and it worked fine.

I thought that libpq.lib would statically complie postgres into the .exe
but it didn't seem to work.

David

On Fri, 3 Sep 1999, Tom Lane wrote:

> David Giffin <david@agent911.com> writes:
> > Yep I'm using the PQconnectDB("host=blah user=blah dbname=blah");
> > I noticed that psql.c uses the PQsetdbLogin maybe I should switch to that
> > function if this one is broken? Would have to parse a little extra but..
> >>>> 
> >>>> connectDB() --  unknown hostname: mobile
> 
> Assuming that "mobile" is the hostname you gave it, then parsing the
> connectinfo string is not the problem.
> 
> The error message is coming out because gethostbyname() is failing ---
> cf. connectDB() in interfaces/libpq/fe-connect.c.  (Or, perchance,
> it is succeeding but delivering a non-INET address?  Seems unlikely
> but if your LAN runs on non-TCP protocols then that's possible.)
> 
> My guess is that there is something broken with DNS name resolution
> on your setup.  Hard to tell what from this much info.  You might
> try making a one-liner program that just calls gethostbyname, and
> work on debugging that simpler situation.
> 
> 			regards, tom lane
> 




^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* RE: [INTERFACES] Win32 interface
@ 1999-09-04 13:51  Magnus Hagander <mha@sollentuna.net>
  0 siblings, 1 reply; 12+ messages in thread

From: Magnus Hagander @ 1999-09-04 13:51 UTC (permalink / raw)
  To: 'David Giffin' <david@agent911.com>; Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Ken J. Wright <ken@ori-ind.com>; pgsql-interfaces

It does just that.

The problem is that in the DllMain() of the libpq.dll file, WSAStartup() is
called, and that is required before any winsock functions will work.
If you link statically, you have to manually run WSAStartup.

This should probably be documented :-)

//Magnus

On Friday, September 03, 1999 10:27 PM, David Giffin
[SMTP:david@agent911.com] wrote:
> 
> I figured out what was happening... Or at least what seem to happen. When
> I linked in lipq.lib it would return unknown hostname. I switched it to
> the libpqdll.lib and it worked fine.
> 
> I thought that libpq.lib would statically complie postgres into the .exe
> but it didn't seem to work.
> 
> David
> 
> On Fri, 3 Sep 1999, Tom Lane wrote:
> 
> > David Giffin <david@agent911.com> writes:
> > > Yep I'm using the PQconnectDB("host=blah user=blah dbname=blah");
> > > I noticed that psql.c uses the PQsetdbLogin maybe I should switch to
that
> > > function if this one is broken? Would have to parse a little extra
but..
> > >>>> 
> > >>>> connectDB() --  unknown hostname: mobile
> > 
> > Assuming that "mobile" is the hostname you gave it, then parsing the
> > connectinfo string is not the problem.
> > 
> > The error message is coming out because gethostbyname() is failing ---
> > cf. connectDB() in interfaces/libpq/fe-connect.c.  (Or, perchance,
> > it is succeeding but delivering a non-INET address?  Seems unlikely
> > but if your LAN runs on non-TCP protocols then that's possible.)
> > 
> > My guess is that there is something broken with DNS name resolution
> > on your setup.  Hard to tell what from this much info.  You might
> > try making a one-liner program that just calls gethostbyname, and
> > work on debugging that simpler situation.
> > 
> > 			regards, tom lane
> > 
> 
> 
> ************



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: [INTERFACES] Win32 interface
@ 1999-09-04 15:20  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Magnus Hagander <mha@sollentuna.net>
  0 siblings, 1 reply; 12+ messages in thread

From: Tom Lane @ 1999-09-04 15:20 UTC (permalink / raw)
  To: Magnus Hagander <mha@sollentuna.net>; +Cc: 'David Giffin' <david@agent911.com>; Ken J. Wright <ken@ori-ind.com>; pgsql-interfaces

Magnus Hagander <mha@sollentuna.net> writes:
> The problem is that in the DllMain() of the libpq.dll file, WSAStartup() is
> called, and that is required before any winsock functions will work.
> If you link statically, you have to manually run WSAStartup.
>
> This should probably be documented :-)

Didn't we talk about having fe-connect.c call WSAStartup()
(conditionally compiled of course) to avoid this problem?

ISTM there was some reason it wouldn't work, like maybe you can
only call WSAStartup once per program, but I don't recall for sure.
If it *would* work it would probably be a better answer than making
users remember to call the thing.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: [INTERFACES] Win32 interface
@ 1999-09-04 17:05  Robert Hiltibidal <rob@y2k.state.il.us>
  1 sibling, 0 replies; 12+ messages in thread

From: Robert Hiltibidal @ 1999-09-04 17:05 UTC (permalink / raw)
  To: David Giffin <david@agent911.com>; pgsql-interfaces

Howdy,

Have you looked at the lmhosts file?

We have a situation on our network where the internal boxes are all
assigned non routing ip's, so if we want to enable a win9x or winnt box to
connect to those other ips we have to create an lmhost entry for them. 

For NT:
Look in your c:/winnt/system32/drivers/etc directory. There you will find a
host and lmhost file. If they end in .sam remove the extension once you
have made the alteration.

This is what my NT lmhosts file looks like:
10.2.6.13	y2k		#PRE	#DOM:Y2K

You may have a template that has *ALL* the configuration stuff. For
Postgres you only need 1 line.

I reccommend putting the #PRE directive in. The NT box handled it just fine
without it, but thw win9x boxes would not see it unless the #PRE directive
was there.

You only need the one line for win9x boxes. For Win9x we put the lmhosts
file in c:\windows\lmhosts. Again, if the sam extension is there remove it. 

Once you make the change to the lmhosts file in both WinNT and Win9x you
will have to reboot the computer.

Once there test for resolution by typing "ping <host>" in a dosshell prompt. 

One other intersting thing is in either WinNT or Win9x you can have a hosts
file, but our experience has been the smb networking will not work. We had
to make lmhosts file entries.

A bit long winded but I hope this helps.

-Rob
 

At 02:02 PM 09/02/1999 -0700, David Giffin wrote:
>
>I'm trying to use the postgresql win32 interface to connect ot a UNIX
>host. I'm using PQconnectDB() to get the connection. Each time I try to
>connect it says unknown host name:
>
>connectDB() --  unknown hostname: mobile
>
>reguardless of specifying the ip address or the complete host name. Any
>ideas??
>
>David
>
>
>
>
>************
>
>




^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* RE: [INTERFACES] Win32 interface
@ 1999-09-06 04:37  Hiroshi Inoue <Inoue@tpf.co.jp>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 12+ messages in thread

From: Hiroshi Inoue @ 1999-09-06 04:37 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; Magnus Hagander <mha@sollentuna.net>; +Cc: 'David Giffin' <david@agent911.com>; Ken J. Wright <ken@ori-ind.com>; pgsql-interfaces


> -----Original Message-----
> From: owner-pgsql-interfaces@postgreSQL.org
> [mailto:owner-pgsql-interfaces@postgreSQL.org]On Behalf Of Tom Lane
> Sent: Sunday, September 05, 1999 12:21 AM
> To: Magnus Hagander
> Cc: 'David Giffin'; Ken J. Wright; pgsql-interfaces@postgreSQL.org
> Subject: Re: [INTERFACES] Win32 interface 
> 
> 
> Magnus Hagander <mha@sollentuna.net> writes:
> > The problem is that in the DllMain() of the libpq.dll file, 
> WSAStartup() is
> > called, and that is required before any winsock functions will work.
> > If you link statically, you have to manually run WSAStartup.
> >
> > This should probably be documented :-)
> 
> Didn't we talk about having fe-connect.c call WSAStartup()
> (conditionally compiled of course) to avoid this problem?
>

Sorry,I forgot to take static link cases into account when I proposed
to call WSAStartup() in DllMain().
 
> ISTM there was some reason it wouldn't work, like maybe you can
> only call WSAStartup once per program, but I don't recall for sure.

We can call WSAStartup() more than once. However,there must be a
call to WSACleanup() for every successful call to WSAStartup()
made by a task. Only the final WSACleanup() for that task does the
actual cleanup.
.
The simplest way may be to call WSAStartup() while connecting and 
to call WSACleanup() while finishing(including error cases).

Regards.

Hiroshi Inoue
Inoue@tpf.co.jp



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: [INTERFACES] Win32 interface
@ 1999-09-06 14:54  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Hiroshi Inoue <Inoue@tpf.co.jp>
  0 siblings, 0 replies; 12+ messages in thread

From: Tom Lane @ 1999-09-06 14:54 UTC (permalink / raw)
  To: Hiroshi Inoue <Inoue@tpf.co.jp>; +Cc: Magnus Hagander <mha@sollentuna.net>; 'David Giffin' <david@agent911.com>; Ken J. Wright <ken@ori-ind.com>; pgsql-interfaces

"Hiroshi Inoue" <Inoue@tpf.co.jp> writes:
>> ISTM there was some reason it wouldn't work, like maybe you can
>> only call WSAStartup once per program, but I don't recall for sure.

> We can call WSAStartup() more than once. However,there must be a
> call to WSACleanup() for every successful call to WSAStartup()
> made by a task. Only the final WSACleanup() for that task does the
> actual cleanup.
>
> The simplest way may be to call WSAStartup() while connecting and 
> to call WSACleanup() while finishing(including error cases).

That would be an easy change.  Are these functions fast enough that
calling them for every connect/disconnect cycle would be tolerable?

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* RE: [INTERFACES] Win32 interface
@ 1999-09-06 15:01  Magnus Hagander <mha@sollentuna.net>
  0 siblings, 1 reply; 12+ messages in thread

From: Magnus Hagander @ 1999-09-06 15:01 UTC (permalink / raw)
  To: 'Tom Lane' <tgl@sss.pgh.pa.us>; Hiroshi Inoue <Inoue@tpf.co.jp>; +Cc: 'David Giffin' <david@agent911.com>; Ken J. Wright <ken@ori-ind.com>; pgsql-interfaces

> >> ISTM there was some reason it wouldn't work, like maybe you can
> >> only call WSAStartup once per program, but I don't recall for sure.
> 
> > We can call WSAStartup() more than once. However,there must be a
> > call to WSACleanup() for every successful call to WSAStartup()
> > made by a task. Only the final WSACleanup() for that task does the
> > actual cleanup.
> >
> > The simplest way may be to call WSAStartup() while connecting and 
> > to call WSACleanup() while finishing(including error cases).
> 
> That would be an easy change.  Are these functions fast enough that
> calling them for every connect/disconnect cycle would be tolerable?

I beleive so. But we could probably get away from that using static
variables, no? Somewhere just put:

static int has_wsastartup = 0;

...

if (!has_wsastartup) {
   has_wsastartup = 1;
   WSAStartup()...
}


That way, it would only be run once, right? 
Naturally, everything within #ifdef WIN32.


One could also check the result code from the first winsock call. If that
one is 'Winsock not initialized', then initialize it and try again. This
would get us around the case of the client application calling WSAStartup()
on its own. But that is probably not necessary - that applcation will call
WSACleanup itself, and an app is allowed to call WSAStartup() more than
once.

Mvh,
 Magnus



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* RE: [INTERFACES] Win32 interface
@ 1999-09-07 08:15  Hiroshi Inoue <Inoue@tpf.co.jp>
  parent: Magnus Hagander <mha@sollentuna.net>
  0 siblings, 0 replies; 12+ messages in thread

From: Hiroshi Inoue @ 1999-09-07 08:15 UTC (permalink / raw)
  To: Magnus Hagander <mha@sollentuna.net>; 'Tom Lane' <tgl@sss.pgh.pa.us>; +Cc: pgsql-interfaces

> 
> > >> ISTM there was some reason it wouldn't work, like maybe you can
> > >> only call WSAStartup once per program, but I don't recall for sure.
> > 
> > > We can call WSAStartup() more than once. However,there must be a
> > > call to WSACleanup() for every successful call to WSAStartup()
> > > made by a task. Only the final WSACleanup() for that task does the
> > > actual cleanup.
> > >
> > > The simplest way may be to call WSAStartup() while connecting and 
> > > to call WSACleanup() while finishing(including error cases).
> > 
> > That would be an easy change.  Are these functions fast enough that
> > calling them for every connect/disconnect cycle would be tolerable?
> 
> I beleive so. But we could probably get away from that using static
> variables, no? Somewhere just put:
> 
> static int has_wsastartup = 0;
> 
> ...
> 
> if (!has_wsastartup) {
>    has_wsastartup = 1;
>    WSAStartup()...
> }
> 
> 
> That way, it would only be run once, right? 
> Naturally, everything within #ifdef WIN32.
>

I don't object to your solution.

WSACleanup() is never called.
But no one would care about such a thing.

Regards.

Hiroshi Inoue
Inoue@tpf.co.jp  




^ permalink  raw  reply  [nested|flat] 12+ messages in thread


end of thread, other threads:[~1999-09-07 08:15 UTC | newest]

Thread overview: 12+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-09-02 20:42 Re: [INTERFACES] Win32 interface Ken J. Wright <ken@ori-ind.com>
1999-09-02 21:57 ` David Giffin <david@agent911.com>
1999-09-03 14:40   ` Tom Lane <tgl@sss.pgh.pa.us>
1999-09-03 20:26     ` David Giffin <david@agent911.com>
1999-09-02 21:02 ` David Giffin <david@agent911.com>
1999-09-04 17:05 ` Robert Hiltibidal <rob@y2k.state.il.us>
1999-09-04 13:51 RE: [INTERFACES] Win32 interface Magnus Hagander <mha@sollentuna.net>
1999-09-04 15:20 ` Tom Lane <tgl@sss.pgh.pa.us>
1999-09-06 04:37   ` Hiroshi Inoue <Inoue@tpf.co.jp>
1999-09-06 14:54     ` Tom Lane <tgl@sss.pgh.pa.us>
1999-09-06 15:01 RE: [INTERFACES] Win32 interface Magnus Hagander <mha@sollentuna.net>
1999-09-07 08:15 ` Hiroshi Inoue <Inoue@tpf.co.jp>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox