Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > PostgreSQL > How to get the ip address?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-20-02, 02:37
uhexo uhexo is offline
Registered User
 
Join Date: Mar 2002
Posts: 9
Question How to get the ip address?

Hi.

There is a way to get the ip address of the session which is connected to de server?

Give me explain, I desiged a tabla for registering the log of the login request, as:

create tabla audit_login
(
noline serial8,
time timestamp not null
default CURRENT_TIMESTAMP,
user char32
default CURRRENT_USER,
ip inet
)

my problem began when I wished to add default for ip ( field ip) . I could find a default like 'CURRENT_HOSTNAME' or function which returns the hostnamae or ip of the cliente sessions.

So, is there a way to get the client's ip o hostname?

thanks
Reply With Quote
  #2 (permalink)  
Old 03-23-02, 00:38
uhexo uhexo is offline
Registered User
 
Join Date: Mar 2002
Posts: 9
Re: How to get the ip address?

Quote:
Originally posted by uhexo
Hi.

There is a way to get the ip address of the session which is connected to de server?

Give me explain, I desiged a tabla for registering the log of the login request, as:

create tabla audit_login
(
noline serial8,
time timestamp not null
default CURRENT_TIMESTAMP,
user char32
default CURRRENT_USER,
ip inet
)

my problem began when I wished to add default for ip ( field ip) . I could find a default like 'CURRENT_HOSTNAME' or function which returns the hostnamae or ip of the cliente sessions.

So, is there a way to get the client's ip o hostname?

thanks

Heeeellllp.

I made a function on C for getting the ip address but it doesn't compile, I get an error that say "dereferencing pointer to incomplete type"

The main idea what I want to do is :
there are external variable ( global scope until I know about C) inside the global.h and it is populated in function doBackend which is called for mainloop.

Then, It's MyProcPort has the pointer to port to open socket, it would be to use to extract the ip address.

The code of the function is something like this:

#include <string.h>
#include <arpa/inet.h>

#include "postgres.h"
#include "utils/builtins.h"
#include "utils/inet.h"


extern struct Port *MyProcPort;
/*
* External declarations
* I guess I have to use the global variable
* "MyProcPort" with is populated
* when postgres' main_loop function.
*/

char* getsesip();
/*
*This function return
* the user session's ip address
*/
char* getsesip()
{
int32 result = 1 ;
struct Port *port = NULL ;
char *host_addr = NULL ;

port = MyProcPort ;
/* link the pointer port to
* MyProcPort global pointer.
*/
if ( port != NULL ) {
if ( port->raddr.sa.sa_family == AF_INET) {
/* Here I get the error
* "dereferencing pointer to incomplete type"
*/

host_addr =
net_ntoa(port->raddr.in.sin_addr);
}
return host_addr
}

I programed on C long time ago, but i don't understand what error means?

Thank for your comments.
Reply With Quote
  #3 (permalink)  
Old 03-23-02, 00:43
uhexo uhexo is offline
Registered User
 
Join Date: Mar 2002
Posts: 9
Re: How to get the ip address?

Quote:
Originally posted by uhexo
Hi.

There is a way to get the ip address of the session which is connected to de server?

Give me explain, I desiged a tabla for registering the log of the login request, as:

create tabla audit_login
(
noline serial8,
time timestamp not null
default CURRENT_TIMESTAMP,
user char32
default CURRRENT_USER,
ip inet
)

my problem began when I wished to add default for ip ( field ip) . I could find a default like 'CURRENT_HOSTNAME' or function which returns the hostnamae or ip of the cliente sessions.

So, is there a way to get the client's ip o hostname?

thanks

Heeeellllp.

I made a function on C for getting the ip address but it doesn't compile, I get an error that say "dereferencing pointer to incomplete type"

The main idea what I want to do is :
there are external variable ( global scope until I know about C) inside the global.h and it is populated in function doBackend which is called for mainloop.

Then, It's MyProcPort has the pointer to port to open socket, it would be to use to extract the ip address.

The code of the function is something like this:

#include <string.h>
#include <arpa/inet.h>

#include "postgres.h"
#include "utils/builtins.h"
#include "utils/inet.h"


extern struct Port *MyProcPort;
/*
* External declarations
* I guess I have to use the global variable
* "MyProcPort" with is populated
* when postgres' main_loop function.
*/

char* getsesip();
/*
*This function return
* the user session's ip address
*/
char* getsesip()
{
int32 result = 1 ;
struct Port *port = NULL ;
char *host_addr = NULL ;

port = MyProcPort ;
/* link the pointer port to
* MyProcPort global pointer.
*/
if ( port != NULL ) {
if ( port->raddr.sa.sa_family == AF_INET) {
/* Here I get the error
* "dereferencing pointer to incomplete type"
*/

host_addr =
net_ntoa(port->raddr.in.sin_addr);
}
return host_addr
}

I programed on C long time ago, but i don't understand what error means?

Thank for your comments.
Reply With Quote
  #4 (permalink)  
Old 03-23-02, 00:59
uhexo uhexo is offline
Registered User
 
Join Date: Mar 2002
Posts: 9
Re: How to get the ip address?

Quote:
Originally posted by uhexo
Hi.

There is a way to get the ip address of the session which is connected to de server?

Give me explain, I desiged a tabla for registering the log of the login request, as:

create tabla audit_login
(
noline serial8,
time timestamp not null
default CURRENT_TIMESTAMP,
user char32
default CURRRENT_USER,
ip inet
)

my problem began when I wished to add default for ip ( field ip) . I could find a default like 'CURRENT_HOSTNAME' or function which returns the hostnamae or ip of the cliente sessions.

So, is there a way to get the client's ip o hostname?

thanks

Heeeellllp.

I made a function on C for getting the ip address but it doesn't compile, I get an error that say "dereferencing pointer to incomplete type"

The main idea what I want to do is :
there are external pointer called MyProcPort ( global scope until I know about C), that's declared in global.h and it is populated with the user session's socket port in function doBackend when is called for mainloop. The mainloop is a routine of postmaster that is main program that manage the user connection.

Then, MyProcPort has the pointer to port to open socket, it would be to use to extract the ip address.

The code of the function is something like this:

#include <string.h>
#include <arpa/inet.h>

#include "postgres.h"
#include "utils/builtins.h"
#include "utils/inet.h"


extern struct Port *MyProcPort;
/*
* External declarations
* I guess I have to use the global variable
* "MyProcPort" with is populated
* when postgres' main_loop function.
*/

char* getsesip();
/*
*This function return
* the user session's ip address
*/
char* getsesip()
{
int32 result = 1 ;
struct Port *port = NULL ;
char *host_addr = NULL ;

port = MyProcPort ;
/* link the pointer port to
* MyProcPort global pointer.
*/
if ( port != NULL ) {
if ( port->raddr.sa.sa_family == AF_INET) {
/* Here I get the error
* "dereferencing pointer to incomplete type"
*/

host_addr =
net_ntoa(port->raddr.in.sin_addr);
}
return host_addr
}

I programed on C long time ago, but i don't understand what error means?

Thank for your comments.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On