From: Padraig Brady (padraig.brady at domain corvil.com)
Date: Mon 23 Sep 2002 - 14:41:03 IST
Padraig Brady wrote:
> Vincent Cunniffe wrote:
>> Padraig Brady wrote:
>>> Vincent Cunniffe wrote:
>>>> Another interesting question :
>>>> I want to write a small application to randomly close a socket
>>>> in another group of named applications, whose pids will be known
>>>> to the first application.
>>>> It will not be forked from or associated in anyway linked to the
>>>> running applications, it just needs to access information about
>>>> their open TCP sockets and set one of them to 'closed' from
>>>> Is this possible, has anyone done it, and how?
>>> First problem is to determine the fds in the processes
>>> that are sockets. This can be done by walking
>>> /proc/pid/fd/* and looking for links to "socket:[*]"
>> Ah, cool. That's the ID of the socket in the global kernel
>> socket table? Is there an easy way to find out which ones are
>> connected to what?
> That would be /proc/net/tcp (for tcp connections etc.)
> But to tie them to pids you probably still need to walk /proc/pids/fd/*
>>> I'm unsure what you mean by closing the socket.
>>> Do you mean close in the TCP stack to check the
>>> application handles this correctly, or actually
>>> closing the fd in the app, so the app will get
>>> "invalid descriptor" when it tries to use it,
>>> or do you mean asking the app to close a particular fd?
>> Closing the socket from outside the application, without it
>> knowing anything about it, such that it will fail next time
>> it tries to read/write the fd.
>> All of this is to simulate network links dropping, if that's
>> any help.
> Hmm, There is probably some netlink messing to do this
> but I don't know.
Thinking more about this, I'd probably create a seperate app
(there must be one of these already) that acts as a redirector
for connections but also give you control over how the connections
are dropped. You may be even able to do this with netfilter?
This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:19:00 GMT