<!--
{
  "availability" : [
    "iOS: 2.0.0 - 27.0.0",
    "iPadOS: 2.0.0 - 27.0.0",
    "macCatalyst: 13.1.0 - 27.0.0",
    "macOS: 10.2.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/CFNetServiceCreate(_:_:_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "CFNetwork"
    ],
    "preciseIdentifier" : "c:@F@CFNetServiceCreate"
  },
  "title" : "CFNetServiceCreate(_:_:_:_:_:)"
}
-->

# CFNetServiceCreate(_:_:_:_:_:)

Creates an instance of a Network Service object.

```
func CFNetServiceCreate(_ alloc: CFAllocator?, _ domain: CFString, _ serviceType: CFString, _ name: CFString, _ port: Int32) -> Unmanaged<CFNetService>
```

## Parameters

`alloc`

The allocator to use to allocate memory for the new object. Pass `NULL` or <doc://com.apple.documentation/documentation/CoreFoundation/kCFAllocatorDefault> to use the current default allocator.

`domain`

The domain in which the CFNetService is to be registered; cannot be `NULL`. Call [`CFNetServiceBrowserCreate(_:_:_:)`](/documentation/CFNetwork/CFNetServiceBrowserCreate(_:_:_:)) and [`CFNetServiceBrowserSearchForDomains(_:_:_:)`](/documentation/CFNetwork/CFNetServiceBrowserSearchForDomains(_:_:_:)) to get the registration domain.

`name`

A unique name if the instance will be used to register a service. The name will become part of the instance name in the DNS records that will be created when the service is registered. If the instance will be used to resolve a service, the name should be the name of the machine or service that will be resolved.

`port`

Local IP port, in host byte order, on which this service accepts connections. Pass zero to get placeholder service. With a placeholder service, the service will not be discovered by browsing, but a name conflict will occur if another client tries to register the same name. Most applications do not need to use placeholder service.

## Return Value

A new net service object, or `NULL` if the instance could not be created. Ownership follows the [The Create Rule](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/Ownership.html#//apple_ref/doc/uid/20001148-103029).

## Discussion

If the service depends on information in DNS TXT records, call `CFNetServiceSetProtocolSpecificInformation`.

If the CFNetService is to run in asynchronous mode, call [`CFNetServiceSetClient(_:_:_:)`](/documentation/CFNetwork/CFNetServiceSetClient(_:_:_:)) to prepare the service for running in asynchronous mode. Then call [`CFNetServiceScheduleWithRunLoop(_:_:_:)`](/documentation/CFNetwork/CFNetServiceScheduleWithRunLoop(_:_:_:)) to schedule the service on a run loop. Then call [`CFNetServiceRegister`](/documentation/CFNetwork/CFNetServiceRegister) to make the service available.

If the CFNetService is to run in synchronous mode, call [`CFNetServiceRegister`](/documentation/CFNetwork/CFNetServiceRegister).

To terminate a service that is running in asynchronous mode, call [`CFNetServiceCancel(_:)`](/documentation/CFNetwork/CFNetServiceCancel(_:)) and [`CFNetServiceUnscheduleFromRunLoop(_:_:_:)`](/documentation/CFNetwork/CFNetServiceUnscheduleFromRunLoop(_:_:_:)).

To terminate a service that is running in synchronous mode, call [`CFNetServiceCancel(_:)`](/documentation/CFNetwork/CFNetServiceCancel(_:)).

### Special Considerations

This function is thread safe.

---

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)