LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-04-2009, 05:06 PM   #1
nkoplm
Member
 
Registered: May 2005
Distribution: Fedora
Posts: 92

Rep: Reputation: 15
binding to a socket with INADDR_ANY, can i find which ip is being connected to?


hello, I'm currently writing a simple mail receiving server that implements smtp. at this point I' not interested in sending out mail, simply receiving it is my only goal. I do have a few non-standard requirements however. one of them I'm having a little trouble with.

When I bind to a socket, I am using INADDR_ANY because I want to listen to all IP's on the system. However, I don't know how to tell which IP was connected to. I would like to treat connections to different IPs slightly differently, so figuring this out is essential.

could anyone tell me how to do this?


thanks.
 
Old 12-04-2009, 09:10 PM   #2
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
Quote:
Originally Posted by nkoplm View Post
hello, I'm currently writing a simple mail receiving server that implements smtp. at this point I' not interested in sending out mail, simply receiving it is my only goal. I do have a few non-standard requirements however. one of them I'm having a little trouble with.

When I bind to a socket, I am using INADDR_ANY because I want to listen to all IP's on the system. However, I don't know how to tell which IP was connected to. I would like to treat connections to different IPs slightly differently, so figuring this out is essential.

could anyone tell me how to do this?


thanks.
Um, do you want to see what IP address is on the other end, or what IP address is on your end? (The second only usually makes sense if you have more than one ethernet card in your computer.)
 
Old 12-04-2009, 09:22 PM   #3
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
(nevermind)
Kevin Barry

Last edited by ta0kira; 12-04-2009 at 09:23 PM.
 
Old 12-06-2009, 12:17 AM   #4
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
Well for tcp after you accept a connection you should be able to do a getsockname() on the new fd to get your ip that's associated with it, kind of like getpeername() to get the ip of where its coming from.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Binding to Unix Domain Socket blank87 Programming 1 06-18-2008 06:19 PM
help needed with raw socket binding in fedora 3 lhtm Programming 0 08-02-2006 04:00 PM
binding a socket blackzone Programming 1 12-21-2004 06:46 AM
socket binding and writing wahhie Programming 0 11-21-2004 08:38 PM
Socket binding to port problems Xris718 Linux - General 0 07-10-2003 01:04 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration