windows下的ipv6客户端,同样用dev-cpp 4.9.9.2编译,5.10版本的dev也可通过编译,x86和x64 TDM-GCC均可成功编译,源代码如下,修改自微软官方样例:
// for linux http://blog.csdn.net/caspiansea/article/details/29779655
// code source from windows: https://msdn.microsoft.com/ja-jp/library/windows/desktop/ms738630(v=vs.85).aspx
>
#undef UNICODE
#include <winsock2.h>// -lWs2_32
//undefined: gai_strerrorA@4'
#include <ws2tcpip.h>
#include <stdio.h>
#include <cctype> // for ToLower() function
#include<iostream>
using namespace std;
// Link with ws2_32.lib
// #pragma comment(lib, "Ws2_32.lib")
#define STRICMP _stricmp
// This code assumes that at the transport level, the system only supports
// one stream protocol (TCP) and one datagram protocol (UDP). Therefore,
// specifying a socket type of SOCK_STREAM is equivalent to specifying TCP
// and specifying a socket type of SOCK_DGRAM is equivalent to specifying UDP.
#define DEFAULT_SERVER NULL // Will use the loopback interface
#define DEFAULT_FAMILY PF_UNSPEC // Accept either IPv4 or IPv6
#define DEFAULT_SOCKTYPE SOCK_STREAM // TCP
#define DEFAULT_PORT "5001" // Arbitrary, albiet a historical test port
#define DEFAULT_EXTRA 0 // Number of "extra" bytes to send
#define BUFFER_SIZE 65536
#define UNKNOWN_NAME "<unknown>"
void Usage(char *ProgName){
cout<<"usage exit:"<<ProgName;
WSACleanup();
exit(1);
}
LPTSTR PrintError(int ErrorCode)
{
static TCHAR Message[1024];
// If this program was multithreaded, we'd want to use
// FORMAT_MESSAGE_ALLOCATE_BUFFER instead of a static buffer here.
// (And of course, free the buffer when we were done with it)
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_MAX_WIDTH_MASK,
NULL, ErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_D