Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how can i get client ip address in AF_INET ?
I want to write a program does as a listener!
and log input information!
Posted

Not completely sure this is what you mean, but you can specify a struct to the accept[^] call (you use this to accept connection requests from clients) that is filled with the client's IP and port. Google for "accept socket" for more information and possible examples.
 
Share this answer
 
Comments
[no name] 22-Jul-12 5:46am    
i meant if i want to write a program that listen on a specific port and i want to log any ip address that try to connect my listening server
Code-o-mat 22-Jul-12 5:55am    
Then I still say what I originally wrote should work.
[no name] 24-Jul-12 7:47am    
struct sockaddr_in cltaddr;
cs = accept(sock ,(struct sockaddr *)&cltaddr ,&addrlen);
printf("%d" ,(cltaddr.sin_addr.s_addr);


how can i show the client ip address in network byte order?
Code-o-mat 24-Jul-12 9:20am    
How about the function inet_ntoa ( http://linux.die.net/man/3/inet_ntoa )? You can also see it being used in the examples shown to you by Volynsky Alex (Solution 2).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900