Raised This Month: $ Target: $400
 0% 

How to define a large integer?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
wwzw
Member
Join Date: Feb 2009
Old 11-02-2011 , 08:38   How to define a large integer?
Reply With Quote #1

I want to convert ip address to a digital, like this:
PHP Code:
 new ip[16],str[12],str1[4],str2[4],str3[4],str4[4];
 
get_user_ip(ip,15,1);
 
split(ipstr13str12".");
 
split(strstr23str12".");
 
split(strstr33str43".");
 new 
intip str_to_num(str1) * 256 256 256 str_to_num(str2) * 256 256 str_to_num(str3) * 256 str_to_num(str4);
 
result dbi_query(sql,"SELECT `address` FROM `cs_ipdata` WHERE (`ipstart` <= '%d') And (`ipend` >= '%d')",intip,intip); 
But error, please teach me !

Last edited by wwzw; 11-02-2011 at 08:43.
wwzw is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-02-2011 , 09:20   Re: How to define a large integer?
Reply With Quote #2

Explain what exactly you want to do.
__________________
Bugsy is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 11-02-2011 , 09:43   Re: How to define a large integer?
Reply With Quote #3

Check this: http://forums.alliedmods.net/showthr...58#post1529958
My code in that post contains ip_to_num function.
__________________
Impossible is Nothing
Sylwester is offline
wwzw
Member
Join Date: Feb 2009
Old 11-02-2011 , 10:26   Re: How to define a large integer?
Reply With Quote #4

My goal is to convert IP numbers from 0 to 4294967295
However, the default variable is -2147483648 to 2147483647
If the calculation result is greater than 2147483647, the actual output is a negative number:
Actual output = The results - 4294967296
How to set variable unsigned?

Last edited by wwzw; 11-02-2011 at 10:37.
wwzw is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 11-02-2011 , 10:47   Re: How to define a large integer?
Reply With Quote #5

You could store bytes separately and let mysql convert it to a single number or you could store numbers in a string and implement your own * and + operators working on strings, but to me it kinda looks like XY problem: your real goal is probably not to convert ip to unsigned int, but to do something with ip ranges, so why don't you explain what do you want to do with those ips and we will see if there is better solution.
__________________
Impossible is Nothing
Sylwester is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-02-2011 , 10:51   Re: How to define a large integer?
Reply With Quote #6

There is no unsigned data type in Pawn. As Sylwester says, explain better what you want to do, you can accomplish this if you're working with ranges

Easier way to load data into a cell:

new IP[ 1 ]
IP{ 0 } = 128
IP{ 1 } = 12
IP{ 2 } = 221
IP{ 3 } = 125
IP[ 0 ] holds address
__________________

Last edited by Bugsy; 11-02-2011 at 10:53.
Bugsy is offline
wwzw
Member
Join Date: Feb 2009
Old 11-02-2011 , 10:57   Re: How to define a large integer?
Reply With Quote #7

I put the IP address of the data conversion from 0 to 4294967295, stored in a mysql database.
In AMXX, I need to use the player's IP address lookup players come from.
So I need to convert the player's IP address is a positive integer from 0 to 4294967295, to the mysql database queries.
If I can not define variables in AMXX as a large integer or unsigned integer, I may only modify the database of preservation methods to adapt to AMXX.
wwzw is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 11-02-2011 , 11:14   Re: How to define a large integer?
Reply With Quote #8

That's not an explanation I asked for. I'm asking what are you going to do with table full of those converted ips. Why are you using something like this: ... WHERE (`ipstart` <= '%d') And (`ipend` >= '%d') ... ?
__________________
Impossible is Nothing
Sylwester is offline
wwzw
Member
Join Date: Feb 2009
Old 11-02-2011 , 11:33   Re: How to define a large integer?
Reply With Quote #9

My IP address data like this:
0.0.0.0 0.255.255.255 IANA reserved address
......
192.168.0.0 192.168.255.255 Lan
......
Style in the database:
ipfrom ipto address
0 16777215 IANA reserved address
......
3232235520 3232301055 Lan
......

If I want to check the IP address 192.168.1.101 come from.
First I must change 192.168.1.101 converted to digital: 3232235877(192*256*256*256+168*256*256+1*256+ 101), and then query the database to get the final result is "Lan"

Last edited by wwzw; 11-02-2011 at 11:34.
wwzw is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-02-2011 , 11:36   Re: How to define a large integer?
Reply With Quote #10

So do you only want to verify if two parts of IP are same? 192.168.x.x?
__________________
Bugsy is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:22.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode