Solved

getting IP address of client on conenction.

Posted on 1998-11-11
1
297 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

630 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