Click here to Skip to main content
13,096,997 members (44,233 online)
Rate this:
Please Sign up or sign in to vote.
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 21-Jul-12 21:52pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
Bathooman 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.
Bathooman 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 ( )? 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170813.1 | Last Updated 22 Jul 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100