[Ttssh2-commit] [5183] getipv4addr, getipv6addr マクロコマンドにIPアドレス数を返す引数を追加

アーカイブの一覧に戻る

svnno****@sourc***** svnno****@sourc*****
2013年 3月 30日 (土) 01:54:43 JST


Revision: 5183
          http://sourceforge.jp/projects/ttssh2/scm/svn/commits/5183
Author:   maya
Date:     2013-03-30 01:54:42 +0900 (Sat, 30 Mar 2013)
Log Message:
-----------
getipv4addr, getipv6addr マクロコマンドにIPアドレス数を返す引数を追加
  要素数を超えるIPアドレスがあった場合にマクロエラーになるのは望ましくない
  そのことをマクロから知ることができるようにresultとは別の変数を利用する

Modified Paths:
--------------
    trunk/doc/en/html/macro/command/getipv4addr.html
    trunk/doc/en/html/macro/command/getipv6addr.html
    trunk/doc/ja/html/macro/command/getipv4addr.html
    trunk/doc/ja/html/macro/command/getipv6addr.html
    trunk/teraterm/ttpmacro/ttl.c

-------------- next part --------------
Modified: trunk/doc/en/html/macro/command/getipv4addr.html
===================================================================
--- trunk/doc/en/html/macro/command/getipv4addr.html	2013-03-29 16:47:52 UTC (rev 5182)
+++ trunk/doc/en/html/macro/command/getipv4addr.html	2013-03-29 16:54:42 UTC (rev 5183)
@@ -24,35 +24,49 @@
 <h2>Parameters</h2>
 
 <dl>
-	<dt class="macro">Array &lt;string array&gt;</dt>
+	<dt class="macro">String array &lt;string array&gt;</dt>
 	<dd>IP addresses are stored in the string array.</dd>
