Implementation of the Get*Name() and Get*Port() methods of C_Socket

for IPv6 protocol;

Modified information in AUTHORS.
parent 55925757
...@@ -15,6 +15,7 @@ D: Administration architecture ...@@ -15,6 +15,7 @@ D: Administration architecture
D: Telnet protocol D: Telnet protocol
D: "Native" admin D: "Native" admin
D: "local" input D: "local" input
D: "dvb" input
N: Benoit Steiner N: Benoit Steiner
E: benny@via.ecp.fr E: benny@via.ecp.fr
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* socket.cpp: socket management * socket.cpp: socket management
*------------------------------------------------------------------------------- *-------------------------------------------------------------------------------
* (c)1999-2001 VideoLAN * (c)1999-2001 VideoLAN
* $Id: socket.cpp,v 1.7 2002/03/25 14:49:33 bozo Exp $ * $Id: socket.cpp,v 1.8 2002/03/26 17:01:36 bozo Exp $
* *
* Authors: Benoit Steiner <benny@via.ecp.fr> * Authors: Benoit Steiner <benny@via.ecp.fr>
* Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr> * Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
...@@ -304,6 +304,7 @@ void C_Inet6Addr::Build(const C_String& strHost, const C_String& strPort, ...@@ -304,6 +304,7 @@ void C_Inet6Addr::Build(const C_String& strHost, const C_String& strPort,
{ {
ASSERT(pRes->ai_family == AF_INET6); ASSERT(pRes->ai_family == AF_INET6);
m_sInetAddr = *(sockaddr_in6*)(pRes->ai_addr); m_sInetAddr = *(sockaddr_in6*)(pRes->ai_addr);
freeaddrinfo(pRes);
} }
else else
{ {
...@@ -849,6 +850,29 @@ C_String C_Socket::GetLocalName() const ...@@ -849,6 +850,29 @@ C_String C_Socket::GetLocalName() const
else else
strLocalName = inet_ntoa(saIntf.sin_addr); strLocalName = inet_ntoa(saIntf.sin_addr);
} }
#ifdef HAVE_IPV6
else if(m_iDomain == AF_INET6)
{
struct sockaddr_in6 saIntf;
socklen iNameLen = sizeof(saIntf);
int iRc = getsockname(m_hSocket, (struct sockaddr*)&saIntf, &iNameLen);
ASSERT(iNameLen == sizeof(saIntf));
if(iRc)
{
throw E_Socket("Unable to get name of the intf: " +
GetErrorMsg(SYSTEM_NETWORK));
}
else
{
char pszDst[40]; // 40 characters is enough for an IPv6 address
if(inet_ntop(AF_INET6, &saIntf.sin6_addr, pszDst, 40) == pszDst)
strLocalName = pszDst;
else if(errno != ENOSPC)
throw E_Socket("Unable to get name of the intf: " +
GetErrorMsg(SYSTEM_NETWORK));
}
}
#endif
else else
{ {
ASSERT(false); ASSERT(false);
...@@ -879,6 +903,22 @@ C_String C_Socket::GetLocalPort() const ...@@ -879,6 +903,22 @@ C_String C_Socket::GetLocalPort() const
else else
strLocalPort = ntohs(saIntf.sin_port); strLocalPort = ntohs(saIntf.sin_port);
} }
#ifdef HAVE_IPV6
else if(m_iDomain == AF_INET6)
{
struct sockaddr_in6 saIntf;
socklen iNameLen = sizeof(saIntf);
int iRc = getsockname(m_hSocket, (struct sockaddr*)&saIntf, &iNameLen);
ASSERT(iNameLen == sizeof(saIntf));
if(iRc)
{
throw E_Socket("Unable to get port of the intf: " +
GetErrorMsg(SYSTEM_NETWORK));
}
else
strLocalPort = ntohs(saIntf.sin6_port);
}
#endif
else else
{ {
ASSERT(false); ASSERT(false);
...@@ -909,6 +949,29 @@ C_String C_Socket::GetPeerName() const ...@@ -909,6 +949,29 @@ C_String C_Socket::GetPeerName() const
else else
strPeerName = inet_ntoa(saPeer.sin_addr); strPeerName = inet_ntoa(saPeer.sin_addr);
} }
#ifdef HAVE_IPV6
else if(m_iDomain == AF_INET6)
{
struct sockaddr_in6 saPeer;
socklen iNameLen = sizeof(saPeer);
int iRc = getpeername(m_hSocket, (struct sockaddr*)&saPeer, &iNameLen);
ASSERT(iNameLen == sizeof(saPeer));
if(iRc)
{
throw E_Socket("Unable to get name of the peer: " +
GetErrorMsg(SYSTEM_NETWORK));
}
else
{
char pszDst[40]; // 40 characters is enough for an IPv6 address
if(inet_ntop(AF_INET6, &saPeer.sin6_addr, pszDst, 40) == pszDst)
strPeerName = pszDst;
else if(errno != ENOSPC)
throw E_Socket("Unable to get name of the intf: " +
GetErrorMsg(SYSTEM_NETWORK));
}
}
#endif
else else
{ {
ASSERT(false); ASSERT(false);
...@@ -939,6 +1002,22 @@ C_String C_Socket::GetPeerPort() const ...@@ -939,6 +1002,22 @@ C_String C_Socket::GetPeerPort() const
else else
strPeerPort = ntohs(saPeer.sin_port); strPeerPort = ntohs(saPeer.sin_port);
} }
#ifdef HAVE_IPV6
if(m_iDomain == AF_INET6)
{
struct sockaddr_in6 saPeer;
socklen iNameLen = sizeof(saPeer);
int iRc = getpeername(m_hSocket, (struct sockaddr*)&saPeer, &iNameLen);
ASSERT(iNameLen == sizeof(saPeer));
if(iRc)
{
throw E_Socket("Unable to get port of the peer: " +
GetErrorMsg(SYSTEM_NETWORK));
}
else
strPeerPort = ntohs(saPeer.sin6_port);
}
#endif
else else
{ {
ASSERT(false); ASSERT(false);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment