# OpenBSD manual page server

Manual Page Search Parameters

 INET_NET_NTOP(3) Library Functions Manual INET_NET_NTOP(3)

# NAME

`inet_net_ntop`, `inet_net_pton`Internet network number manipulation routines

# SYNOPSIS

```#include <sys/socket.h>```
`#include <arpa/inet.h>`

char *
`inet_net_ntop`(int af, const void *src, int bits, char *dst, size_t size);

int
`inet_net_pton`(int af, const char *src, void *dst, size_t size);

# DESCRIPTION

The () function converts an Internet network number from network format (usually a `struct in_addr` or some other binary form, in network byte order) to CIDR presentation format (suitable for external display purposes). bits is the number of bits in src that are the network number. It returns `NULL` if a system error occurs (in which case, errno will have been set), or it returns a pointer to the destination string.

The () function converts a presentation format Internet network number (that is, printable form as held in a character string) to network format (usually a `struct in_addr` or some other internal binary representation, in network byte order). It returns the number of bits (either computed based on the class, or specified with /CIDR), or -1 if a failure occurred (in which case errno will have been set. It will be set to `ENOENT` if the Internet network number was not valid).

Caution: The dst field should be zeroed before calling () as the function will only fill the number of bytes necessary to encode the network number in network byte order.

The only values for af currently supported are `AF_INET` and `AF_INET6`. size is the size of the result buffer dst.

# NETWORK NUMBERS (IP VERSION 4)

The external representation of Internet network numbers may be specified in one of the following forms:

```a
a.b
a.b.c
a.b.c.d```

Any of the above four forms may have “`/bits`” appended where “`bits`” is in the range `0-32` and is used to explicitly specify the number of bits in the network address. When “`/bits`” is not specified the number of bits in the network address is calculated as the larger of the number of bits in the class to which the address belongs and the number of bits provided rounded up modulo 8. Examples:

an 8-bit network number (class A), value `10.0.0.0`.
a 24-bit network number (class C), value `192.0.0.0`.
a 16-bit network number, value `10.10.0.0`.
a 24-bit network number, value `10.1.2.0`.
a 32-bit network number, value `10.1.2.3`.
a 24-bit network number (explicit), value `10.1.2.3`.

Note that when the number of bits is specified using “`/bits`” notation, the value of the address still includes all bits supplied in the external representation, even those bits which are the host part of an Internet address. Also, unlike inet_pton(3) where the external representation is assumed to be a host address, the external representation for () is assumed to be a network address. Thus “`10.1`” is assumed to be “`10.1.0.0`” not “`10.0.0.1`

All numbers supplied as “parts” in a ‘`.`’ notation may be decimal, octal, or hexadecimal, as specified in the C language (i.e., a leading 0x or 0X implies hexadecimal; otherwise, a leading 0 implies octal; otherwise, the number is interpreted as decimal).

# NETWORK NUMBERS (IP VERSION 6)

See inet_pton(3) for valid external representations of IP version 6 addresses. A valid external representation may have “`/bits`” appended where “`bits`” is in the range `0-128` and is used to explicitly specify the number of bits in the network address. When “`/bits`” is not specified 128 is used. Note that when the number of bits is specified using “`/bits`” notation, the value of the address still includes all bits supplied in the external representation, even those bits which are the host part of an Internet address.

The `inet_net_ntop` and `inet_net_pton` functions first appeared in BIND 4.9.4.
{"ft_lang_label":"__label__en","ft_lang_prob":0.716962,"math_prob":0.9325696,"size":3526,"snap":"2021-43-2021-49","text_gpt3_token_len":957,"char_repetition_ratio":0.15388983,"word_repetition_ratio":0.2322357,"special_character_ratio":0.25836644,"punctuation_ratio":0.14799447,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9653915,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-10-16T06:14:08Z\",\"WARC-Record-ID\":\"<urn:uuid:9d2196d1-64a6-446e-8a1e-050bd253823d>\",\"Content-Length\":\"13636\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:9975941c-6aa9-4526-a2c1-0238f1719fb5>\",\"WARC-Concurrent-To\":\"<urn:uuid:eee0ee1a-1a45-4fe8-91be-0bc48e2832df>\",\"WARC-IP-Address\":\"128.100.17.244\",\"WARC-Target-URI\":\"https://man.openbsd.org/inet_net_ntop.3\",\"WARC-Payload-Digest\":\"sha1:ZYKH52H77IC6KLLO4OXIPEWWHVWFPTU6\",\"WARC-Block-Digest\":\"sha1:YG7L6TFPOWFJHRD4P4QFSHIU3T42HT5I\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-43/CC-MAIN-2021-43_segments_1634323583423.96_warc_CC-MAIN-20211016043926-20211016073926-00469.warc.gz\"}"}