Test Foro de elhacker.net SMF 2.1

Programación => .NET (C#, VB.NET, ASP) => Programación General => Programación Visual Basic => Mensaje iniciado por: Karcrack en 26 Junio 2010, 13:50 PM

Título: [VB-SNIPPET] htons() replacement
Publicado por: Karcrack en 26 Junio 2010, 13:50 PM
Código (vb) [Seleccionar]
Public Function htons(ByVal lPort As Long) As Integer
   htons = ((((lPort And &HFF000000) \ &H1000000) And &HFF&) Or ((lPort And &HFF0000) \ &H100&) Or ((lPort And &HFF00&) * &H100&) Or ((lPort And &H7F&) * &H1000000) Or (IIf((lPort And &H80&), &H80000000, &H0)) And &HFFFF0000) \ &H10000
End Function


He hecho esta alternativa a htons@Ws2_32 (http://msdn.microsoft.com/en-us/library/ms738557%28VS.85%29.aspx) para un Shell que estoy haciendo y he pensado que os seria util.
La alternativa la he hecho para quitarme la declaracion de esa API, que siempre puede ser algo sospechosa :P

Simplemente lo que hace la funcion es revertir el orden de bytes y devolver solo el Integer significante... Por ejemplo:
Citar666 decimal = 00000029A hexadecimal
Se invierten los bytes de orden: 9A020000
Y se devuelve el Integer (2 BYTES) mas significante, 9A02

Referencias:
http://www.xbeat.net/vbspeed/c_SwapEndian.htm
http://www.xbeat.net/vbspeed/c_HiWord.htm


Saludos :D
Título: Re: [VB-SNIPPET] htons() replacement
Publicado por: LeandroA en 26 Junio 2010, 23:15 PM
Muy buen tip Karcrack

Saludos.