Re: how to allow read/write socket only from localhost?



Gordon Beaton <n.o.t@xxxxxxxxx> writes:

On Thu, 10 Aug 2006 16:17:23 -0700, Frank Fredstone wrote:
I want to close a socket if the other side is not on the local
machine, how can I do that?

InetAddress.getHostname() is not "localhost" sometimes, if the
client connects to "localhost". For example, sometimes getHostname()
returns "127.0.0.1".

If it's a server doing this, then it's easier to simply prevent
non-local clients from connecting in the first place.

Just specify the localhost address when you create the ServerSocket.
Connection attempts on other interfaces will be refused by the
operating system, so you never have to deal with them in your
application.

Thank you! It appears to do what you say, but I don't understand the
javadoc:

"The bindAddr argument can be used on a multi-homed host for a
ServerSocket that will only accept connect requests to one of its
addresses."

Is that saying the client must have a local address that is the same
as was given to the ServerSocket constructor on the server?
.



Relevant Pages

  • Re: C# Reflection - Nasty bug??
    ... I am not connecting to the server through localhost, ... > 2) The client portion is not connecting to the right host. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: how to allow read/write socket only from localhost?
    ... InetAddress.getHostnameis not "localhost" sometimes, ... client connects to "localhost". ... If it's a server doing this, then it's easier to simply prevent ... non-local clients from connecting in the first place. ...
    (comp.lang.java.programmer)
  • Xdm and the XDMPC CHooser.. How?
    ... I have one machine that has an X server. ... I would like to have XDM throw up a chooser menu that contains all 5 ... examples with 1 possible client machine and one Xserver machine ... CHOOSER localhost client ...
    (freebsd-questions)
  • Re: 127.0.0.1/localhost in ActiveSync, Windows Mobile 5
    ... The actual exchange server name should be entered in the activesync client, ... workaround is to use 'localhost' in web browser and mail client. ...
    (microsoft.public.pocketpc.developer)
  • Re: Web session come from IP 127.0.0.1 ???
    ... you have a browser open at the ISA and it's configured to use either "localhost" or "127.0.0.1" in the proxy settings ... In ISA session monitor, I saw Web session come from IP ... I think that some client use firewall-pass- ...
    (microsoft.public.isa)