Representing IPv4/IPv6 addresses in Oracle -


in oracle, appropriate data type or technique representing network addresses, addresses may ipv4 or ipv6?

background: i'm converting table recording network activity, built using postgresql inet data type hold both v4 , v6 addresses in same table.

no row contains both v4 , v6 addresses, however. (that is, record either machine's v4 stack, or machine's v6 stack.)

in oracle, appropriate data type or technique representing network addresses, addresses may ipv4 or ipv6

there 2 approaches :

  1. storing only.
  2. storing conventional representation

for storing only. ipv4 address should integer (32bits enough). ip v6, 128 bits, integer (which similar number(38)) do. of course, that's storing. approach takes view representation matter application.

if 1 take opposite strategy, of storing conventional representation, 1 needs make sure ip v4 , ipv6 addresses have 1 conventional (string) representation. it's well-known ipv4. ipv6, there standard format.

my preference goes first strategy. in worst case, can adopt hybrid approach (non acid though) , store both binary , ascii representation side side "priority" binary value.

no row contains both v4 , v6 addresses, however.

the standard representation of ipv4 address in ipv6 format : ::ffff:192.0.2.128.

i don't know context reserve 2 columns, 1 ipv4 , other distinct ipv6 address.

update
following comment @sleepymonad's, i'd point out instead of number data type preferable use integer data type, happily accommodate highest possible value can expressed 128 bits integer 'ff...ff' (which need 39 decimal digits). 38 highest power of ten ranging 0 9 can encoded on 128 bits 1 can still insert maximum unsigned value 2**128 - 1 (decimal 340282366920938463463374607431768211455). here small test illustrate possibility.

create table test (   id integer primary key,   ipv6_address_bin integer );  -- let's enter 2**128 - 1 in nueric field insert test (id, ipv6_address_bin) values ( 1, to_number ( 'ffffffffffffffffffffffffffffffff', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') ) ;  -- retrieve make sure it's not "truncated". select to_char ( ipv6_address_bin, 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' ) test id = 1 ; -- yields 'ffffffffffffffffffffffffffffffff'  select to_char ( ipv6_address_bin ) test id = 1 ; -- yields 340282366920938463463374607431768211455  select log(2, ipv6_address_bin) test id = 1 ; -- yields 128  select log(10, ipv6_address_bin) test id = 1 ; -- yields > 38 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -