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.