[#CService]
= CService
:mrdocs:

A combination of a network address (CNetAddr) and a (TCP) port

== Synopsis

Declared in `&lt;netaddress&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
class CService
    : public xref:CNetAddr.adoc[CNetAddr]
----

== Base Classes

[cols="1,4"]
|===
| Name| Description
| `xref:CNetAddr.adoc[CNetAddr]`
| Network address&period;
|===

== Types

[cols="1,4"]
|===
| Name| Description
| xref:CNetAddr/SerParams.adoc[`SerParams`] 
| Serialization parameters selecting the address wire encoding&period;
|===


== Enums

[cols="1,4"]
|===
| Name| Description
| xref:CNetAddr/BIP155Network.adoc[`BIP155Network`] 
| BIP155 network ids recognized by this software&period;
| xref:CNetAddr/Encoding.adoc[`Encoding`] 
| Wire encoding used when (un)serializing an address&period;
|===


== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:CService/2constructor-045.adoc[`CService`]         [.small]#[constructor]#
| Constructors
| xref:CNetAddr/GetAddrBytes.adoc[`GetAddrBytes`] 
| Get the raw address bytes&period;
| xref:CNetAddr/GetIn6Addr.adoc[`GetIn6Addr`] 
| Fill an in6&lowbar;addr with this address&apos;s IPv6 value&period;
| xref:CNetAddr/GetInAddr.adoc[`GetInAddr`] 
| Fill an in&lowbar;addr with this address&apos;s IPv4 value&period;
| xref:CService/GetKey.adoc[`GetKey`] 
| Get a unique key identifying this service (address and port)&period;
| xref:CNetAddr/GetLinkedIPv4.adoc[`GetLinkedIPv4`] 
| For IPv4, mapped IPv4, SIIT translated IPv4, Teredo, 6to4 tunneled addresses, return the relevant IPv4 address as a uint32&period;
| xref:CNetAddr/GetNetClass.adoc[`GetNetClass`] 
| Get the network class used for grouping this address&period;
| xref:CNetAddr/GetNetwork.adoc[`GetNetwork`] 
| Get the network this address belongs to&period;
| xref:CService/GetPort.adoc[`GetPort`] 
| Get the TCP port in host byte order&period;
| xref:CNetAddr/GetReachabilityFrom.adoc[`GetReachabilityFrom`] 
| Calculate how reachable this address is from a given peer address&period;
| xref:CService/GetSAFamily.adoc[`GetSAFamily`] 
| Get the address family
| xref:CService/GetSockAddr.adoc[`GetSockAddr`] 
| Fill a sockaddr structure with this service&apos;s address and port&period;
| xref:CNetAddr/HasCJDNSPrefix.adoc[`HasCJDNSPrefix`] 
| Whether the raw address begins with the CJDNS prefix byte&period;
| xref:CNetAddr/HasLinkedIPv4.adoc[`HasLinkedIPv4`] 
| Whether this address has a linked IPv4 address (see GetLinkedIPv4())&period;
| xref:CNetAddr/IsAddrV1Compatible.adoc[`IsAddrV1Compatible`] 
| Check if the current object can be serialized in pre&hyphen;ADDRv2&sol;BIP155 format&period;
| xref:CNetAddr/IsBindAny.adoc[`IsBindAny`] 
| Whether this address is the INADDR&lowbar;ANY &sol; &quot;bind any&quot; wildcard address&period;
| xref:CNetAddr/IsCJDNS.adoc[`IsCJDNS`] 
| Whether this is a CJDNS address&period;
| xref:CNetAddr/IsHeNet.adoc[`IsHeNet`] 
| Whether this is an IPv6 Hurricane Electric address (2001&colon;0470&colon;&colon;&sol;36)&period;
| xref:CNetAddr/IsI2P.adoc[`IsI2P`] 
| Whether this is an I2P address&period;
| xref:CNetAddr/IsIPv4.adoc[`IsIPv4`] 
| Whether this is an IPv4 address (&colon;&colon;FFFF&colon;0&colon;0&sol;96, 0&period;0&period;0&period;0&sol;0)&period;
| xref:CNetAddr/IsIPv6.adoc[`IsIPv6`] 
| Whether this is a native IPv6 address (not mapped IPv4, not Tor)&period;
| xref:CNetAddr/IsInternal.adoc[`IsInternal`] 
| Whether this is an internal (NET&lowbar;INTERNAL) address&period;
| xref:CNetAddr/IsLocal.adoc[`IsLocal`] 
| Whether this is a local (loopback) address&period;
| xref:CNetAddr/IsPrivacyNet.adoc[`IsPrivacyNet`] 
| Whether this object is a privacy network&period; TODO&colon; consider adding IsCJDNS() here when more peers adopt CJDNS, see&colon; https&colon;&sol;&sol;github&period;com&sol;bitcoin&sol;bitcoin&sol;pull&sol;27411&num;issuecomment&hyphen;1497176155
| xref:CNetAddr/IsRFC1918.adoc[`IsRFC1918`] 
| Whether this is an IPv4 private&hyphen;network address (10&sol;8, 192&period;168&sol;16, 172&period;16&sol;12)&period;
| xref:CNetAddr/IsRFC2544.adoc[`IsRFC2544`] 
| Whether this is an IPv4 inter&hyphen;network benchmarking address (198&period;18&period;0&period;0&sol;15)&period;
| xref:CNetAddr/IsRFC3849.adoc[`IsRFC3849`] 
| Whether this is an IPv6 documentation address (2001&colon;0DB8&colon;&colon;&sol;32)&period;
| xref:CNetAddr/IsRFC3927.adoc[`IsRFC3927`] 
| Whether this is an IPv4 link&hyphen;local autoconfig address (169&period;254&period;0&period;0&sol;16)&period;
| xref:CNetAddr/IsRFC3964.adoc[`IsRFC3964`] 
| Whether this is an IPv6 6to4 tunnelling address (2002&colon;&colon;&sol;16)&period;
| xref:CNetAddr/IsRFC4193.adoc[`IsRFC4193`] 
| Whether this is an IPv6 unique&hyphen;local address (FC00&colon;&colon;&sol;7)&period;
| xref:CNetAddr/IsRFC4380.adoc[`IsRFC4380`] 
| Whether this is an IPv6 Teredo tunnelling address (2001&colon;&colon;&sol;32)&period;
| xref:CNetAddr/IsRFC4843.adoc[`IsRFC4843`] 
| Whether this is an IPv6 ORCHID (deprecated) address (2001&colon;10&colon;&colon;&sol;28)&period;
| xref:CNetAddr/IsRFC4862.adoc[`IsRFC4862`] 
| Whether this is an IPv6 link&hyphen;local autoconfig address (FE80&colon;&colon;&sol;64)&period;
| xref:CNetAddr/IsRFC5737.adoc[`IsRFC5737`] 
| Whether this is an IPv4 documentation address (192&period;0&period;2&sol;24, 198&period;51&period;100&sol;24, 203&period;0&period;113&sol;24)&period;
| xref:CNetAddr/IsRFC6052.adoc[`IsRFC6052`] 
| Whether this is an IPv6 well&hyphen;known prefix for IPv4&hyphen;embedded addresses (64&colon;FF9B&colon;&colon;&sol;96)&period;
| xref:CNetAddr/IsRFC6145.adoc[`IsRFC6145`] 
| Whether this is an IPv6 IPv4&hyphen;translated address (&colon;&colon;FFFF&colon;0&colon;0&colon;0&sol;96)&period;
| xref:CNetAddr/IsRFC6598.adoc[`IsRFC6598`] 
| Whether this is an IPv4 ISP&hyphen;level NAT (shared) address (100&period;64&period;0&period;0&sol;10)&period;
| xref:CNetAddr/IsRFC7343.adoc[`IsRFC7343`] 
| Whether this is an IPv6 ORCHIDv2 address (2001&colon;20&colon;&colon;&sol;28)&period;
| xref:CNetAddr/IsRelayable.adoc[`IsRelayable`] 
| Whether this address should be relayed to other peers even if we can&apos;t reach it ourselves&period;
| xref:CNetAddr/IsRoutable.adoc[`IsRoutable`] 
| Whether this address is publicly routable&period;
| xref:CNetAddr/IsTor.adoc[`IsTor`] 
| Whether this is a Tor onion address&period;
| xref:CNetAddr/IsValid.adoc[`IsValid`] 
| Whether this address is valid&period;
| xref:CNetAddr/SetIP.adoc[`SetIP`] 
| Copy the address value from another CNetAddr&period;
| xref:CNetAddr/SetInternal.adoc[`SetInternal`] 
| Set this address to an internal address derived from a string or FQDN&period;
| xref:CNetAddr/SetLegacyIPv6.adoc[`SetLegacyIPv6`] 
| Set from a legacy IPv6 address&period; Legacy IPv6 address may be a normal IPv6 address, or another address (e&period;g&period; IPv4) disguised as IPv6&period; This encoding is used in the legacy `addr` encoding&period;
| xref:CService/SetSockAddr.adoc[`SetSockAddr`] 
| Set CService from a network sockaddr&period;
| xref:CNetAddr/SetSpecial.adoc[`SetSpecial`] 
| Parse a Tor or I2P address and set this object to it&period;
| xref:CNetAddr/ToStringAddr.adoc[`ToStringAddr`] 
| Get the address as a human&hyphen;readable string, without a port&period;
| xref:CService/ToStringAddrPort.adoc[`ToStringAddrPort`] 
| Get a human&hyphen;readable representation of the address and port&period;
|===


== Static Data Members

[cols="1,4"]
|===
| Name| Description
| xref:CNetAddr/V1.adoc[`V1`] 
| Serialization parameters for the legacy ADDRv1 encoding&period;
| xref:CNetAddr/V2.adoc[`V2`] 
| Serialization parameters for the BIP155 ADDRv2 encoding&period;
|===


== Protected Data Members

[cols="1,4"]
|===
| Name| Description
| xref:CNetAddr/m_addr.adoc[`m&lowbar;addr`] 
| Raw representation of the network address&period; In network byte order (big endian) for IPv4 and IPv6&period;
| xref:CNetAddr/m_net.adoc[`m&lowbar;net`] 
| Network to which this address belongs&period;
| xref:CNetAddr/m_scope_id.adoc[`m&lowbar;scope&lowbar;id`] 
| Scope id if scoped&sol;link&hyphen;local IPV6 address&period; See https&colon;&sol;&sol;tools&period;ietf&period;org&sol;html&sol;rfc4007
| xref:CService/port.adoc[`port`] 
| TCP port number, in host byte order&period;
|===


== Friends

[cols="1,4"]
|===
| Name| Description
| `xref:MaybeFlipIPv6toCJDNS.adoc[MaybeFlipIPv6toCJDNS]`
| If an IPv6 address belongs to the address range used by the CJDNS network and the CJDNS network is reachable (&hyphen;cjdnsreachable config is set), then change the type from NET&lowbar;IPV6 to NET&lowbar;CJDNS&period;
| `xref:CServiceHash.adoc[CServiceHash]`
| Hasher for CService, suitable for use with unordered containers&period;
| `xref:operator_lt-07a.adoc[operator&lt;]`
| Order two services&period;
| `xref:operator_eq-007e.adoc[operator&equals;&equals;]`
| Compare two services for equality&period;
|===

== Non-Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:AddLocal-0ab.adoc[`AddLocal`]
| Record a local address that we may advertise, scored by nScore&period;
| xref:AddLocal-0af.adoc[`AddLocal`]
| Record a local address (with port) that we may advertise, scored by nScore&period;
| xref:ConnectDirectly-0c.adoc[`ConnectDirectly`]
| Create a socket and try to connect to the specified service, using the provided timeout&period;
| xref:ConnectDirectly-0e.adoc[`ConnectDirectly`]
| Create a socket and try to connect to the specified service&period;
| xref:DefaultOnionServiceTarget.adoc[`DefaultOnionServiceTarget`]
| Build the default local target address for the onion service&period;
| xref:GetBindAddress.adoc[`GetBindAddress`]
| Get the bind address for a socket as CService&period;
| xref:GetLocalAddrForPeer.adoc[`GetLocalAddrForPeer`]
| Returns a local address that we should advertise to this peer&period;
| xref:GetLocalAddress.adoc[`GetLocalAddress`]
| Return the best local address to use when talking to the given peer&period;
| xref:IsLocal.adoc[`IsLocal`]
| Return whether the given address is one of our known local addresses&period;
| xref:IsProxy.adoc[`IsProxy`]
| Check whether an address is one of the configured proxies&period;
| xref:Lookup-04.adoc[`Lookup`]
| Resolve a service string to its corresponding service&period;
| xref:Lookup-0b.adoc[`Lookup`]
| Resolve a service string to its first corresponding service&period;
| xref:LookupNumeric.adoc[`LookupNumeric`]
| Resolve a service string with a numeric IP to its first corresponding service&period;
| xref:NATPMPRequestPortMap.adoc[`NATPMPRequestPortMap`]
| Try to open a port using RFC 6886 NAT&hyphen;PMP&period; IPv4 only&period;
| xref:RemoveLocal.adoc[`RemoveLocal`]
| Forget a previously recorded local address&period;
| xref:SeenLocal.adoc[`SeenLocal`]
| Mark a local address as having been seen, returning whether it was already known&period;
| xref:operator_lt-0c.adoc[`operator&lt;`]
| Order two addresses&period;
| xref:operator_eq-0d.adoc[`operator&equals;&equals;`]
| Compare two addresses for equality&period;
|===

== Derived Classes

[cols="1,4"]
|===
| Name| Description
| xref:CAddress.adoc[`CAddress`] 
| A CService with information about it as peer
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
