Solved

getting IP address of client on conenction.

Posted on 1998-11-11
1
289 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Question regarding Copy/Paste 16 95
sameEnds challenge 3 158
maven archtype selection in eclipse 1 57
twoTwo  challenge 35 101
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

786 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