Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

getting address name from socket

Posted on 1999-08-18
7
Medium Priority
?
508 Views
Last Modified: 2008-02-20
we are trying to use getpeerbyname to get the other computer name (connected by socket), but we get the wrong address all the time. anyone how think he can help please e-mail me to sliv.tech2.technion.ac.il , and i will send him the program itself.
0
Comment
Question by:yaronliv
[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
7 Comments
 
LVL 11

Expert Comment

by:alexo
ID: 1264594
What does the call to getpeername() return?
0
 
LVL 3

Expert Comment

by:cwrea
ID: 1264595
How do you know it is the wrong address?  Is it possible that the other end is a multi-homed machine?  (i.e. has more than one network interface, thus more than one address?)

Is it possible that the other end is behind a firewall that is proxy-based, or is performing Network Address Translation, so that you are getting a different address instead?

0
 
LVL 11

Expert Comment

by:alexo
ID: 1264596
Yaron, try running the client and the server on the same machine
0
Industry Leaders: 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!

 
LVL 8

Expert Comment

by:shlomoy
ID: 1264597
check what you inpot to the function. Perhaps you let ir read the wrong data structure.
0
 

Expert Comment

by:m_t_m
ID: 1264598
Are you sure you used the corect call, i mean something like:

sockaddr_in addr;
int sz=sizeof(addr);
getpeername(sock,(sockaddr *)&addr,&sz);

peerName=strdup(inet_ntoa(addr.sin_addr));
peerPort=ntohs(addr.sin_port);


0
 
LVL 2

Accepted Solution

by:
zbang earned 800 total points
ID: 1264599
I encountered the same problem myself.
try doing a:

   sprintf(peerName, "%d.%d.%d.%d",
        addr.sin_addr.s_addr.s_un_b.b1,
        addr.sin_addr.s_addr.s_un_b.b2,
        addr.sin_addr.s_addr.s_un_b.b3,
        addr.sin_addr.s_addr.s_un_b.b4);

there seems to be a bug with inet_ntoa()


0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6820354
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects that and the expert will now receive these points, all verified.
Moondancer
Moderator @ Experts Exchange
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

664 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