本文整理汇总了C++中TInetAddr::Init方法的典型用法代码示例。如果您正苦于以下问题:C++ TInetAddr::Init方法的具体用法?C++ TInetAddr::Init怎么用?C++ TInetAddr::Init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TInetAddr
的用法示例。
在下文中一共展示了TInetAddr::Init方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sizeof
/*
* Convert text to IPv4/IPv6 address.
*/
PJ_DEF(pj_status_t) pj_inet_pton(int af, const pj_str_t *src, void *dst)
{
char tempaddr[PJ_INET6_ADDRSTRLEN];
PJ_ASSERT_RETURN(af==PJ_AF_INET || af==PJ_AF_INET6, PJ_EINVAL);
PJ_ASSERT_RETURN(src && src->slen && dst, PJ_EINVAL);
/* Initialize output with PJ_IN_ADDR_NONE for IPv4 (to be
* compatible with pj_inet_aton()
*/
if (af==PJ_AF_INET) {
((pj_in_addr*)dst)->s_addr = PJ_INADDR_NONE;
}
/* Caution:
* this function might be called with cp->slen >= 46
* (i.e. when called with hostname to check if it's an IP addr).
*/
if (src->slen >= PJ_INET6_ADDRSTRLEN) {
return PJ_ENAMETOOLONG;
}
pj_memcpy(tempaddr, src->ptr, src->slen);
tempaddr[src->slen] = '\0';
wchar_t tempaddr16[PJ_INET6_ADDRSTRLEN];
pj_ansi_to_unicode(tempaddr, pj_ansi_strlen(tempaddr),
tempaddr16, sizeof(tempaddr16));
TBuf<PJ_INET6_ADDRSTRLEN> ip_addr((const TText*)tempaddr16);
TInetAddr addr;
addr.Init(KAfInet6);
if (addr.Input(ip_addr) == KErrNone) {
if (af==PJ_AF_INET) {
/* Success (Symbian IP address is in host byte order) */
pj_uint32_t ip = pj_htonl(addr.Address());
pj_memcpy(dst, &ip, 4);
} else if (af==PJ_AF_INET6) {
const TIp6Addr & ip6 = addr.Ip6Address();
pj_memcpy(dst, ip6.u.iAddr8, 16);
} else {
pj_assert(!"Unexpected!");
return PJ_EBUG;
}
return PJ_SUCCESS;
} else {
/* Error */
return PJ_EINVAL;
}
}
示例2: connect_test
static int connect_test()
{
RSocketServ rSockServ;
RSocket rSock;
TInetAddr inetAddr;
TRequestStatus reqStatus;
char buffer[16];
TPtrC8 data((const TUint8*)buffer, (TInt)sizeof(buffer));
int rc;
rc = rSockServ.Connect();
if (rc != KErrNone)
return rc;
rc = rSock.Open(rSockServ, KAfInet, KSockDatagram, KProtocolInetUdp);
if (rc != KErrNone)
{
rSockServ.Close();
return rc;
}
inetAddr.Init(KAfInet);
inetAddr.Input(_L("127.0.0.1"));
inetAddr.SetPort(80);
rSock.Connect(inetAddr, reqStatus);
User::WaitForRequest(reqStatus);
if (reqStatus != KErrNone) {
rSock.Close();
rSockServ.Close();
return rc;
}
rSock.Send(data, 0, reqStatus);
User::WaitForRequest(reqStatus);
if (reqStatus!=KErrNone) {
rSock.Close();
rSockServ.Close();
return rc;
}
rSock.Close();
rSockServ.Close();
return KErrNone;
}