Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

getting IP address of client on conenction.

Posted on 1998-11-11
1
Medium Priority
?
307 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 200 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
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.
Suggested Courses

824 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