0

i am building a voice messenger type application ... my server application is expected to receive several connections and should b given the option to choose one connection...

my problem is i do not know how to display the ip adress of all the connections that are coming before i pick one specific ip and connect to it .. i am using python on ubuntu ...

2
  • I'm curious why your server doesn't just accept all incoming connections? Commented Apr 10, 2011 at 8:06
  • it does accept...i want it to accept only the one i choose based on the incoming IP ... Commented Apr 10, 2011 at 16:51

1 Answer 1

3

There is no API mechanism that allows you to read the peer address of a potential connection before you accept(2) that connection. It doesn't exist at the sockets level, so it's not going to be in Python, either.

If you want to build way too much knowledge of your operating environment into your application, you can always use libpcap or winpcap or similar tools to sniff the wire for incoming traffic, but (a) this requires elevated privileges, which is often a horrible idea (b) is really unrelated to most communication server tasks.

What the tcp_wrappers mechanism does is accept(2) the incoming connection, call getpeername(2) on the socket, and then close(2) the socket if the program using the tcp_wrappers shouldn't be talking with that remote peer. (See /etc/hosts.allow, /etc/hosts.deny, and /etc/hosts.options, hosts.allow(5) manpage.) This might be rude to the clients, but the sysadmin decided to forbid talking with them anyway, so being friendly isn't a very high priority.

So, is it acceptable to simply close(2) connections after you have already accept(2)ed the connection? If so, you can use socket.getpeername() to find the IP of the remote peer, do what you need, and then call socket.close() on the socket if you shouldn't have accepted the connection in the first place.

Sign up to request clarification or add additional context in comments.

1 Comment

yeah that should do the job for me...rest a'll implement some control logic..thanks ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.