RSPlib Discussions

Text archives Help


Re: [RSPlib-Discusssion] ext_getpeername()


Chronological Thread 
  • From: "Marjan Bozinovski" <marjanb AT cpk.auc.dk>
  • To: "Thomas Dreibholz" <dreibh AT exp-math.uni-essen.de>, <rsplib-discussion AT sctp.de>
  • Subject: Re: [RSPlib-Discusssion] ext_getpeername()
  • Date: Mon Nov 4 10:52:01 2002
  • List-id: RSPlib Discussions <rsplib-discussion.sctp.de>

Thanks Thomas. I realized what the mistake was, and now it's fine, it
returns the IP address.

Regards,
Marjan

----- Original Message -----
From: "Thomas Dreibholz"
<dreibh AT exp-math.uni-essen.de>
To: "Marjan Bozinovski"
<marjanb AT cpk.auc.dk>;

<rsplib-discussion AT sctp.de>
Sent: Monday, November 04, 2002 10:22 AM
Subject: Re: [RSPlib-Discusssion] ext_getpeername()


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Am Sonntag, 3. November 2002 13:19 schrieb Marjan Bozinovski:
> Hi Thomas,
>
> In my application I need to retrieve the IP address of the peer host to
> which there is an existing connection identified by the socket number. As
> far as I know there is a function in a kernel implementation of TCP, which
> can accomplish this: getpeername(). The version of this function in the
> socketapi is: ext_getpeername().
>
> Thus, I call this function as follows:
>
> ext_getpeername(socket_number, (struct sockaddr *) &saddr, (socklen_t *)
> sizeof((struct sockaddr) saddr));

The function is defined as
int ext_getpeername(int sockfd, struct sockaddr* name, socklen_t* namelen).
namelen is a pointer to a variable of type socklen_t, which must contain the
size of the structure given by name before ext_getpeername() is called.
ext_getpeername() returns the real size in this variable.
You give the size directly as the parameter namelen (casted to socklen_t*).
ext_getpeername() interprets this size as address, therefore the segfault.
Do
the following, and your program should work:

socklen_t saddr_size;
...
saddr_size = sizeof(saddr);
result = ext_getpeername(socket_number, (struct sockaddr *) &saddr,
&saddr_size);


> where
>
> socket_number - the socket descriptor of the SCTP association
> saddr - a structure of type sockaddr_in
>
> But, as a result of the execution of the function, I get segmentation
fault
> (core dumped).
>
> Where do I make the mistake? Is there another way of finding out the peer
> host name or IP address by only knowing the socket number.

For multi-homed environments, use sctp_getpaddrs() and sctp_getladdrs() to
obtain remote and local addresses. ext_getpeername() and ext_getsockname()
can only return one of the addresses!


Best regards
- --
=======================================================================
Dipl.-Inform. Thomas Dreibholz

University of Essen, Room ES210
Inst. for Experimental Mathematics Ellernstraße 29
Computer Networking Technology Group D-45326 Essen/Germany
- -----------------------------------------------------------------------
E-Mail:
dreibh AT exp-math.uni-essen.de
Homepage: http://www.exp-math.uni-essen.de/~dreibh
=======================================================================
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE9xjw732BbsHYPLWURAmR2AKDAb4JVG5RmjEhlul8AgYx0wzliTwCeKux+
2EJeymCB6nLGhuj9vu77GQo=
=Tr3E
-----END PGP SIGNATURE-----






Archive powered by MHonArc 2.6.19+.

Top of page