わいえむねっと

Contents
Categories
Calendar
2007/08
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Monthly Archives
~2000/01
Recent Entries
RSS1.0
Templates
Information
Processed: 0.019 sec
Chashed: -
2007/08/21 Tue
bindされているポートに別ソケットでbindしてもエラーにならずnetstatで確認しても複数のソケットが同アドレス同ポートでLISTENしていることになっていてなんだよそれと思ったら、

Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE (Windows)
http://msdn2.micr​osoft.com/en-us/library/ms740621.a​spx
In the case where the first call to bind sets either SO_REUSEADDR or no socket options at all, the second bind call will "hijack" the port and the application will be unable to determine which of the two sockets received specific packets sent to the "shared" port.

てことですか。
LinuxとSO_REUSEADDRの挙動が違うじゃないのさ。

http://www.linux.​or.jp/JM/html/LDP_man-pages/man7/socket.7.h​tml
SO_REUSEADDR
bind(2) コールに与えられたアドレスが正しいかを判断するルールで、ローカルアドレスの再利用を可能にする。つまり PF_INET ソケットなら、そのアドレスにバインドされたアクティブな listen 状態のソケットが存在しない限り、バインドが行える。 listen 状態のソケットがアドレス INADDR_ANY で特定のポートにバインドされている場合には、このポートに対しては、どんなローカルアドレスでもバインドできない。

SO_EXCLUSIVEADDRUSEにしたらWSAEADDRINUSEが返るように。
パターンは


の"Bind Behavior with Various Options Set"に。