Skip to content

Eggbertx/sqlite-inet6

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sqlite-inet

This SQLite extension provides inet_aton(), inet_ntoa, inet6_aton(), and inet6_ntoa() functions for converting IP addresses to and from strings. The function inet_ntoa accepts integers as input, but inet6_ntoa does not.

Usage

$ make
$ sqlite3
sqlite> .load bin/inet6
sqlite> select inet_ntoa(3232235777);
192.168.1.1
sqlite> select inet6_aton('192.168.1.3') > inet6_aton('192.168.1.1');
1
sqlite> select inet6_aton('192.168.1.3') < inet6_aton('192.168.1.1');
0
sqlite> create table ip_addrs (id integer primary key, ip varbinary(16));
sqlite> insert into ip_addrs values (1, inet6_aton('2607:f8b0:400a:808::200e'));
sqlite> insert into ip_addrs values (2, inet6_aton('2607::1'));
sqlite> insert into ip_addrs values (3, inet6_aton('192.168.1.1'));
sqlite> select inet6_ntoa(ip) from ip_addrs where ip > inet6_aton('2607:f800::');
2607:f8b0:400a:808::200e

Misc

The functions behave like their MariaDB analogs, that is, they expect integers in host byte order, rather than network byte order as expected by C functions. For more info, see this bug report.

Like their MariaDB analogs, when invoked with NULL or incorrect data (invalid IP string or incorrect type), NULL is returned.

About

Converting IP addresses between string and numeric representation in sqlite (with added IPv6 support)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • C 63.1%
  • Shell 33.8%
  • Makefile 3.1%