+
+<--
+	<dt class="macro">\x90\xAE\x90\x94\x8C^\x95ϐ\x94 &lt;num&gt;</dt>
+	<dd>IP\x83A\x83h\x83\x8C\x83X\x82̌\x94\x82\xF0\x8Ai\x94[\x82\xB7\x82鐮\x90\x94\x8C^\x95ϐ\x94\x81BIP\x83A\x83h\x83\x8C\x83X\x82\xAA\x91\xB6\x8D݂\xB5\x82Ȃ\xA2\x8Fꍇ\x81A0\x82\xAA\x8Ai\x94[\x82\xB3\x82\xEA\x82\xE9\x81B</dd>
+-->
 </dl>
 
 <h2>Return Value</h2>
 
 <dl>
 	<dt class="macro">System variable &lt;result&gt;</dt>
-	<dd>It is set to the IP address number.<br>
-	    If the IP address is nothing, it is set to 0.<br>
+	<dd>
+<!--
+        IP\x83A\x83h\x83\x8C\x83X\x82̎擾\x82ɐ\xAC\x8C\x{1C2D42}\xBD\x8Fꍇ\x81A1\x82\xAA\x8Ai\x94[\x82\xB3\x82\xEA\x82\xE9\x81B<br>
+	    IP\x83A\x83h\x83\x8C\x83X\x82̌\x94\x82\xAA&lt;string array&gt;\x82̗v\x91f\x90\x94\x82\xE6\x82\xE8\x91傫\x82\xA2\x8Fꍇ\x81A0\x82\xAA\x8Ai\x94[\x82\xB3\x82\xEA\x82\xE9\x81B<br>
+-->
 	    When the IP address can not retrieve, it is set to -1.</dd>
-	
 </dl>
 
 <h2>Example</h2>
 
 <pre class="macro-example">
-strdim ipaddr 10
+ipaddr_size = 10
+strdim ipaddr ipaddr_size
 
-getipv4addr ipaddr
+getipv4addr ipaddr num
 if result = -1 then
-	messagebox 'Error' 'IPv4 address'
+    messagebox 'Error' 'IPv4 address'
 elseif result = 0 then
-	messagebox 'Not found' 'IPv4 address'
+    N = ipaddr_size - 1
+    for i 0 N
+        messagebox ipaddr[i] "IPv4 address"
+    next
+    N = num - ipaddr_size
+    sprintf2 str "And %d address(es)." N
+    messagebox str "IPv4 address"
 else
-	N = result - 1
-	for i 0 N
-		messagebox ipaddr[i] "IPv4 address"
-	next
+    N = num - 1
+    for i 0 N
+        messagebox ipaddr[i] "IPv4 address"
+    next
 endif
 
 </pre>

Modified: trunk/doc/en/html/macro/command/getipv6addr.html
===================================================================
--- trunk/doc/en/html/macro/command/getipv6addr.html	2013-03-29 16:47:52 UTC (rev 5182)
+++ trunk/doc/en/html/macro/command/getipv6addr.html	2013-03-29 16:54:42 UTC (rev 5183)
@@ -26,34 +26,49 @@
 <dl>
 	<dt class="macro">Array &lt;string array&gt;</dt>
 	<dd>IP addresses are stored in the string array.</dd>
+
+<--
+	<dt class="macro">\x90\xAE\x90\x94\x8C^\x95ϐ\x94 &lt;num&gt;</dt>
+	<dd>IP\x83A\x83h\x83\x8C\x83X\x82̌\x94\x82\xF0\x8Ai\x94[\x82\xB7\x82鐮\x90\x94\x8C^\x95ϐ\x94\x81BIP\x83A\x83h\x83\x8C\x83X\x82\xAA\x91\xB6\x8D݂\xB5\x82Ȃ\xA2\x8Fꍇ\x81A0\x82\xAA\x8Ai\x94[\x82\xB3\x82\xEA\x82\xE9\x81B</dd>
+-->
 </dl>
 
 <h2>Return Value</h2>
 
 <dl>
 	<dt class="macro">System variable &lt;result&gt;</dt>
-	<dd>It is set to the IP address number.<br>
-	    If the IP address is nothing, it is set to 0.<br>
+	<dd>
+<!--
+        IP\x83A\x83h\x83\x8C\x83X\x82̎擾\x82ɐ\xAC\x8C\x{1C2D42}\xBD\x8Fꍇ\x81A1\x82\xAA\x8Ai\x94[\x82\xB3\x82\xEA\x82\xE9\x81B<br>
+	    IP\x83A\x83h\x83\x8C\x83X\x82̌\x94\x82\xAA&lt;string array&gt;\x82̗v\x91f\x90\x94\x82\xE6\x82\xE8\x91傫\x82\xA2\x8Fꍇ\x81A0\x82\xAA\x8Ai\x94[\x82\xB3\x82\xEA\x82\xE9\x81B<br>
+-->
 	    When the IP address can not retrieve, it is set to -1. It is always failed on Windows 2000 or earlier.</dd>
-	
 </dl>
 
 <h2>Example</h2>
 
 <pre class="macro-example">
-strdim ipaddr 10
+ipaddr_size = 10
+strdim ipaddr ipaddr_size
 
-getipv6addr ipaddr
+getipv6addr ipaddr num
 if result = -1 then
-	messagebox 'Error' 'IPv6 address'
+    messagebox 'Error' 'IPv6 address'
 elseif result = 0 then
-	messagebox 'Not found' 'IPv6 address'
+    N = ipaddr_size - 1
+    for i 0 N
+        messagebox ipaddr[i] "IPv6 address"
+    next
+    N = num - ipaddr_size
+    sprintf2 str "And %d address(es)." N
+    messagebox str "IPv6 address"
 else
-	N = result - 1
-	for i 0 N
-		messagebox ipaddr[i] "IPv6 address"
-	next
+    N = num - 1
+    for i 0 N
+        messagebox ipaddr[i] "IPv6 address"
+    next
 endif
+
 </pre>
 
 <h2>See also</h2>

Modified: trunk/doc/ja/html/macro/command/getipv4addr.html
===================================================================
--- trunk/doc/ja/html/macro/command/getipv4addr.html	2013-03-29 16:47:52 UTC (rev 5182)
+++ trunk/doc/ja/html/macro/command/getipv4addr.html	2013-03-29 16:54:42 UTC (rev 5183)
@@ -18,41 +18,50 @@
 </p>
 
 <pre class="macro-syntax">
-getipv4addr &lt;string array&gt;
+getipv4addr &lt;string array&gt; &lt;num&gt;
 </pre>
 
 <h2>\x83p\x83\x89\x83\x81\x81[\x83^</h2>
 
 <dl>
-	<dt class="macro">\x94z\x97\xF1 &lt;string array&gt;</dt>
+	<dt class="macro">\x95\xB6\x8E\x9A\x97\xF1\x94z\x97\xF1 &lt;string array&gt;</dt>
 	<dd>IP\x83A\x83h\x83\x8C\x83X\x82\xF0\x8Ai\x94[\x82\xB7\x82镶\x8E\x9A\x8C^\x94z\x97\xF1\x81B</dd>
+
+	<dt class="macro">\x90\xAE\x90\x94\x8C^\x95ϐ\x94 &lt;num&gt;</dt>
+	<dd>IP\x83A\x83h\x83\x8C\x83X\x82̌\x94\x82\xF0\x8Ai\x94[\x82\xB7\x82鐮\x90\x94\x8C^\x95ϐ\x94\x81BIP\x83A\x83h\x83\x8C\x83X\x82\xAA\x91\xB6\x8D݂\xB5\x82Ȃ\xA2\x8Fꍇ\x81A0\x82\xAA\x8Ai\x94[\x82\xB3\x82\xEA\x82\xE9\x81B</dd>
 </dl>
 
 <h2>\x95Ԃ\xE8\x92l</h2>
 
 <dl>
 	<dt class="macro">\x83V\x83X\x83e\x83\x80\x95ϐ\x94 &lt;result&gt;</dt>
-	<dd>IP\x83A\x83h\x83\x8C\x83X\x82̌\x94\x82\xAA\x8Ai\x94[\x82\xB3\x82\xEA\x82\xE9\x81B<br>
-	    IP\x83A\x83h\x83\x8C\x83X\x82\xAA\x91\xB6\x8D݂\xB5\x82Ȃ\xA2\x8Fꍇ\x81A0\x82\xAA\x8Ai\x94[\x82\xB3\x82\xEA\x82\xE9\x81B<br>
+	<dd>IP\x83A\x83h\x83\x8C\x83X\x82̎擾\x82ɐ\xAC\x8C\x{1C2D42}\xBD\x8Fꍇ\x81A1\x82\xAA\x8Ai\x94[\x82\xB3\x82\xEA\x82\xE9\x81B<br>
+	    IP\x83A\x83h\x83\x8C\x83X\x82̌\x94\x82\xAA&lt;string array&gt;\x82̗v\x91f\x90\x94\x82\xE6\x82\xE8\x91傫\x82\xA2\x8Fꍇ\x81A0\x82\xAA\x8Ai\x94[\x82\xB3\x82\xEA\x82\xE9\x81B<br>
 	    IP\x83A\x83h\x83\x8C\x83X\x82̎擾\x82Ɏ\xB8\x94s\x82\xB5\x82\xBD\x8Fꍇ\x81A-1\x82\xAA\x8Ai\x94[\x82\xB3\x82\xEA\x82\xE9\x81B</dd>
-	
 </dl>
 
 <h2>\x97\xE1</h2>
 
 <pre class="macro-example">
-strdim ipaddr 10
+ipaddr_size = 10
+strdim ipaddr ipaddr_size
 
-getipv4addr ipaddr
+getipv4addr ipaddr num
 if result = -1 then
-	messagebox 'Error' 'IPv4 address'
+    messagebox 'Error' 'IPv4 address'
 elseif result = 0 then
-	messagebox 'Not found' 'IPv4 address'
+    N = ipaddr_size - 1
+    for i 0 N
+        messagebox ipaddr[i] "IPv4 address"
+    next
+    N = num - ipaddr_size
+    sprintf2 str "And %d address(es)." N
+    messagebox str "IPv4 address"
 else
-	N = result - 1
-	for i 0 N
-		messagebox ipaddr[i] "IPv4 address"
-	next
+    N = num - 1
+    for i 0 N
+        messagebox ipaddr[i] "IPv4 address"
+    next
 endif
 
 </pre>

Modified: trunk/doc/ja/html/macro/command/getipv6addr.html
===================================================================
--- trunk/doc/ja/html/macro/command/getipv6addr.html	2013-03-29 16:47:52 UTC (rev 5182)
+++ trunk/doc/ja/html/macro/command/getipv6addr.html	2013-03-29 16:54:42 UTC (rev 5183)
@@ -26,34 +26,44 @@
 <dl>
 	<dt class="macro">\x94z\x97\xF1 &lt;string array&gt;</dt>
 	<dd>IP\x83A\x83h\x83\x8C\x83X\x82\xF0\x8Ai\x94[\x82\xB7\x82镶\x8E\x9A\x8C^\x94z\x97\xF1\x81B</dd>
+
+	<dt class="macro">\x90\xAE\x90\x94\x8C^\x95ϐ\x94 &lt;num&gt;</dt>
+	<dd>IP\x83A\x83h\x83\x8C\x83X\x82̌\x94\x82\xF0\x8Ai\x94[\x82\xB7\x82鐮\x90\x94\x8C^\x95ϐ\x94\x81BIP\x83A\x83h\x83\x8C\x83X\x82\xAA\x91\xB6\x8D݂\xB5\x82Ȃ\xA2\x8Fꍇ\x81A0\x82\xAA\x8Ai\x94[\x82\xB3\x82\xEA\x82\xE9\x81B</dd>
 </dl>
 
 <h2>\x95Ԃ\xE8\x92l</h2>
 
 <dl>
 	<dt class="macro">\x83V\x83X\x83e\x83\x80\x95ϐ\x94 &lt;result&gt;</dt>
-	<dd>IP\x83A\x83h\x83\x8C\x83X\x82̌\x94\x82\xAA\x8Ai\x94[\x82\xB3\x82\xEA\x82\xE9\x81B<br>
-	    IP\x83A\x83h\x83\x8C\x83X\x82\xAA\x91\xB6\x8D݂\xB5\x82Ȃ\xA2\x8Fꍇ\x81A0\x82\xAA\x8Ai\x94[\x82\xB3\x82\xEA\x82\xE9\x81B
+	<dd>IP\x83A\x83h\x83\x8C\x83X\x82̎擾\x82ɐ\xAC\x8C\x{1C2D42}\xBD\x8Fꍇ\x81A1\x82\xAA\x8Ai\x94[\x82\xB3\x82\xEA\x82\xE9\x81B<br>
+	    IP\x83A\x83h\x83\x8C\x83X\x82̌\x94\x82\xAA&lt;string array&gt;\x82̗v\x91f\x90\x94\x82\xE6\x82\xE8\x91傫\x82\xA2\x8Fꍇ\x81A0\x82\xAA\x8Ai\x94[\x82\xB3\x82\xEA\x82\xE9\x81B<br>
 	    IP\x83A\x83h\x83\x8C\x83X\x82̎擾\x82Ɏ\xB8\x94s\x82\xB5\x82\xBD\x8Fꍇ\x81A-1\x82\xAA\x8Ai\x94[\x82\xB3\x82\xEA\x82\xE9\x81BWindows 2000 \x88ȑO\x82ł͏\xED\x82Ɏ\xB8\x94s\x82\xB7\x82\xE9\x81B</dd>
-	
 </dl>
 
 <h2>\x97\xE1</h2>
 
 <pre class="macro-example">
-strdim ipaddr 10
+ipaddr_size = 10
+strdim ipaddr ipaddr_size
 
-getipv6addr ipaddr
+getipv6addr ipaddr num
 if result = -1 then
-	messagebox 'Error' 'IPv6 address'
+    messagebox 'Error' 'IPv6 address'
 elseif result = 0 then
-	messagebox 'Not found' 'IPv6 address'
+    N = ipaddr_size - 1
+    for i 0 N
+        messagebox ipaddr[i] "IPv6 address"
+    next
+    N = num - ipaddr_size
+    sprintf2 str "And %d address(es)." N
+    messagebox str "IPv6 address"
 else
-	N = result - 1
-	for i 0 N
-		messagebox ipaddr[i] "IPv6 address"
-	next
+    N = num - 1
+    for i 0 N
+        messagebox ipaddr[i] "IPv6 address"
+    next
 endif
+
 </pre>
 
 <h2>\x8EQ\x8F\xC6</h2>

Modified: trunk/teraterm/ttpmacro/ttl.c
===================================================================
--- trunk/teraterm/ttpmacro/ttl.c	2013-03-29 16:47:52 UTC (rev 5182)
+++ trunk/teraterm/ttpmacro/ttl.c	2013-03-29 16:54:42 UTC (rev 5183)
@@ -2256,23 +2256,23 @@
 #define MAX_IPADDR 30
 /*
  strdim ipaddr 10
- getipv4addr ipaddr
- result = N
+ getipv4addr ipaddr num
  */
 WORD TTLGetIPv4Addr()
 {
 	WORD Err;
-	TVarId VarId, id;
+	TVarId VarId, VarId2, id;
 	WSADATA ws;
 	INTERFACE_INFO info[MAX_IPADDR];
 	SOCKET sock;
 	DWORD socknum;
-	int num;
+	int num, result, arysize;
 	int i, n;
 	IN_ADDR addr;
 
 	Err = 0;
 	GetStrAryVar(&VarId,&Err);
+	GetIntVar(&VarId2, &Err);
 	if ((Err==0) && (GetFirstChar()!=0))
 		Err = ErrSyntax;
 	if (Err!=0) return Err;
@@ -2280,9 +2280,12 @@
 	// \x8E\xA9\x95\xAA\x8E\xA9\x90g\x82̑SIPv4\x83A\x83h\x83\x8C\x83X\x82\xF0\x8E擾\x82\xB7\x82\xE9\x81B
 	if (WSAStartup(MAKEWORD(2,2), &ws) != 0) {
 		SetResult(-1);
+		SetIntVal(VarId2, 0);
 		return Err;
 	}
+	arysize = GetStrAryVarSize(VarId);
 	num = 0;
+	result = 1;
 	sock = WSASocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, NULL, 0, 0);
 	if (WSAIoctl(sock, SIO_GET_INTERFACE_LIST, NULL, 0, info, sizeof(info), &socknum, NULL, NULL) != SOCKET_ERROR) {
 		n = socknum / sizeof(info[0]);
@@ -2293,19 +2296,21 @@
 				continue;
 			addr = info[i].iiAddress.AddressIn.sin_addr;
 
-			id = GetStrVarFromArray(VarId, num, &Err);
-			if (Err == 0) {
+			if (num < arysize) {
+				id = GetStrVarFromArray(VarId, num, &Err);
 				SetStrVal(id, inet_ntoa(addr));
-				num++;
-			} else {
-				break;
 			}
+			else {
+				result = 0;
+			}
+			num++;
 		}
 	}
 	closesocket(sock);
 	WSACleanup();
 
-	SetResult(num);
+	SetResult(result);
+	SetIntVal(VarId2, num);
 
 	return Err;
 }
@@ -2338,8 +2343,8 @@
 WORD TTLGetIPv6Addr()
 {
 	WORD Err;
-	TVarId VarId, id;
-	int num;
+	TVarId VarId, VarId2, id;
+	int num, result, arysize;
     DWORD ret;
     IP_ADAPTER_ADDRESSES addr[256];/* XXX */
     ULONG len = sizeof(addr);
@@ -2349,22 +2354,26 @@
 
 	Err = 0;
 	GetStrAryVar(&VarId,&Err);
+	GetIntVar(&VarId2, &Err);
 	if ((Err==0) && (GetFirstChar()!=0))
 		Err = ErrSyntax;
 	if (Err!=0) return Err;
 
 	// \x8E\xA9\x95\xAA\x8E\xA9\x90g\x82̑SIPv6\x83A\x83h\x83\x8C\x83X\x82\xF0\x8E擾\x82\xB7\x82\xE9\x81B
 	if ((h = LoadLibrary("iphlpapi.dll")) == NULL) {
-		int err = GetLastError();
 		SetResult(-1);
+		SetIntVal(VarId2, 0);
 		return Err;
 	}
 	if ((pfunc = (pGetAdaptersAddresses)GetProcAddress(h, "GetAdaptersAddresses")) == NULL) {
 		FreeLibrary(h);
 		SetResult(-1);
+		SetIntVal(VarId2, 0);
 		return Err;
 	}
+	arysize = GetStrAryVarSize(VarId);
 	num = 0;
+	result = 1;
 	ret = pfunc(AF_INET6, 0, NULL, addr, &len);
 	if (ret == ERROR_SUCCESS) {
 		IP_ADAPTER_ADDRESSES *padap = &addr[0];
@@ -2385,17 +2394,21 @@
 				sa = (struct sockaddr_in6*)addr.lpSockaddr;
 				myInetNtop(AF_INET6, (char*)&sa->sin6_addr, ipv6str, sizeof(ipv6str));
 
-				id = GetStrVarFromArray(VarId, num, &Err);
-				if (Err == 0) {
+				if (num < arysize) {
+					id = GetStrVarFromArray(VarId, num, &Err);
 					SetStrVal(id, ipv6str);
-					num++;
 				}
+				else {
+					result = 0;
+				}
+				num++;
 
 			} while ((uni = uni->Next));
 		} while ((padap = padap->Next));
 	}
 
-	SetResult(num);
+	SetResult(result);
+	SetIntVal(VarId2, num);
 
 	FreeLibrary(h);
 	return Err;



Ttssh2-commit メーリングリストの案内
アーカイブの一覧に戻る