<!--
{
  "availability" : [
    "macOS: 10.0.0 - 10.13.0"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSSocketPortNameServer/portForName:host:nameServerPortNumber:",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSSocketPortNameServer(im)portForName:host:nameServerPortNumber:"
  },
  "title" : "portForName:host:nameServerPortNumber:"
}
-->

# portForName:host:nameServerPortNumber:

Looks up and returns the port registered under the specified name on a specified host.

```
- (NSPort *) portForName:(NSString *) name host:(NSString *) host nameServerPortNumber:(uint16_t) portNumber;
```

## Parameters

`name`

The name of the desired port.

`host`

The name of the host. `hostName` is an Internet domain name (for example, “`sales.anycorp.com`”) or IP address (IPv4 or IPv6). If `hostName` is `nil` or empty, the local host is checked. If `hostName` is `@”*”`, all hosts on the local network are checked.

`portNumber`

The `portNumber` parameter is ignored.

## Return Value

The port associated with `portName` on the host `hostName`. Returns `nil` if no such port exists.

## See Also

[`- (BOOL) registerPort:(NSPort *) port name:(NSString *) name nameServerPortNumber:(uint16_t) portNumber;`](/documentation/Foundation/NSSocketPortNameServer/registerPort:name:nameServerPortNumber:)

Registers a given port as a network service with the specified name in the local domain.



---

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)