MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / GetSockAddr

Method GetSockAddr

src/netaddress.cpp:862–890  ·  view source on GitHub ↗

* Obtain the IPv4/6 socket address this represents. * * @param[out] paddr The obtained socket address. * @param[in,out] addrlen The size, in bytes, of the address structure pointed * to by paddr. The value that's pointed to by this * parameter might change after calling this function if * the size of the corresponding addre

Source from the content-addressed store, hash-verified

860 * @returns Whether or not the operation was successful.
861 */
862bool CService::GetSockAddr(struct sockaddr* paddr, socklen_t *addrlen) const
863{
864 if (IsIPv4()) {
865 if (*addrlen < (socklen_t)sizeof(struct sockaddr_in))
866 return false;
867 *addrlen = sizeof(struct sockaddr_in);
868 struct sockaddr_in *paddrin = (struct sockaddr_in*)paddr;
869 memset(paddrin, 0, *addrlen);
870 if (!GetInAddr(&paddrin->sin_addr))
871 return false;
872 paddrin->sin_family = AF_INET;
873 paddrin->sin_port = htons(port);
874 return true;
875 }
876 if (IsIPv6() || IsCJDNS()) {
877 if (*addrlen < (socklen_t)sizeof(struct sockaddr_in6))
878 return false;
879 *addrlen = sizeof(struct sockaddr_in6);
880 struct sockaddr_in6 *paddrin6 = (struct sockaddr_in6*)paddr;
881 memset(paddrin6, 0, *addrlen);
882 if (!GetIn6Addr(&paddrin6->sin6_addr))
883 return false;
884 paddrin6->sin6_scope_id = m_scope_id;
885 paddrin6->sin6_family = AF_INET6;
886 paddrin6->sin6_port = htons(port);
887 return true;
888 }
889 return false;
890}
891
892/**
893 * @returns An identifier unique to this service's address and port number.

Callers 6

BindAndStartListeningMethod · 0.80
ConnectDirectlyFunction · 0.80
BindListenPortMethod · 0.80
GetSockNameMethod · 0.80
NATPMPRequestPortMapFunction · 0.80
PCPRequestPortMapFunction · 0.80

Calls 3

IsIPv4Function · 0.85
IsIPv6Function · 0.85
IsCJDNSFunction · 0.85

Tested by 1

GetSockNameMethod · 0.64