Monday 15 February 2010

c++ - How to get IP address from sockaddr -


After accepting I want to try the client's IP address. This is what I have done so far, but I just end up having a few long numbers that clearly do not know an IP. What could be wrong?

  int tcp_sock = socket (AF_INET, SOCK_STREAM, 0); Sockaddr_in Client; Client.sin_family = AF_INET; Socklen_t c_len = sizeof (customer); Int acc_tcp_sock = Accepted (TCP_sock, (Socadar *) and Client, & amp; c_len); Cout & lt; & Lt; "Connect to:" & lt; & Lt; Client.sin_addr.s_addr & lt; & Lt; Endl;  

that long number is the IP address, form in integer (An IP address is just an integer, after all, when people separate octets and split it into dot notation, it is easy to use).

To change the integer value into standard dot notation.


No comments:

Post a Comment