Hello P,

Friday, August 24, 2001, P lerenard <[EMAIL PROTECTED]> wrote:

Pl> I can transform an ip a1.a2.a3.a4 to an integer using
Pl> b1=a1 << 24
Pl> b2=a2 << 16
Pl> b3=a3 << 8
Pl> int =b1+b2+b3+a4
Pl> now I want to do the opposite.
Pl> how can I get a1.a2.a3.a4 from this integer?
Pl> ok I get a1, but I start to have a headeach to get the rest
if you interested in ip addresses conversions, you can use
use Socket;

    sub ip2ul {
        return inet_aton($_[0]);
    }

    sub ul2ip {
        return inet_ntoa($_[0]);
    }

or something like this:
sub ip2ul {
   return unpack( 'N', pack( 'C4', split( /\./, shift ) ) );
}
sub ul2ip {
   return join( '.', unpack( 'C4', pack( 'N', shift ) ) );
}

(receipts stolen from russian fido7.ru.perl group)

Best wishes,
 Maxim                            mailto:[EMAIL PROTECTED]



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to