Hi,
I am currently coding a program that allows you to share files between two computers by way of ip address. Its going to work like this. The client receives the IP address from the server then connects via an open port that the server has allowed to be open. What I dont get is how to get the server side IP. Can anyone help me with this? Thanks in advance.

RIF
Posted on 2002-06-28 19:33:03 by resistance_is_futile
gethostname(), gethostbyname()
Posted on 2002-06-28 22:19:44 by comrade
umm arent those used to get the ip of my machine and not the server side? I use them to get my ip but never heard of them being used to get server side ip..
Posted on 2002-06-28 22:26:24 by resistance_is_futile
getpeername() then
Posted on 2002-06-28 22:30:03 by comrade
okay ill try it...
Posted on 2002-06-28 22:54:05 by resistance_is_futile
From MSDN description of the "accept" API:


addr
An optional pointer to a buffer that receives the address of the connecting entity, as known to the communications layer. The exact format of the addr parameter is determined by the address family established when the socket was created.


Meaning you just supply a sockaddr structure and it'll give you the address of the computer connecting to you. Of course if you're the client you should already have the address.
Posted on 2002-06-29 04:58:15 by Qweerdy
there would have to be some way for the server to send it's IP to the client, meaning the server would need the clients IP or some place where it can pick up the clients IP.
For example when somone wants to send a file over IRC the persons IRC client opens a port and then sends his IP and PORT number to the person he wants to send the file to
Hope this helps
Posted on 2002-06-29 07:02:09 by Kudos
If both client and server are connected, there is no need to send any of IPs as both can get them with getpeername().
Posted on 2002-06-29 12:04:23 by comrade
Okay, thanks for all the help guys. Its really helped me out with this. Im still working on it though. Ill fill you guys in with my status when I get done.
Posted on 2002-06-29 19:54:44 by resistance_is_futile