svnno****@sourc*****
svnno****@sourc*****
2013年 3月 21日 (木) 00:13:18 JST
Revision: 5150 http://sourceforge.jp/projects/ttssh2/scm/svn/commits/5150 Author: yutakapon Date: 2013-03-21 00:13:17 +0900 (Thu, 21 Mar 2013) Log Message: ----------- getipv4addr, getipv6addr マクロコマンドを追加した。 strdim ipaddr 10 getipv6addr ipaddr[0] N = result - 1 for i 0 N messagebox ipaddr[i] "IPv6 address" next getipv4addr ipaddr[0] N = result - 1 for i 0 N messagebox ipaddr[i] "IPv4 address" next Modified Paths: -------------- trunk/teraterm/common/helpid.h trunk/teraterm/ttpmacro/ttl.c trunk/teraterm/ttpmacro/ttmparse.c trunk/teraterm/ttpmacro/ttmparse.h trunk/teraterm/ttpmacro/ttpmacro.vcproj -------------- next part -------------- Modified: trunk/teraterm/common/helpid.h =================================================================== --- trunk/teraterm/common/helpid.h 2013-03-19 15:17:48 UTC (rev 5149) +++ trunk/teraterm/common/helpid.h 2013-03-20 15:13:17 UTC (rev 5150) @@ -223,6 +223,8 @@ #define HlpMacroCommandGetenv 92045 #define HlpMacroCommandGetfileattr 92189 #define HlpMacroCommandGethostname 92141 +#define HlpMacroCommandGetipv4addr 92199 +#define HlpMacroCommandGetipv6addr 92200 #define HlpMacroCommandGetpassword 92046 #define HlpMacroCommandGetspecialfolder 92195 #define HlpMacroCommandGettime 92047 Modified: trunk/teraterm/ttpmacro/ttl.c =================================================================== --- trunk/teraterm/ttpmacro/ttl.c 2013-03-19 15:17:48 UTC (rev 5149) +++ trunk/teraterm/ttpmacro/ttl.c 2013-03-20 15:13:17 UTC (rev 5150) @@ -40,6 +40,11 @@ #include "ttl.h" +#include <winsock2.h> +#include <ws2tcpip.h> +#include <iptypes.h> +#include <iphlpapi.h> + #define TTERMCOMMAND "TTERMPRO /D=" #define CYGTERMCOMMAND "cyglaunch -o /D=" @@ -2166,6 +2171,130 @@ return Err; } +#define MAX_IPADDR 10 +/* + strdim ipaddr 10 + getipv4addr ipaddr[0] + result = N + */ +WORD TTLGetIPv4Addr() +{ + WORD Err; + TVarId VarId, id; + INTERFACE_INFO info[MAX_IPADDR]; + SOCKET sock; + DWORD socknum; + int num; + int i, n; + IN_ADDR addr; + + Err = 0; + GetStrVar(&VarId,&Err); + if ((Err==0) && (GetFirstChar()!=0)) + Err = ErrSyntax; + if (Err!=0) return Err; + + // \x8E\xA9\x95\xAA\x8E\xA9\x90g\x82̑SIPv4\x83A\x83h\x83\x8C\x83X\x82\xF0\x8E擾\x82\xB7\x82\xE9\x81B + num = 0; + 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]); + for (i = 0 ; i < n ; i++) { + if ((info[i].iiFlags & IFF_UP) == 0) + continue; + if ((info[i].iiFlags & IFF_LOOPBACK) != 0) + continue; + addr = info[i].iiAddress.AddressIn.sin_addr; + + id = GetStrVarFromArray(GetArrayVarId(VarId), num, &Err); + if (Err == 0) { + SetStrVal(id, inet_ntoa(addr)); + num++; + } else { + break; + } + } + } + closesocket(sock); + + SetResult(num); + + return Err; +} + + +// IPv6\x83A\x83h\x83\x8C\x83X\x82\x9A\x97\xF1\x82ɕϊ\xB7\x82\xB7\x82\xE9\x81B +static void myInetNtop(int Family, char *pAddr, char *pStringBuf, size_t StringBufSize) +{ + int i; + char s[16]; + unsigned int val; + + pStringBuf[0] = '\0'; + for (i = 0 ; i < 16 ; i++) { + val = (pAddr[i]) & 0xFF; + _snprintf_s(s, sizeof(s), _TRUNCATE, "%02x", val); + strncat_s(pStringBuf, StringBufSize, s, _TRUNCATE); + if (i != 15 && (i & 1)) + strncat_s(pStringBuf, StringBufSize, ":", _TRUNCATE); + } +} + + +WORD TTLGetIPv6Addr() +{ + WORD Err; + TVarId VarId, id; + int num; + DWORD ret; + IP_ADAPTER_ADDRESSES addr[256];/* XXX */ + ULONG len = sizeof(addr); + char ipv6str[64]; + + Err = 0; + GetStrVar(&VarId,&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 + num = 0; + ret = GetAdaptersAddresses(AF_INET6, 0, NULL, addr, &len); + if (ret == ERROR_SUCCESS) { + IP_ADAPTER_ADDRESSES *padap = &addr[0]; + + do { + IP_ADAPTER_UNICAST_ADDRESS *uni = padap->FirstUnicastAddress; + + if (!uni) { + continue; + } + do { + SOCKET_ADDRESS addr = uni->Address; + struct sockaddr_in6 *sa; + + if (!(uni->Flags & IP_ADAPTER_ADDRESS_DNS_ELIGIBLE)) { + continue; + } + sa = (struct sockaddr_in6*)addr.lpSockaddr; + myInetNtop(AF_INET6, (char*)&sa->sin6_addr, ipv6str, sizeof(ipv6str)); + + id = GetStrVarFromArray(GetArrayVarId(VarId), num, &Err); + if (Err == 0) { + SetStrVal(id, ipv6str); + num++; + } + + } while ((uni = uni->Next)); + } while ((padap = padap->Next)); + } + + SetResult(num); + + return Err; +} + + WORD TTLGetPassword() { TStrVal Str, Str2, Temp2; @@ -5195,6 +5324,10 @@ Err = TTLGetFileAttr(); break; case RsvGetHostname: Err = TTLGetHostname(); break; + case RsvGetIPv4Addr: + Err = TTLGetIPv4Addr(); break; + case RsvGetIPv6Addr: + Err = TTLGetIPv6Addr(); break; case RsvGetPassword: Err = TTLGetPassword(); break; case RsvSetPassword: Modified: trunk/teraterm/ttpmacro/ttmparse.c =================================================================== --- trunk/teraterm/ttpmacro/ttmparse.c 2013-03-19 15:17:48 UTC (rev 5149) +++ trunk/teraterm/ttpmacro/ttmparse.c 2013-03-20 15:13:17 UTC (rev 5150) @@ -225,6 +225,8 @@ else if (_stricmp(Str,"getenv")==0) *WordId = RsvGetEnv; else if (_stricmp(Str,"getfileattr")==0) *WordId = RsvGetFileAttr; else if (_stricmp(Str,"gethostname")==0) *WordId = RsvGetHostname; + else if (_stricmp(Str,"getipv4addr")==0) *WordId = RsvGetIPv4Addr; + else if (_stricmp(Str,"getipv6addr")==0) *WordId = RsvGetIPv6Addr; else if (_stricmp(Str,"getpassword")==0) *WordId = RsvGetPassword; else if (_stricmp(Str,"getspecialfolder")==0) *WordId = RsvGetSpecialFolder; else if (_stricmp(Str,"gettime")==0) *WordId = RsvGetTime; @@ -1815,3 +1817,9 @@ *Err = 0; return ((VarId+1) << 16) | Index; } + +// \x94z\x97\xF1\x82̗v\x91f\x95ϐ\x94\x82\xA9\x82\xE7\x81A\x94z\x97\xF1\x91S\x91̂\xCCVarID\x82\xF0\x95Ԃ\xB7\x81B +TVarId GetArrayVarId(TVarId VarId) +{ + return ((VarId>>16)-1); +} Modified: trunk/teraterm/ttpmacro/ttmparse.h =================================================================== --- trunk/teraterm/ttpmacro/ttmparse.h 2013-03-19 15:17:48 UTC (rev 5149) +++ trunk/teraterm/ttpmacro/ttmparse.h 2013-03-20 15:13:17 UTC (rev 5150) @@ -225,6 +225,8 @@ #define RsvSetPassword 196 #define RsvIsPassword 197 #define RsvListBox 198 +#define RsvGetIPv4Addr 199 +#define RsvGetIPv6Addr 200 #define RsvOperator 1000 #define RsvBNot 1001 @@ -309,6 +311,7 @@ TVarId GetIntVarFromArray(TVarId VarId, int Index, LPWORD Err); TVarId GetStrVarFromArray(TVarId VarId, int Index, LPWORD Err); BOOL GetIndex(int *Index, LPWORD Err); +TVarId GetArrayVarId(TVarId VarId); extern WORD TTLStatus; extern char LineBuff[MaxLineLen]; Modified: trunk/teraterm/ttpmacro/ttpmacro.vcproj =================================================================== --- trunk/teraterm/ttpmacro/ttpmacro.vcproj 2013-03-19 15:17:48 UTC (rev 5149) +++ trunk/teraterm/ttpmacro/ttpmacro.vcproj 2013-03-20 15:13:17 UTC (rev 5150) @@ -176,7 +176,7 @@ /> <Tool Name="VCLinkerTool" - AdditionalDependencies="onig_sd.lib Version.lib" + AdditionalDependencies="onig_sd.lib Version.lib iphlpapi.lib" OutputFile="..\Debug/ttpmacro.exe" LinkIncremental="1" SuppressStartupBanner="true"