わいえむねっと

Contents
Categories
Calendar
2007/04
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
Monthly Archives
~2000/01
Recent Entries
RSS1.0
Templates
Information
Processed: 0.047 sec
Chashed: -
2007/04/13 Fri
2時。
寝ると見せかけてウィスキーをぐいー。 そして昨日と同じ電車でやっぱり豚角煮まんは食う。 航空関係の仕事をいくつかやってきたわけですが、ドキュメントが『かんせいとしょ』と呼ばれていたのは『完成図書』でなくて『管制図書』だったのでは。
とか今更のように気付く。 well-knownじゃないよ、ephemeralだよ。

The default dynamic port range for TCP/IP has changed in Windows Vista Enterprise
http://support.mi​crosoft.co​m/kb/929851/en-us
To conform with IANA port-assignment standards, the default dynamic port range for TCP/IP has changed from 1024-5000 to 49152-65535 in Windows Vista Enterprise.

Widnowsでは1024~5000がephemeralで、Vista Enterpriseだけ49152~65535。

How to reserve a range of ephemeral ports on a computer that is running Windows Server 2003 or Windows 2000 Server
http://support.mi​crosoft.co​m/kb/812873/en-us

設定は、

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters

にて変更可能と。

When you try to connect from TCP ports greater than 5000 you receive the error 'WSAENOBUFS (10055)'
http://support.mi​crosoft.co​m/kb/196271/en-us

試しに

#include <stdio.h>
#include <winsock2.h>

void main()
{
	WSADATA tWSAData;
	WSAStartup(MAKEWORD(2, 2), &tWSAData);

	sockaddr_in name;
	name.sin_family = AF_INET;
	name.sin_port = htons(5001);
	name.sin_addr.s_addr = INADDR_ANY;
	int namelen = sizeof(SOCKADDR);

	SOCKET s = socket(AF_INET, SOCK_STREAM, 0);
	bind(s, (SOCKADDR*)&name, namelen);
	listen(s, 1);

	for(;;)
	{
		sockaddr_in name;
		name.sin_family = AF_INET;
		name.sin_port = htons(5001);
		name.sin_addr.s_addr = inet_addr("127.0.0.1");
		int namelen = sizeof(SOCKADDR);

		if(connect(socket(AF_INET, SOCK_STREAM, 0), (SOCKADDR*)&name, namelen) == SOCKET_ERROR)
		{
			break;
		}
		accept(s, (SOCKADDR*)&name, &namelen);
		printf("%d\n", ntohs(name.sin_port));
	}
	printf("->%d\n", WSAGetLastError());
}

とかしてポートを食い潰してみると、確かにWSAENOBUFS。
Linuxでは、

ip-sysctl.txt
Defines the local port range that is used by TCP and UDP to
choose the local port. The first number is the first, the
second the last local port number. Default value depends on
amount of memory available on the system:
> 128Mb 32768-61000
< 128Mb 1024-4999 or even less.
This number defines number of active connections, which this
system can issue simultaneously to systems not supporting
TCP extensions (timestamps). With tcp_tw_recycle enabled
(i.e. by default) range 1024-4999 is enough to issue up to
2000 connections per second to systems supporting timestamps.

128MB以上メモリを積んでいたら32768~61000。

man 7 ip
ip_local_port_range
Contains two integers that define the default local port range allocated to sockets. Allocation starts with the first number and ends with the second number. Note that these should not conflict with the ports used by masquerading (although the case is handled). Also arbitrary choices may cause problems with some firewall packet filters that make assumptions about the local ports in use. First number should be at least >1024, better >4096 to avoid clashes with well known ports and to minimize firewall problems.

設定は、

/proc/sys/net/ipv4/ip_local_port_range

にて変更可能と。
同様にポートを食い潰してみるとEADDRNOTAVAIL。
ふむ。 無糖ブラックは3本。