---
name: "nng_socket_proto_id"
section: "3"
platform: "linux"
package: "libnng-dev"
version: "1.10.1-2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/nng_socket_proto_id"
---

# nng\_socket\_proto\_id(3)

obtain the socket protocol id

## NAME

nng\_socket\_proto\_id - obtain the socket protocol id

## SYNOPSIS

```
#include <nng/nng.h>
int nng_socket_proto_id(nng_socket s, uint16_t *id);
int nng_socket_peer_id(nng_socket s, uint16_t *id);
```

## DESCRIPTION

These functions store the 16-bit protocol identifier of either the socket *s*, or its natural peer, in *id*.

**Tip**\

These functions should be used in place of the `NNG_OPT_PROTO` and `NNG_OPT_PEER` options in new code.

## RETURN VALUES

These functions return zero on success, or an error if the socket is invalid.

## ERRORS

`NNG_ECLOSED`

Parameter *s* does not refer to an open socket.

## SEE ALSO

[nng\_socket(5)](/nng_socket/5.md), [nng(7)](/nng/7.md)
