Solved

getting IP address of client on conenction.

Posted on 1998-11-11
1
282 Views
Last Modified: 2013-12-26
I am writing some basic client server code, and I need to get the ip address of the client so I  can log it. I use the following...

int sockfd, newsockfd, clilen;
struct sockaddr_in   cli_addr;

...
set up listen on sockfd
...

clilen = sizeof(cli_addr);
newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);

..
process communications on newsockfd.

I have tried several iocntl and fcntl calls, but all I get is garbage. I tried getpeername, and getsocketname, but all I get is unitelligable garbage.

any ideas?
0
Comment
Question by:nigel5
1 Comment
 
LVL 4

Accepted Solution

by:
jos010697 earned 50 total points
ID: 1294041
Your cli_addr structure contains the address in its sin_addr member field.
Check out  inet_ntoa() from your man pages (it converts an internet address
to a dotted decimal string).

kind regards,

Jos aka jos@and.nl
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Running shell command from Access 3 63
Separate into files by filename 12 67
if loop in java 3 114
countEvens challenge 2 59
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now