For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > August 2005 > inet_ntoa desn't work on Solaris8?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author inet_ntoa desn't work on Solaris8?
snoullez@gmail.com

2005-08-30, 7:57 am

Hi,

I use a open source SSL proxy (by Symbion) and I've modify it to log IP
and and a time stamp.

I develop on Linux Debian but the target is Solaris 8.
On Linux, all is OK, log is correct and the proxy works.
When I try to run the proxy on Solaris, it works too except loging the
IP address, I have 0.0.0.0 information

I don't understand why IP adresse could be log on Linux and couldn't
work on Solaris. Is it a library problem?


Thanks for answer.
Sebastien N.

Nils O. Selåsdal

2005-08-30, 7:57 am

snoullez@gmail.com wrote:
> Hi,
>
> I use a open source SSL proxy (by Symbion) and I've modify it to log IP
> and and a time stamp.
>
> I develop on Linux Debian but the target is Solaris 8.
> On Linux, all is OK, log is correct and the proxy works.
> When I try to run the proxy on Solaris, it works too except loging the
> IP address, I have 0.0.0.0 information
>
> I don't understand why IP adresse could be log on Linux and couldn't
> work on Solaris. Is it a library problem?

How about showing the code ?
snoullez@gmail.com

2005-08-30, 7:57 am

Here is the dedicated code lines to get IP address
*******************************
struct in_addr in;
char *inetadd;
in =3D cn->server_sa.sin_addr;
inetadd =3D inet_ntoa(in);
debug("IP address client %s\n",inetadd);
*******************************

IP address is stocked in the server_sa.sin_addr ... on Linux it sure
..=2E on Solaris, I hope :-)

S=E9bastien

Nils O. Selåsdal

2005-08-30, 7:57 am

snoullez@gmail.com wrote:
> Here is the dedicated code lines to get IP address
> *******************************
> struct in_addr in;
> char *inetadd;
> in = cn->server_sa.sin_addr;
> inetadd = inet_ntoa(in);
> debug("IP address client %s\n",inetadd);
> *******************************
>
> IP address is stocked in the server_sa.sin_addr ... on Linux it sure
> .. on Solaris, I hope :-)


Looks ok.
How does the struct in_addr get to the cn->server_sa.sin_addr; ?
(Hopefully there isn't something else going on, e.g.
your program is started from inetd,which uses a "tcp6" socket.)
Maxim Yegorushkin

2005-08-30, 7:57 am


snoullez@gmail.com wrote:
> Here is the dedicated code lines to get IP address
> *******************************
> struct in_addr in;
> char *inetadd;
> in = cn->server_sa.sin_addr;
> inetadd = inet_ntoa(in);
> debug("IP address client %s\n",inetadd);
> *******************************


You might like adding raw IP value to the output to see what's going
on:

debug("IP address client (%u) %s\n", in.s_addr, inetadd);

snoullez@gmail.com

2005-08-30, 7:57 am

This code is extract from the Symbion ssl proxy (a sourceforge
project).


Here is my cn structure :
****************************************
***
typedef struct {
ConnStatus stat; // Status of the connection
int server_sock; // Server side socket id
struct sockaddr_in server_sa; // Server's socket address
int server_sa_len; // ^^^^^^^^^^^^^^^^^^^^^^^'s len
SSL *ssl_conn; // SSL connection structure pointer
int client_sock; // Client side socket id
char *csbuf; // Server side write buffer
char *csbuf_b; // Server side write buffer begin ptr
char *csbuf_e; // Server side write buffer end ptr
// int c_end_req; // Client requested connection close
char *scbuf; // Client side write buffer
char *scbuf_b; // Client side write buffer begin ptr
char *scbuf_e; // Client side write buffer end ptr
// int s_end_req; // Server requested connection close

} Conn;
****************************************
***


And here is the code where the cn->server_sa is initialize (it uses an
array of Conn structure from which my cn is extract
****************************************
***
// Initialize SSL connection (server side)
int s=3Daccept(server_socket, (struct sockaddr *)&server_sa,
&server_sa_len);
if (s<=3D0) return 0;
debug("conn_accept(): Client connected");
conn[i].server_sock=3Ds;
bcopy(&server_sa, &conn[i].server_sa, server_sa_len);
****************************************
***

I don't know how accept() function works ...

S=E9bastien

Nils O. Selåsdal

2005-08-30, 6:59 pm

snoullez@gmail.com wrote:
> This code is extract from the Symbion ssl proxy (a sourceforge
> project).
>
>
> Here is my cn structure :
> ****************************************
***
> typedef struct {
> ConnStatus stat; // Status of the connection
> int server_sock; // Server side socket id
> struct sockaddr_in server_sa; // Server's socket address
> int server_sa_len; // ^^^^^^^^^^^^^^^^^^^^^^^'s len
> SSL *ssl_conn; // SSL connection structure pointer
> int client_sock; // Client side socket id
> char *csbuf; // Server side write buffer
> char *csbuf_b; // Server side write buffer begin ptr
> char *csbuf_e; // Server side write buffer end ptr
> // int c_end_req; // Client requested connection close
> char *scbuf; // Client side write buffer
> char *scbuf_b; // Client side write buffer begin ptr
> char *scbuf_e; // Client side write buffer end ptr
> // int s_end_req; // Server requested connection close
>
> } Conn;
> ****************************************
***
>
>
> And here is the code where the cn->server_sa is initialize (it uses an
> array of Conn structure from which my cn is extract
> ****************************************
***
> // Initialize SSL connection (server side)
> int s=accept(server_socket, (struct sockaddr *)&server_sa,
> &server_sa_len);
> if (s<=0) return 0;
> debug("conn_accept(): Client connected");
> conn[i].server_sock=s;
> bcopy(&server_sa, &conn[i].server_sa, server_sa_len);
> ****************************************
***
>
> I don't know how accept() function works ...

Should be goodish too. Atleast if server_sa_len is correct
(the size of the type of server_sa, not e.g. the size of a struct
sockaddr). For debugging purposes, check what server_sa_len
is after the accept call as well..
Maxim Yegorushkin

2005-08-30, 6:59 pm


snoul...@gmail.com wrote:

[]

>
> And here is the code where the cn->server_sa is initialize (it uses an
> array of Conn structure from which my cn is extract
> ****************************************
***
> // Initialize SSL connection (server side)


I don't see here:

server_sa_len = sizeof(server_sa);

> int s=accept(server_socket, (struct sockaddr *)&server_sa,
> &server_sa_len);


snoullez@gmail.com

2005-08-30, 6:59 pm

I forgot write it into this topics but it is in the real code.

I can't test it today, only tomorrow morning (in France ...)

Now, I think it's only the inet_ntoa function which be mad on Solaris
library ...

Thaks for help!

snoullez@gmail.com

2005-08-31, 6:58 pm

Hi,

I could test all variable and struture today and I found this :

On unix, accept() function aren't entierly implemented and the sockaddr
struture is empty after connection.
The getpeerbyname function could be use to get the sockaddr
informations

So, her is the working code :
int s=3Daccept(server_socket, (struct sockaddr *)&server_sa,
&server_sa_len);
struct sockaddr_in server_sa2;
int peerlen =3D sizeof(struct sockaddr);
getpeername(s, (struct sockaddr*)&server_sa2, (int*)&peerlen);
debug("--> addr IP =3D %s
(%u)",inet_ntoa(server_sa2.sin_addr),server_sa2.sin_addr);


It's dummy no?

Thanks for help.
S=E9bastien

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com