long2ip()

The long2ip() function converts an integer to an IPv4 address string.

Syntax

long2ip(N)

Parameters

N
The integer to convert to an IPv4 address. Accepts 32-bit integer (integer) and 64-bit integer (long) types.

Description

The long2ip() function converts an integer to an IPv4 address string. It is the inverse of the ip2long() function. The integer value is decomposed into four octets and returned as a dotted-decimal notation string.

Returns null if the input is not an integer type or if conversion fails. Returns null if N is null.

Error codes

N/A

Usage examples

To prepare the WEB_APACHE_SAMPLE table used in these examples, refer to Preparing sample data.

  1. Convert the source IP address to an integer and then restore it as an IP address.

    table limit=5 WEB_APACHE_SAMPLE | eval n = ip2long(src_ip), result = long2ip(n)
    | fields src_ip, n, result
    
  2. Convert a signed 32-bit integer to an IP address.

    json "{}" | eval ip = long2ip(-1073741311)
    | # ip: 192.0.2.1
    
  3. NULL input

    json "{}" | eval ip = long2ip(null)
    | # ip: null
    

Compatibility

The long2ip() function has been available since before Sonar 4.0.