1824219 Members
4250 Online
109669 Solutions
New Discussion юеВ

getpeername API()

 
Shweta_3
Occasional Advisor

getpeername API()

I am using the API getpeername() in my multi-threaded application.

The API returns with return code zero, however does not fill in the struct addr or value of length.

Is this an expected behavior by the API, else, what could I suspect?
The other APIs like getsockname() etc return correct value just before this call. So if their is a issue with the peer socket, it would report it, right?

I am setting the length to the struct sockaddr before calling the API, which is reset to zero post call.

Any pointers/ link to known issues/ patches required will be of help.

Thanks,
Shweta
5 REPLIES 5
Muthukumar_5
Honored Contributor

Re: getpeername API()

which operating system you are using? Is it your own application or from any third party or build in? Do you have the code for getpeername() call?

--
Muthu
Easy to suggest when don't know about the problem!
Arunvijai_4
Honored Contributor

Re: getpeername API()

Hi Shweta,

Hope you are using HP-UX. Take a look at this links, it may help you if you are transisting your apps from Solaris to HP-UX or Linux to HP-UX.

http://devrsrc1.external.hp.com/STKS/cgi-bin/man2html?debug=0&manpage=/usr/share/man/man2.Z/getpeername.2
http://devrsrc1.external.hp.com/STKL/impacts/i38.html

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Shweta_3
Occasional Advisor

Re: getpeername API()

Thanks, and sorry for not being more specific.
Yes I am running this on a HP-UX B.11.11 U 9000/800

I did go though the manual page, however didn't catch anything in particular.

Using a simple socket program, the API does return having filled in the addr structure properly. However not in my application, I am not sure what to suspect.
I tried both the combinations
a)
struct sockaddr and sizeof(struct sockaddr)
b)
struct sockaddr_un and sizeof(struct sockaddr_un)

Anything more I may provide?

Arunvijai_4
Honored Contributor

Re: getpeername API()

Hi Shweta,

It could be due to incompatible types, if possible attach your sample code to take a look at it.

-Arun

P.S Assign points.
"A ship in the harbor is safe, but that is not what ships are built for"
rick jones
Honored Contributor

Re: getpeername API()

When you are compiling your multi-threaded application, are you setting -D_REENTRANT? You are linking against -lpthread right?

Have you looked at your application's getpeername() call in a verbose tusc trace (tusc -v)?

BTW, unless you are completely disassociated from the code that made the accept() call, you should already have the peer information from what is returned by the accept() call (or for that matter from what you passed-in to a connect() call)

Also, you might check what sizeof(struct sockaddr) happens to be comapred with sizeof (struct sockaddr_in) if this is an IPv4 application or struct sockaddr_in6 if this is IPv6...
there is no rest for the wicked yet the virtuous have no pillows