{"action":"created","comment":{"url":"https://api.github.com/repos/xdebug/xdebug/pulls/comments/60213123","id":60213123,"diff_hunk":"@@ -25,165 +25,205 @@\n # include <sys/select.h>\n #endif\n #ifndef PHP_WIN32\n-#include <unistd.h>\n-#endif\n-\n-#ifdef PHP_WIN32\n-# include <process.h>\n-# include <direct.h>\n-# include \"win32/time.h\"\n-#define PATH_MAX MAX_PATH\n-#else\n+# include <unistd.h>\n # include <sys/socket.h>\n-# include <netinet/in.h>\n # include <netinet/tcp.h>\n-# include <arpa/inet.h>\n # include <netdb.h>\n+#else\n+# include <process.h>\n+# include <direct.h>\n+# include \"win32/time.h\"\n+# undef UNICODE\n+# include <winsock2.h>\n+# include <ws2tcpip.h>\n+# pragma comment (lib, \"Ws2_32.lib\")\n+# define PATH_MAX MAX_PATH\n #endif\n \n #include \"xdebug_com.h\"\n \n-#ifdef PHP_WIN32\n-int inet_aton(const char *cp, struct in_addr *inp)\n-{\n-\tinp->s_addr = inet_addr(cp);\n-\tif (inp->s_addr == INADDR_NONE) {\n-\t\treturn 0;\n-\t}\n-\treturn 1;\n-}\n-#endif\n-\n-/*\n- * Converts a host name to an IP address.  */\n-static int lookup_hostname(const char *addr, struct in_addr *in)\n-{\n-\tstruct hostent *host_info;\n-\n-\tif (!inet_aton(addr, in)) {\n-\t\thost_info = gethostbyname(addr);\n-\t\tif (host_info == 0) {\n-\t\t\t/* Error: unknown host */\n-\t\t\treturn -1;\n-\t\t}\n-\t\t*in = *((struct in_addr *) host_info->h_addr);\n-\t}\n-\treturn 0;\n-}\n-/* }}} */\n-\n int xdebug_create_socket(const char *hostname, int dport)\n {\n-\tstruct sockaddr    sa;\n-\tstruct sockaddr_in address;\n-\tint                sockfd;\n-\tint                status;\n-\tstruct timeval     timeout;\n-\tint                actually_connected;\n-\tsocklen_t          size = sizeof(sa);\n+\tstruct addrinfo            hints;\n+\tstruct addrinfo            *remote;\n+\tstruct addrinfo            *ptr;\n+\tint                        status;\n+\tint                        sockfd;\n+\tint                        sockerror;\n+\tchar                       sport[10];\n+\tstruct timeval             timeout;\n+\tint                        actually_connected;\n+\tstruct sockaddr_in6        sa;\n+\tsocklen_t                  size = sizeof(sa);\n #if WIN32|WINNT\n-\tWORD               wVersionRequested;\n-\tWSADATA            wsaData;\n-\tchar               optval = 1;\n-\tconst char         yes = 1;\n-\tu_long             no = 0;\n+\tWORD                       wVersionRequested;\n+\tWSADATA                    wsaData;\n+\tchar                       optval = 1;\n+\tconst char                 yes = 1;\n+\tu_long                     no = 0;\n \n \twVersionRequested = MAKEWORD(2, 2);\n \tWSAStartup(wVersionRequested, &wsaData);\n #else\n-\tlong               optval = 1;\n+\tlong            optval = 1;\n #endif\n-\tmemset(&address, 0, sizeof(address));\n-\tlookup_hostname(hostname, &address.sin_addr);\n-\taddress.sin_family = AF_INET;\n-\taddress.sin_port = htons((unsigned short)dport);\n-\n-\tsockfd = socket(address.sin_family, SOCK_STREAM, 0);\n-\tif (sockfd == SOCK_ERR) {\n+\t\n+\t/* Make a string of the port number that can be used with getaddrinfo */\n+\tsprintf(sport, \"%d\", dport);\n+\n+\t/* Create hints for getaddrinfo saying that we want IPv4 and IPv6 TCP stream sockets */\n+\tmemset(&hints, 0, sizeof(hints));\n+\thints.ai_family = AF_UNSPEC;\n+\thints.ai_socktype = SOCK_STREAM;\n+\thints.ai_protocol = IPPROTO_TCP;\n+\thints.ai_flags = AI_PASSIVE;\n+\n+\t/* Call getaddrinfo and return SOCK_ERR if the call fails for some reason */\n+\tif ((status = getaddrinfo(hostname, sport, &hints, &remote)) != 0) {\n #ifndef DEBUGGER_FAIL_SILENTLY\n #if WIN32|WINNT\n-\t\tprintf(\"create_debugger_socket(\\\"%s\\\", %d) socket: %d\\n\",\n+\t\tprintf(\"create_debugger_socket(\\\"%s\\\", %d) getaddrinfo: %d\\n\",\n \t\t\t\t\thostname, dport, WSAGetLastError());\n #else\n-\t\tprintf(\"create_debugger_socket(\\\"%s\\\", %d) socket: %s\\n\",\n+\t\tprintf(\"create_debugger_socket(\\\"%s\\\", %d) getaddrinfo: %s\\n\",\n \t\t\t\t\thostname, dport, strerror(errno));\n #endif\n #endif\n-\t\treturn -1;\n+\t\treturn SOCK_ERR;\n \t}\n \n-\t/* Put socket in non-blocking mode so we can use select for timeouts */\n-\ttimeout.tv_sec = 0;\n-\ttimeout.tv_usec = 200000;\n+\t/* Go through every returned IP address */\n+\tfor (ptr = remote; ptr != NULL; ptr = ptr->ai_next) {\n+\t\t/* Try to create the socket. If the creation fails continue on with the next IP address in the list */\n+\t\tif ((sockfd = socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol)) == SOCK_ERR) {\n+#ifndef DEBUGGER_FAIL_SILENTLY\n+#if WIN32|WINNT\n+\t\t\tprintf(\"create_debugger_socket(\\\"%s\\\", %d) socket: %d\\n\",\n+\t\t\t\t\t\thostname, dport, WSAGetLastError());\n+#else\n+\t\t\tprintf(\"create_debugger_socket(\\\"%s\\\", %d) socket: %s\\n\",\n+\t\t\t\t\t\thostname, dport, strerror(errno));\n+#endif\n+#endif\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\t/* Put socket in non-blocking mode so we can use select for timeouts */\n+\t\ttimeout.tv_sec = 0;\n+\t\ttimeout.tv_usec = 200000;\n \n #ifdef WIN32\n-\tioctlsocket(sockfd, FIONBIO, (u_long*)&yes);\n+\t\tioctlsocket(sockfd, FIONBIO, (u_long*)&yes);\n #else\n-\tfcntl(sockfd, F_SETFL, O_NONBLOCK);\n+\t\tfcntl(sockfd, F_SETFL, O_NONBLOCK);\n #endif\n \n-\t/* connect */\n-\tstatus = connect(sockfd, (struct sockaddr*)&address, sizeof(address));\n-\tif (status < 0) {\n+\t\t/* Try to connect to the newly created socket */\n+\t\t/* Worth noting is that the port is set in the getaddrinfo call before */\n+\t\tstatus = connect(sockfd, ptr->ai_addr, ptr->ai_addrlen);\n+\t\t\n+\t\t/* Determine if we got a connection. If no connection could be made we close the socket and continue with the next IP address in the list */","path":"xdebug_com.c","position":172,"original_position":172,"commit_id":"3146a97c0bc55051244b4b60768c99ce8049164e","original_commit_id":"3146a97c0bc55051244b4b60768c99ce8049164e","user":{"login":"vanhanit","id":5859654,"avatar_url":"https://avatars.githubusercontent.com/u/5859654?v=3","gravatar_id":"","url":"https://api.github.com/users/vanhanit","html_url":"https://github.com/vanhanit","followers_url":"https://api.github.com/users/vanhanit/followers","following_url":"https://api.github.com/users/vanhanit/following{/other_user}","gists_url":"https://api.github.com/users/vanhanit/gists{/gist_id}","starred_url":"https://api.github.com/users/vanhanit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vanhanit/subscriptions","organizations_url":"https://api.github.com/users/vanhanit/orgs","repos_url":"https://api.github.com/users/vanhanit/repos","events_url":"https://api.github.com/users/vanhanit/events{/privacy}","received_events_url":"https://api.github.com/users/vanhanit/received_events","type":"User","site_admin":false},"body":"Should the new line start with /*, * or nothing, i.e. should the previous line be ended and a new comment started?","created_at":"2016-04-19T11:21:26Z","updated_at":"2016-04-19T11:21:26Z","html_url":"https://github.com/xdebug/xdebug/pull/88#discussion_r60213123","pull_request_url":"https://api.github.com/repos/xdebug/xdebug/pulls/88","_links":{"self":{"href":"https://api.github.com/repos/xdebug/xdebug/pulls/comments/60213123"},"html":{"href":"https://github.com/xdebug/xdebug/pull/88#discussion_r60213123"},"pull_request":{"href":"https://api.github.com/repos/xdebug/xdebug/pulls/88"}}},"pull_request":{"url":"https://api.github.com/repos/xdebug/xdebug/pulls/88","id":9787529,"html_url":"https://github.com/xdebug/xdebug/pull/88","diff_url":"https://github.com/xdebug/xdebug/pull/88.diff","patch_url":"https://github.com/xdebug/xdebug/pull/88.patch","issue_url":"https://api.github.com/repos/xdebug/xdebug/issues/88","number":88,"state":"open","locked":false,"title":"Implemented issue #998: Added support for IPv6","user":{"login":"vanhanit","id":5859654,"avatar_url":"https://avatars.githubusercontent.com/u/5859654?v=3","gravatar_id":"","url":"https://api.github.com/users/vanhanit","html_url":"https://github.com/vanhanit","followers_url":"https://api.github.com/users/vanhanit/followers","following_url":"https://api.github.com/users/vanhanit/following{/other_user}","gists_url":"https://api.github.com/users/vanhanit/gists{/gist_id}","starred_url":"https://api.github.com/users/vanhanit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vanhanit/subscriptions","organizations_url":"https://api.github.com/users/vanhanit/orgs","repos_url":"https://api.github.com/users/vanhanit/repos","events_url":"https://api.github.com/users/vanhanit/events{/privacy}","received_events_url":"https://api.github.com/users/vanhanit/received_events","type":"User","site_admin":false},"body":"- Rewrote the xdebug_create_socket function so that it also supports\r\ncreating sockets for IPv6 addresses.\r\n- Wrote a couple of tests that test both IPv4 and IPv6 connectivity.\r\n- Added some functions to the DebugClient (some refactoring to make it\r\nmore extendable).\r\n- Created a DebugClientIPv6 class that extends from DebugClient. This\r\ncommunicates with Xdebug over IPv6.\r\n\r\n### Known potential problems ###\r\n- Haven't been tested on Windows.\r\n- The DebugClientIPv6::isSupported() function isn't tested, so the SKIP for the test could be ignored on a machine that doesn't support IPv6.","created_at":"2013-11-08T08:20:39Z","updated_at":"2016-04-19T11:21:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b9d5e1300b5376b7ebdb3d71fea2a85b58cb71da","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/xdebug/xdebug/pulls/88/commits","review_comments_url":"https://api.github.com/repos/xdebug/xdebug/pulls/88/comments","review_comment_url":"https://api.github.com/repos/xdebug/xdebug/pulls/comments{/number}","comments_url":"https://api.github.com/repos/xdebug/xdebug/issues/88/comments","statuses_url":"https://api.github.com/repos/xdebug/xdebug/statuses/3146a97c0bc55051244b4b60768c99ce8049164e","head":{"label":"vanhanit:issue998-ipv6","ref":"issue998-ipv6","sha":"3146a97c0bc55051244b4b60768c99ce8049164e","user":{"login":"vanhanit","id":5859654,"avatar_url":"https://avatars.githubusercontent.com/u/5859654?v=3","gravatar_id":"","url":"https://api.github.com/users/vanhanit","html_url":"https://github.com/vanhanit","followers_url":"https://api.github.com/users/vanhanit/followers","following_url":"https://api.github.com/users/vanhanit/following{/other_user}","gists_url":"https://api.github.com/users/vanhanit/gists{/gist_id}","starred_url":"https://api.github.com/users/vanhanit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vanhanit/subscriptions","organizations_url":"https://api.github.com/users/vanhanit/orgs","repos_url":"https://api.github.com/users/vanhanit/repos","events_url":"https://api.github.com/users/vanhanit/events{/privacy}","received_events_url":"https://api.github.com/users/vanhanit/received_events","type":"User","site_admin":false},"repo":{"id":14140703,"name":"xdebug","full_name":"vanhanit/xdebug","owner":{"login":"vanhanit","id":5859654,"avatar_url":"https://avatars.githubusercontent.com/u/5859654?v=3","gravatar_id":"","url":"https://api.github.com/users/vanhanit","html_url":"https://github.com/vanhanit","followers_url":"https://api.github.com/users/vanhanit/followers","following_url":"https://api.github.com/users/vanhanit/following{/other_user}","gists_url":"https://api.github.com/users/vanhanit/gists{/gist_id}","starred_url":"https://api.github.com/users/vanhanit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vanhanit/subscriptions","organizations_url":"https://api.github.com/users/vanhanit/orgs","repos_url":"https://api.github.com/users/vanhanit/repos","events_url":"https://api.github.com/users/vanhanit/events{/privacy}","received_events_url":"https://api.github.com/users/vanhanit/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/vanhanit/xdebug","description":"Xdebug","fork":true,"url":"https://api.github.com/repos/vanhanit/xdebug","forks_url":"https://api.github.com/repos/vanhanit/xdebug/forks","keys_url":"https://api.github.com/repos/vanhanit/xdebug/keys{/key_id}","collaborators_url":"https://api.github.com/repos/vanhanit/xdebug/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/vanhanit/xdebug/teams","hooks_url":"https://api.github.com/repos/vanhanit/xdebug/hooks","issue_events_url":"https://api.github.com/repos/vanhanit/xdebug/issues/events{/number}","events_url":"https://api.github.com/repos/vanhanit/xdebug/events","assignees_url":"https://api.github.com/repos/vanhanit/xdebug/assignees{/user}","branches_url":"https://api.github.com/repos/vanhanit/xdebug/branches{/branch}","tags_url":"https://api.github.com/repos/vanhanit/xdebug/tags","blobs_url":"https://api.github.com/repos/vanhanit/xdebug/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/vanhanit/xdebug/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/vanhanit/xdebug/git/refs{/sha}","trees_url":"https://api.github.com/repos/vanhanit/xdebug/git/trees{/sha}","statuses_url":"https://api.github.com/repos/vanhanit/xdebug/statuses/{sha}","languages_url":"https://api.github.com/repos/vanhanit/xdebug/languages","stargazers_url":"https://api.github.com/repos/vanhanit/xdebug/stargazers","contributors_url":"https://api.github.com/repos/vanhanit/xdebug/contributors","subscribers_url":"https://api.github.com/repos/vanhanit/xdebug/subscribers","subscription_url":"https://api.github.com/repos/vanhanit/xdebug/subscription","commits_url":"https://api.github.com/repos/vanhanit/xdebug/commits{/sha}","git_commits_url":"https://api.github.com/repos/vanhanit/xdebug/git/commits{/sha}","comments_url":"https://api.github.com/repos/vanhanit/xdebug/comments{/number}","issue_comment_url":"https://api.github.com/repos/vanhanit/xdebug/issues/comments{/number}","contents_url":"https://api.github.com/repos/vanhanit/xdebug/contents/{+path}","compare_url":"https://api.github.com/repos/vanhanit/xdebug/compare/{base}...{head}","merges_url":"https://api.github.com/repos/vanhanit/xdebug/merges","archive_url":"https://api.github.com/repos/vanhanit/xdebug/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/vanhanit/xdebug/downloads","issues_url":"https://api.github.com/repos/vanhanit/xdebug/issues{/number}","pulls_url":"https://api.github.com/repos/vanhanit/xdebug/pulls{/number}","milestones_url":"https://api.github.com/repos/vanhanit/xdebug/milestones{/number}","notifications_url":"https://api.github.com/repos/vanhanit/xdebug/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/vanhanit/xdebug/labels{/name}","releases_url":"https://api.github.com/repos/vanhanit/xdebug/releases{/id}","deployments_url":"https://api.github.com/repos/vanhanit/xdebug/deployments","created_at":"2013-11-05T12:21:40Z","updated_at":"2014-10-06T10:14:56Z","pushed_at":"2016-04-19T09:49:50Z","git_url":"git://github.com/vanhanit/xdebug.git","ssh_url":"git@github.com:vanhanit/xdebug.git","clone_url":"https://github.com/vanhanit/xdebug.git","svn_url":"https://github.com/vanhanit/xdebug","homepage":"http://xdebug.org","size":7175,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"xdebug:master","ref":"master","sha":"2bfc4982b40622ea792da276f2d1c3bc8b6e8f98","user":{"login":"xdebug","id":1224722,"avatar_url":"https://avatars.githubusercontent.com/u/1224722?v=3","gravatar_id":"","url":"https://api.github.com/users/xdebug","html_url":"https://github.com/xdebug","followers_url":"https://api.github.com/users/xdebug/followers","following_url":"https://api.github.com/users/xdebug/following{/other_user}","gists_url":"https://api.github.com/users/xdebug/gists{/gist_id}","starred_url":"https://api.github.com/users/xdebug/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xdebug/subscriptions","organizations_url":"https://api.github.com/users/xdebug/orgs","repos_url":"https://api.github.com/users/xdebug/repos","events_url":"https://api.github.com/users/xdebug/events{/privacy}","received_events_url":"https://api.github.com/users/xdebug/received_events","type":"Organization","site_admin":false},"repo":{"id":1934695,"name":"xdebug","full_name":"xdebug/xdebug","owner":{"login":"xdebug","id":1224722,"avatar_url":"https://avatars.githubusercontent.com/u/1224722?v=3","gravatar_id":"","url":"https://api.github.com/users/xdebug","html_url":"https://github.com/xdebug","followers_url":"https://api.github.com/users/xdebug/followers","following_url":"https://api.github.com/users/xdebug/following{/other_user}","gists_url":"https://api.github.com/users/xdebug/gists{/gist_id}","starred_url":"https://api.github.com/users/xdebug/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xdebug/subscriptions","organizations_url":"https://api.github.com/users/xdebug/orgs","repos_url":"https://api.github.com/users/xdebug/repos","events_url":"https://api.github.com/users/xdebug/events{/privacy}","received_events_url":"https://api.github.com/users/xdebug/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/xdebug/xdebug","description":"Xdebug","fork":false,"url":"https://api.github.com/repos/xdebug/xdebug","forks_url":"https://api.github.com/repos/xdebug/xdebug/forks","keys_url":"https://api.github.com/repos/xdebug/xdebug/keys{/key_id}","collaborators_url":"https://api.github.com/repos/xdebug/xdebug/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/xdebug/xdebug/teams","hooks_url":"https://api.github.com/repos/xdebug/xdebug/hooks","issue_events_url":"https://api.github.com/repos/xdebug/xdebug/issues/events{/number}","events_url":"https://api.github.com/repos/xdebug/xdebug/events","assignees_url":"https://api.github.com/repos/xdebug/xdebug/assignees{/user}","branches_url":"https://api.github.com/repos/xdebug/xdebug/branches{/branch}","tags_url":"https://api.github.com/repos/xdebug/xdebug/tags","blobs_url":"https://api.github.com/repos/xdebug/xdebug/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/xdebug/xdebug/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/xdebug/xdebug/git/refs{/sha}","trees_url":"https://api.github.com/repos/xdebug/xdebug/git/trees{/sha}","statuses_url":"https://api.github.com/repos/xdebug/xdebug/statuses/{sha}","languages_url":"https://api.github.com/repos/xdebug/xdebug/languages","stargazers_url":"https://api.github.com/repos/xdebug/xdebug/stargazers","contributors_url":"https://api.github.com/repos/xdebug/xdebug/contributors","subscribers_url":"https://api.github.com/repos/xdebug/xdebug/subscribers","subscription_url":"https://api.github.com/repos/xdebug/xdebug/subscription","commits_url":"https://api.github.com/repos/xdebug/xdebug/commits{/sha}","git_commits_url":"https://api.github.com/repos/xdebug/xdebug/git/commits{/sha}","comments_url":"https://api.github.com/repos/xdebug/xdebug/comments{/number}","issue_comment_url":"https://api.github.com/repos/xdebug/xdebug/issues/comments{/number}","contents_url":"https://api.github.com/repos/xdebug/xdebug/contents/{+path}","compare_url":"https://api.github.com/repos/xdebug/xdebug/compare/{base}...{head}","merges_url":"https://api.github.com/repos/xdebug/xdebug/merges","archive_url":"https://api.github.com/repos/xdebug/xdebug/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/xdebug/xdebug/downloads","issues_url":"https://api.github.com/repos/xdebug/xdebug/issues{/number}","pulls_url":"https://api.github.com/repos/xdebug/xdebug/pulls{/number}","milestones_url":"https://api.github.com/repos/xdebug/xdebug/milestones{/number}","notifications_url":"https://api.github.com/repos/xdebug/xdebug/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/xdebug/xdebug/labels{/name}","releases_url":"https://api.github.com/repos/xdebug/xdebug/releases{/id}","deployments_url":"https://api.github.com/repos/xdebug/xdebug/deployments","created_at":"2011-06-22T12:33:00Z","updated_at":"2016-04-15T16:24:27Z","pushed_at":"2016-04-19T11:08:16Z","git_url":"git://github.com/xdebug/xdebug.git","ssh_url":"git@github.com:xdebug/xdebug.git","clone_url":"https://github.com/xdebug/xdebug.git","svn_url":"https://github.com/xdebug/xdebug","homepage":"http://xdebug.org","size":9082,"stargazers_count":831,"watchers_count":831,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":225,"mirror_url":null,"open_issues_count":6,"forks":225,"open_issues":6,"watchers":831,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/xdebug/xdebug/pulls/88"},"html":{"href":"https://github.com/xdebug/xdebug/pull/88"},"issue":{"href":"https://api.github.com/repos/xdebug/xdebug/issues/88"},"comments":{"href":"https://api.github.com/repos/xdebug/xdebug/issues/88/comments"},"review_comments":{"href":"https://api.github.com/repos/xdebug/xdebug/pulls/88/comments"},"review_comment":{"href":"https://api.github.com/repos/xdebug/xdebug/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/xdebug/xdebug/pulls/88/commits"},"statuses":{"href":"https://api.github.com/repos/xdebug/xdebug/statuses/3146a97c0bc55051244b4b60768c99ce8049164e"}}}}