本文整理汇总了C++中IpAddress::setNetAddress方法的典型用法代码示例。如果您正苦于以下问题:C++ IpAddress::setNetAddress方法的具体用法?C++ IpAddress::setNetAddress怎么用?C++ IpAddress::setNetAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IpAddress
的用法示例。
在下文中一共展示了IpAddress::setNetAddress方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
virtual int run()
{
Thread::Link();
int ret = 0;
try
{
char peername[256];
int clientport = m_client->peer_name(peername, 256);
char inbuf[1024];
char outbuf[1024];
memset(inbuf, 0, 1024);
memset(outbuf, 0, 1024);
unsigned int len = 0;
unsigned int lenread = 0;
m_client->read(inbuf, 8, 8, lenread);
if(lenread != 8)
{
DBGLOG("didn't get the first 8 bytes, invalid socks request.");
return -1;
}
len += lenread;
m_client->read(inbuf + len, 0, 1, lenread);
StringBuffer username;
while(lenread > 0)
{
len += lenread;
if(len >= 1023)
{
len = 0;
}
if(inbuf[len - 1] == '\0')
{
break;
}
char c = inbuf[len - 1];
username.append(c);
m_client->read(inbuf + len, 0, 1, lenread);
}
if(http_tracelevel >= 5)
fprintf(m_ofile, "\n>>receivd SOCKS request from %s:%d, user %s\n", peername, clientport, username.str());
outbuf[0] = '\0';
outbuf[1] = (char)0x5a;
m_client->write(outbuf, 8);
char ubyte = inbuf[2];
char lbyte = inbuf[3];
unsigned short port = (unsigned short)ubyte;
port = port << 8;
port += lbyte;
// TBD IPV6 (should use serialize/deserialize)
IpAddress ip;
ip.setNetAddress(4,inbuf+4);
StringBuffer ipstr;
ip.getIpText(ipstr);
if(http_tracelevel >= 5)
fprintf(m_ofile, "\n>>The request is for %s:%d\n", ipstr.str(), port);
SocketEndpoint ep;
ep.set(port, ip);
m_remotesocket.setown(ISocket::connect(ep));
m_client->set_nonblock(false);
m_remotesocket->set_nonblock(false);
CReadWriteThread t1(m_client.get(), m_remotesocket.get(), m_ofile);
CReadWriteThread t2(m_remotesocket.get(), m_client.get(), m_ofile);
t1.start();
t2.start();
t1.join();
t2.join();
m_remotesocket->shutdown();
m_remotesocket->close();
m_client->shutdown();
m_client->close();
}
catch(IException *excpt)
{
StringBuffer errMsg;
DBGLOG("%s", excpt->errorMessage(errMsg).str());
ret = -1;
}
catch(...)
{
DBGLOG("unknown exception");
ret = -1;
}
Thread::Release();
return 0;
//.........这里部分代码省略.........