如何在tcl中将网络转换为主机地址

时间:2016-04-28 03:18:47

标签: tcl

在tcl中转换此代码以及如何在tcl

中创建一个函数network来托管
capturedTlpData[i] = (UInt32)IPAddress.NetworkToHostOrder(BitConverter.ToInt32((byte[])retValbuffer,i*4));

这里NetworkToHostOrder是: - `

public static int NetworkToHostOrder(int network`)

1 个答案:

答案 0 :(得分:1)

您是否以网络端格式从网络中读取了四个字节,并希望将其转换为无符号整数? binary scan命令可以做到这一点。你需要u修饰符,它需要Tcl 8.6。

binary scan $theBytes Iu theValue

例如,如果你有与ASCII abcd对应的字节,那么你得到:

set theBytes "abcd"
binary scan $theBytes Iu theValue
puts $theValue
# Prints 1633837924
puts [format %x $theValue]
# Prints 61626364

如果您使用的是Tcl 8.5,只需使用I说明符并对其进行后处理即可转换为无符号(因为Tcl在内部使用bignums):

set theValue [expr {$theValue & 0xFFFFFFFF}]