开发者

Help out a beginner with MySQL docs byte definitions

开发者 https://www.devze.com 2023-02-10 09:48 出处:网络
http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#function_inet-ato开发者_如何学Gon

http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#function_inet-ato开发者_如何学Gon

I want to store users IP's in numerical values in my db. The docs says the following about the INET_ATON function:

Given the dotted-quad representation of a network address as a string, returns an integer that represents the numeric value of the address. Addresses may be 4- or 8-byte addresses.

What on earth does this mean? And what length should my unsigned int field be for storing these values?

Thanks for your time!


IPv4 uses 32-bit (four-byte) addresses,
which limits the address space to 4,294,967,296 (232)

example:

create table ip ( ip int(10) unsigned default 0);
insert into ip values ( inet_aton('255.255.255.255')), (inet_aton('0.0.0.0'));
select * from ip;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号