4—IPv6编程windows篇,client篇

本文档展示了如何在Windows环境下使用Dev-C++进行IPv6客户端编程,通过编译源代码实现TCP连接,并提供了解析命令行参数的示例。源代码来源于微软官方样例,适合初学者学习。
摘要由CSDN通过智能技术生成

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值