bak

>/dev/null 2>&1



http://www.west263.com/info/html/chengxusheji/Javajishu/20080226/49389.html


http://www.west263.com/info/html/chengxusheji/Javajishu/20080226/49389_2.html


However, when it comes to server-side programming in C/C , there is an additional wrinkle. Namely, depending on whether your application is written for a dual-stack platform, such as Solaris or Linux, or a single-stack platform, such as Windows, you would need to structure the code differently.


Notice that on a dual-stack machine, since one socket, the IPv6 socket, will be able to Access both IPv4 and IPv6 protocol stacks, you only need to create one socket. Thus this server can potentially support both IPv4 and IPv6 clients

Here's the corresponding server C code for a dual-stack platform:

int ServSock, csock;
struct sockaddr addr, from;
...
ServSock = socket(AF_INET6, SOCK_STREAM, PF_INET6);
bind(ServSock, &addr, sizeof(addr));
do {
csock = accept(ServSocket, &from, sizeof(from));
doClientStuff(csock);
} while (!finished);

Here's the C code for the same server for a single-stack platform:

SOCKET ServSock[FD_SETSIZE];
ADDRINFO AI0, AI1;
ServSock[0] = socket(AF_INET6, SOCK_STREAM, PF_INET6);
ServSock[1] = socket(AF_INET, SOCK_STREAM, PF_INET);
...
bind(ServSock[0], AI0->ai_addr, AI0->ai_addrlen);
bind(ServSock[1], AI1->ai_addr, AI1->ai_addrlen);
...
select(2, &SockSet, 0, 0, 0);
if (FD_ISSET(ServSocket[0], &SockSet)) {
// IPv6 connection csock = accept(ServSocket[0], (LPSOCKADDR)&From, FromLen);
...
}
if (FD_ISSET(ServSocket[1], &SockSet))
// IPv4 connection csock = accept(ServSocket[1], (LPSOCKADDR)&From, FromLen);
...
}

客户端代码:

大学课件 第07章IPv4和IPv6编程

大学课件

http://www.doc88.com/p-98433611979.html

IPv4IPv6


http://wenku.baidu.com/view/ef8eae33b90d6c85ec3ac6a7.html


http://cd34.com/blog/infrastructure/conversion-to-dual-stack-ipv6/


http://wenku.baidu.com/view/3b3e0c1514791711cc79172a.html



IPV4IPV6socket


http://wenku.baidu.com/view/292b9e3283c4bb4cf7ecd182.html


http://download.csdn.net/download/morneve1/2710834


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值