socket编程 ipv4代码改造成ipv6代码,谁能帮我? 20
intTerminal::ConnectTo(char*ip,intnPort,intnTimeOut){socklen_tsvrlen;structsockaddr_i...
int Terminal::ConnectTo(char *ip,int nPort,int nTimeOut)
{
socklen_t svrlen;
struct sockaddr_in localaddr;
int sockls;
int ret,flag,error=1;
struct pollfd pollflag;
svrlen = sizeof(localaddr);
memset( (char *)&localaddr, 0, svrlen);
localaddr.sin_family = AF_INET;
localaddr.sin_addr.s_addr = inet_addr(ip);
localaddr.sin_port = htons( nPort );
if( ( sockls = socket(AF_INET, SOCK_STREAM, 0) ) == -1 )
{
//WriteLog(__FILE__,__LINE__,"socket error");
return -1;
}
flag = fcntl( sockls, F_GETFL, 0 );
if( fcntl( sockls, F_SETFL, flag | O_NONBLOCK ) == -1 )
{
//WriteLog(__FILE__,__LINE__, "fcntl error");
close(sockls);
return -2;
}
if( connect(sockls,(const struct sockaddr *)&localaddr,svrlen) != 0 )
{
if( errno == EINPROGRESS )
{
pollflag.fd = sockls;
pollflag.events = POLLOUT;
ret = poll( &pollflag, 1, nTimeOut*1000 );
if( ret <= 0 )
{
close(sockls);
return -3;
}
svrlen = sizeof(error);
if( getsockopt(sockls,SOL_SOCKET,SO_ERROR,&error,&svrlen) == -1 )
{
close(sockls);
return -4;
}
if( error != 0 )
{
close(sockls);
return -5;
}
}
else
{
close(sockls);
return -6;
}
}
return sockls;
}
iOS中要兼容ipv4和ipv6,但我修改后ipv6环境跑不通 展开
{
socklen_t svrlen;
struct sockaddr_in localaddr;
int sockls;
int ret,flag,error=1;
struct pollfd pollflag;
svrlen = sizeof(localaddr);
memset( (char *)&localaddr, 0, svrlen);
localaddr.sin_family = AF_INET;
localaddr.sin_addr.s_addr = inet_addr(ip);
localaddr.sin_port = htons( nPort );
if( ( sockls = socket(AF_INET, SOCK_STREAM, 0) ) == -1 )
{
//WriteLog(__FILE__,__LINE__,"socket error");
return -1;
}
flag = fcntl( sockls, F_GETFL, 0 );
if( fcntl( sockls, F_SETFL, flag | O_NONBLOCK ) == -1 )
{
//WriteLog(__FILE__,__LINE__, "fcntl error");
close(sockls);
return -2;
}
if( connect(sockls,(const struct sockaddr *)&localaddr,svrlen) != 0 )
{
if( errno == EINPROGRESS )
{
pollflag.fd = sockls;
pollflag.events = POLLOUT;
ret = poll( &pollflag, 1, nTimeOut*1000 );
if( ret <= 0 )
{
close(sockls);
return -3;
}
svrlen = sizeof(error);
if( getsockopt(sockls,SOL_SOCKET,SO_ERROR,&error,&svrlen) == -1 )
{
close(sockls);
return -4;
}
if( error != 0 )
{
close(sockls);
return -5;
}
}
else
{
close(sockls);
return -6;
}
}
return sockls;
}
iOS中要兼容ipv4和ipv6,但我修改后ipv6环境跑不通 展开
2016-07-01
展开全部
//下面使用MySql Connector/net提供的专用对象
MySqlConnection mycon = new MySqlConnection(constr);
mycon.Open();
MySqlCommandmycmd = new MySqlCommand("select * from users", mycon);
MySqlDataReader myreader = mycmd.ExecuteReader();
while (myreader.Read())
MySqlConnection mycon = new MySqlConnection(constr);
mycon.Open();
MySqlCommandmycmd = new MySqlCommand("select * from users", mycon);
MySqlDataReader myreader = mycmd.ExecuteReader();
while (myreader.Read())
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
Storm代理
2023-07-25 广告
2023-07-25 广告
StormProxies是一家国内优质海外HTTP代理商,拥有一个庞大的IP资源池,覆盖200多个地区,IP数量大且匿名度高。其优点还包括超高并发、稳定高效、技术服务等特点,同时提供HTTP、HTTPS以及SOCKS5协议支持。此外,Sto...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询