<!--
{
  "availability" : [
    "iOS: 2.0.0 - 27.0.0",
    "iPadOS: 2.0.0 - 27.0.0",
    "macCatalyst: 13.1.0 - 27.0.0",
    "macOS: 10.5.0 - 27.0.0",
    "tvOS: 9.0.0 - 27.0.0",
    "visionOS: 1.0.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "CFNetwork",
  "identifier" : "/documentation/CFNetwork/CFNetServiceGetPortNumber(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "CFNetwork"
    ],
    "preciseIdentifier" : "c:@F@CFNetServiceGetPortNumber"
  },
  "title" : "CFNetServiceGetPortNumber(_:)"
}
-->

# CFNetServiceGetPortNumber(_:)

This function gets the port number from a CFNetService.

```
func CFNetServiceGetPortNumber(_ theService: CFNetService) -> Int32
```

## Parameters

`theService`

The CFNetService whose protocol-specific information is to be obtained; cannot be `NULL`. Note that in order to get protocol-specific information, you must resolve `theService` by calling [`CFNetServiceResolve`](/documentation/CFNetwork/CFNetServiceResolve) or [`CFNetServiceResolveWithTimeout(_:_:_:)`](/documentation/CFNetwork/CFNetServiceResolveWithTimeout(_:_:_:)) before calling this function.

## Return Value

The port number of the service.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)