2011-05-13 12 views
19

可能な値stの列を/proc/net/tcpに知りたいと思います。私はst列がnetstat(8)またはss(8)のSTATE列に等しいと考えます。可能な内部ソケットステータスの一覧/ proc

私は3つのコードを識別するために管理している:

sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode 
0: 0100007F:08A0 00000000:0000 0A 00000000:00000000 00:00000000 00000000  0  0 7321 1 ffff81002f449980 3000 0 0 2 -1      
1: 00000000:006F 00000000:0000 0A 00000000:00000000 00:00000000 00000000  0  0 6656 1 ffff81003a30c080 3000 0 0 2 -1      
2: 00000000:0272 00000000:0000 0A 00000000:00000000 00:00000000 00000000  0  0 6733 1 ffff81003a30c6c0 3000 0 0 2 -1      
3: 0100007F:0277 00000000:0000 0A 00000000:00000000 00:00000000 00000000  0  0 7411 1 ffff81002f448d00 3000 0 0 2 -1      
4: 0100007F:0019 00000000:0000 0A 00000000:00000000 00:00000000 00000000  0  0 7520 1 ffff81002f4486c0 3000 0 0 2 -1      
5: 0100007F:089F 00000000:0000 0A 00000000:00000000 00:00000000 00000000  0  0 7339 1 ffff81002f449340 3000 0 0 2 -1   
6: 0100007F:E753 0100007F:0016 01 00000000:00000000 02:000AFA92 00000000 500  0 18198 2 ffff81002f448080 204 40 20 2 -1     
7: 0100007F:E752 0100007F:0016 06 00000000:00000000 03:000005EC 00000000  0  0 0 2 ffff81000805dc00          

上記番組:線SL 0で

  • :TCP/2208上のリスニングポートを。 st = 0A = LISTEN
  • オンラインsl 6:tcp/22で確立されたセッション。 st = 01 = ESTABLISHED
  • オンラインsl 7:sshログアウト後のTIME_WAIT状態のソケット。 inodeはありません。 st = 06 = TIME_WAIT

誰でもこのリストを展開できますか? proc(5) manページは述べ、件名には非常に簡潔である:

/proc/net/tcp 
      Holds a dump of the TCP socket table. Much of the information is not of use apart from debugging. The "sl" value is the kernel hash slot for the socket, the "local address" is the local address and 
      port number pair. The "remote address" is the remote address and port number pair (if connected). ’St’ is the internal status of the socket. The ’tx_queue’ and ’rx_queue’ are the outgoing and incom- 
      ing data queue in terms of kernel memory usage. The "tr", "tm->when", and "rexmits" fields hold internal information of the kernel socket state and are only useful for debugging. The "uid" field 
      holds the effective UID of the creator of the socket. 

および関連ノートに

は、上記の/ proc /ネット/ tcpの出力は、いくつかのリスニングプロセス(2208、62、111など)を示しています。しかし、確立されたtime_waitの状態が表示されていますが、tcp/22でリッスンするtcp接続を見ることはできません。はい、私は /proc/net/tcp6でそれらを見ることができますが、彼らは /proc/net/tcpにも存在しないはずですか? Netstatの出力は、ipv4だけにバインドされたアプリケーションとは異なる方法で表示されます。例えば。

tcp  0  0 0.0.0.0:111     0.0.0.0:*     LISTEN  4231/portmap   
tcp  0  0 :::22      :::*      LISTEN  4556/sshd   

多くのおかげで、 -Andrew

+0

Heres some [more reading](http://www.readmespot.com/question/f/21657/semantics-of----and-0-0-0-0-in-dual-stack- oses)誰でも興味があればipv4へのipv4へのマッピング –

+0

これは現在死んでいるリンクです。私はおそらくこれにリンクしていると思う:http://serverfault.com/questions/21657/semantics-of-and-0-0-0-0-in-dual-stack-oses – user314104

答えて

27

彼らは、Linuxカーネルソースに./include/net/tcp_states.hに列挙型に一致する必要があります:あなたの2の質問については

enum { 
    TCP_ESTABLISHED = 1, 
    TCP_SYN_SENT, 
    TCP_SYN_RECV, 
    TCP_FIN_WAIT1, 
    TCP_FIN_WAIT2, 
    TCP_TIME_WAIT, 
    TCP_CLOSE, 
    TCP_CLOSE_WAIT, 
    TCP_LAST_ACK, 
    TCP_LISTEN, 
    TCP_CLOSING, /* Now a valid state */ 

    TCP_MAX_STATES /* Leave at the end! */ 
}; 

を、あなたはあります本当に確信しています聞いているsshdではない0.0.0.0:22?そうでない場合は、あなたが見ているものがv4-v6ソケットに関連していると思われます。 man 7 ipv6

+0

ありがとう、なぜ私は知らないソースをグロッピングするときにそれを捕まえていませんでした。私は 'EST 'でマッチングを試みていたと思う。 '0016'にはサービスはありませんので、あなたが言及しているようにv4からv6へのマッピングでなければなりません。私に新しい。 –

+0

また、私は 'tcp_states.h'から16進値をどのように取得するのか完全にはわかりません。あなたが上に貼り付けたような価値を持つ確立されたものしか見ることができませんが、他の州はどのように働いていますか? –

+2

これは列挙型で、1から始まります。 TCP_SYN_SENTは2、TCP_LISTENは10です。10進数の10は16進数の 'A'です。これは/ proc/net/tcpに表示される' 0A'です – nos

関連する問題