Advertisement

get sockaddr_in from socket

Started by February 05, 2006 01:38 AM
1 comment, last by mattd 19 years ago
if i have a connected socket, can i get the sockaddr_in. my problem is this: i open a tcp connection using INADDR_ANY between the client and server. Now when i want to open a UDP socket connecting the server and client, but i cant use INADDR_ANY on the UDP socket, but i cant receive any udp data. So on the server i want to retreive the ip address the tcp connection is using (incase the server has multiple network cards) and open up my udp port over that network card.
The accept call will fill in the address for you.

EDIT: Oh, you want the server IP address. Hm. Dunno.
Advertisement
getsockname().
    sockaddr_in addr;    socklen_t len = sizeof(sockaddr_in);    getsockname(socketHandle, (sockaddr *)&addr, &len);

This is the opposite to getpeername().

This topic is closed to new replies.

Advertisement