converting Integers (ip addess) to decimal in Data Grid

tmehmet used Ask the Experts™

I have a Snort IDS sensor sending logs to a MySQL DB.
I created a VB GUI using .NET to query the DB but for some reason I am having trouble. (x2 !)

Firstly - there are two columns for source and Destination IP ( field type is INT(10)UNSIGNED ) which when specifed with SELECT statement, it throws up a

'System.Overflowexecption' and additional info says 'Value was either too large or too small for an Int32

When I select just one of the IP fields it comes back with a list of integers as expected.

Other question - how do you convert the Integers for the IP address in MySQL DB to a decimal format and put it into a DataGrid in .NET

thanks in Advance. I sure this is a easy one for you guy's.


ps. I am a complete fool when it comes to programming - I have not added anything manually to the above at all in the VB scripts, it only has whatever .NET put into it!!
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
sorry not used mySQL however you may need to clarify some points

how big is an int(10)unsigned is that 10bytes? if so why so big and ip address will easily fit into a 4 byte integer or a 15 byte string (15 chars) 0xFF,0xFF,0xFF,0xFF - 4 bytes

so if that is the case I am not surprised that there was an overflow


Thanks Shaun, just before I got your e-mail I started changing those very parameters and the Exceptions disappeared.

As for the DB schema - well thats what the guy's give you from Snort, your guess is as good as mine on their decision making for those integers. Maybe they are planning for IPv6 : )

I'm only left with one problem now, how to convert/format those integers into decimal IP address. In Perl and PHP it was very easy but this VB stuff is new to me.

Any help would be appreciated.


try this

Public Sub uwSplit(ByVal w As Long, a As Byte, b As Byte, c As Byte, d As Byte)
    a = CByte(((w And &HFF000000) \ &H1000000) And &HFF)
    b = CByte(((w And &HFF0000) \ &H10000) And &HFF)
    c = CByte(((w And &HFF00) \ &H100) And &HFF)
    d = CByte((w And &HFF) And &HFF)
End Sub

should take a long such as &H8FFFFFFF (note this is a negative one) and convert it to bytes eg

  x = &H8FFFFFFF
  uwSplit x, a, b, c, d



Many thanks

I also note there is a command that mysql has to convert those numbers to ip address as well;


so we have two options !!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial