1833451 Members
2903 Online
110052 Solutions
New Discussion

on inet_ntoa in hp-ux

 
Vishal Augustine
Frequent Advisor

on inet_ntoa in hp-ux

Hi

After an accept system call, when I perform an inet_ntoa, I get the result as "0.0.0.0" ? Why is it so ? The same code works fine in Linux with one exception. For the 1st accept it gives "0.0.0.0" and later it shows proper value !!!!! (Linux RedHat 6.2 Kernel 2.2.14-12 /glibc2.1.3-15)

Below is the portion of the sample program. Program was compiled using g++

struct sockaddr_in acc_addr;
memset(&acc_addr,0,sizeof(acc_addr));
if((sad = accept(s_sd,(struct sockaddr *)&acc_addr, &len)) < 0)
{
exit(1);
}

if(!fork())
{
unsigned char readbuff[SOCK_BUFF_SIZE];
cout << inet_ntoa(acc_addr.sin_addr)) << endl;
close(sad)
close(s_sd)
exit(0);
}


Thanks and Regards
Vishal
4 REPLIES 4
Vishal Augustine
Frequent Advisor

Re: on inet_ntoa in hp-ux

Forgot to give the hp details

HP-UX 11.0
aCC 3.3 compiled

Thanks and Regards
Vishal
Vishal Augustine
Frequent Advisor

Re: on inet_ntoa in hp-ux

Got the answer !!!

Thought will share with u ...

The 'len' value passed to 'accept' was not set. Hence the sockaddr_in structure - acc_addr was not getting populated properly.

An interesting aspect is .. it works fine in Linux !! If len is set to zero and we pass acc_addr, the len value is populated but not the acc_addr. In HP-UX , we need to let 'accept' know the value of len.

So the solution is ..

len = sizeof(acc_addr);
if((sad = accept(s_sd,(struct sockaddr *)&acc_addr, &len)) < 0)
{
exit(1);
}

Thanks and Regards
Vishal
rick jones
Honored Contributor

Re: on inet_ntoa in hp-ux

that Linux is happy to fill-in what you have told it is a zero-length sockaddr implies that Linux may not be doing proper parameter checking on the accept() call...
there is no rest for the wicked yet the virtuous have no pillows
Vishal Augustine
Frequent Advisor

Re: on inet_ntoa in hp-ux

I am not a strict guy ... so I wud not say what linux is doing is bad

Vishal