Skip to forum content

You are not logged in. Please login or register.


forums.pvpgn.pro → [EN] The Source Code → [Solved] Command restrict for IP

Pages 1

You must login or register to post a reply

RSS topic feed

Posts: 9

1

Topic: [Solved] Command restrict for IP

Hi
I need help with this code, cannot seem to find the errors. sad

static int _handle_host_command(t_connection * c, char const * text)
{
    unsigned int  i;
    unsigned int slvl;
    unsigned int check; 
    t_message *  message;
    t_connection *    user;
    char const *    channel;
    struct in_addr addr;
    unsigned int ip;

     ip = conn_get_addr(c);
     ip = ntohl(addr.s_addr);

     //check if users ip matches 192.168.x.x
     if (ip & 0xFFFF0000 == 0xC0A80000)
    {
        message_send_text(c,message_type_error,c,"Command is reserved for local clients only.");
        return 0;
    }
}

Example:
If user types /host, and the users IP doesn't match 192.168.x.x an error code should be sent saying "Command is reserved for local clients only." But if the IP matches the 192.168.x.x - no error should be displayed and continue using the correct output of the command.

2

Re: [Solved] Command restrict for IP

You have to use mask 13 (not 16) to cover more addresses of range 192.168.x.x (524285 vs 65533).
The condition should be:

if (ip & 0xFFF80000 != 0xC0A80000)
Do not ask for support in PM.

3

Re: [Solved] Command restrict for IP

Is the code correct? especially the ip integer.
Please correct my code if possible will be appreciated

4

Re: [Solved] Command restrict for IP

I'm not sure about "ntohl". Try with and without this conversion.

Do not ask for support in PM.

5

Re: [Solved] Command restrict for IP

I wasn't sure if I should use ntohl or inet_aton as a string to declare the ip range.

6

Re: [Solved] Command restrict for IP

In the above code line "ip = ntohl(addr.s_addr);" is wrong. But if you want to declare the ip range as a string, you can use these functions of course.

Do not ask for support in PM.

7 (edited by DropDead 19.07.2014 23:52)

Re: [Solved] Command restrict for IP

Ok Im going to try the code you gave me, will reply with the results in a few.

8

Re: [Solved] Command restrict for IP

One more correction - the bitwise operation must be in brackets:

if ((ip & 0xFFF80000) != 0xC0A80000)
Do not ask for support in PM.

9

Re: [Solved] Command restrict for IP

Command is working after I did a test on 127.0.0.1 & 192.168.x.x... Thanks harpywar. I actually had the bitwise like that then I changed it, was probably the mask giving out problems.

Posts: 9

Pages 1

You must login or register to post a reply

Who now at forum

Currently view post: 1 guest, 0 registered users

forums.pvpgn.pro → [EN] The Source Code → [Solved] Command restrict for IP