Stored Procedures [dbo].[tng_ipstr2iphex]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
Parameters
NameData TypeMax Length (Bytes)Direction
@ipaddr_strchar(15)15
@ipaddr_hexbinary(4)4Out
Permissions
TypeActionOwning Principal
GrantExecuteuniadmin
GrantExecutewvadmin
SQL Script
/****** Object:  Stored Procedure dbo.tng_ipstr2iphex    Script Date: 12/1/2005 11:49:13 PM ******/


CREATE procedure tng_ipstr2iphex @ipaddr_str char(15), @ipaddr_hex binary(4) OUTPUT
as
    declare @ipaddr float, @ipbyte int, @temp char(25), @ch char(1), @ipaddr_int int

    if (@ipaddr_str = NULL)
    begin
        select @ipaddr_hex = NULL
        return
    end
    select @ipaddr = 0, @ipbyte = 0, @temp = ltrim(@ipaddr_str)

    while  @ipaddr >= 0
    begin
        select @ch = substring( @temp, 1, 1 )
        if @ch = '.'
        begin
            select @ipaddr = (@ipaddr + @ipbyte) * 256
            select @ipbyte = 0
        end
        else if @ch between '0' and '9'
            select @ipbyte = (@ipbyte * 10) + (ASCII( @ch ) - ASCII( '0' ))
        else
        begin
            select @ipaddr = @ipaddr + @ipbyte
            if @ipaddr > 2147483647.0
            begin
                select @ipaddr = - (4294967295.0 - @ipaddr + 1)
            end
            select @ipaddr_int = convert(int, @ipaddr)
            select @ipaddr_hex = convert(binary(4), @ipaddr_int)
            return
        end
        select @temp = stuff( @temp, 1, 1, ' ' )
        select @temp = ltrim(@temp)
    end
GO
GRANT EXECUTE ON  [dbo].[tng_ipstr2iphex] TO [uniadmin]
GRANT EXECUTE ON  [dbo].[tng_ipstr2iphex] TO [wvadmin]
GO
Uses