当前位置: 首页>>代码示例>>Golang>>正文


Golang IPv4.Protocol方法代码示例

本文整理汇总了Golang中code/google/com/p/gopacket/layers.IPv4.Protocol方法的典型用法代码示例。如果您正苦于以下问题:Golang IPv4.Protocol方法的具体用法?Golang IPv4.Protocol怎么用?Golang IPv4.Protocol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在code/google/com/p/gopacket/layers.IPv4的用法示例。


在下文中一共展示了IPv4.Protocol方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Unshim

/*Unshim removes the shim layer from an IPv4 packet, if it's present.*/
func Unshim(ipLayer *layers.IPv4) *RouteRecord {
	if Shimmed(ipLayer) {
		/*Remove the route record from the payload*/
		ipPayload := bytes.NewBuffer(ipLayer.LayerPayload())
		var rr RouteRecord
		rr.ReadFrom(ipPayload)

		ipLayer.Length -= uint16(rr.Len())
		ipLayer.Protocol = layers.IPProtocol(rr.Protocol)
		ipLayer.Checksum = 0
		ipLayer.Payload = ipPayload.Bytes()

		return &rr
	}

	return nil
}
开发者ID:ThomasJClark,项目名称:cs4404project,代码行数:18,代码来源:shim.go

示例2: Shim

/*Shim inserts the given router into the shim layer route record of the given
IPv4 packet, creating a new route record if it's not already present.*/
func Shim(ipLayer *layers.IPv4, r Router) {
	ipPayload := bytes.NewBuffer(ipLayer.LayerPayload())
	var modifiedIPPayload bytes.Buffer

	var rr RouteRecord

	if Shimmed(ipLayer) {
		rr.ReadFrom(ipPayload)
		ipLayer.Length -= uint16(rr.Len())
	} else {
		rr.Protocol = uint8(ipLayer.Protocol)
	}

	/*Add the specified router to the route record and put the record at the
	beginning of the payload.*/
	rr.AddRouter(r)
	rr.WriteTo(&modifiedIPPayload)
	ipPayload.WriteTo(&modifiedIPPayload)

	ipLayer.Length += uint16(rr.Len())
	ipLayer.Protocol = layers.IPProtocol(IPProtocolAITFRouteRecord)
	ipLayer.Checksum = 0
	ipLayer.Payload = modifiedIPPayload.Bytes()
}
开发者ID:ThomasJClark,项目名称:cs4404project,代码行数:26,代码来源:shim.go


注:本文中的code/google/com/p/gopacket/layers.IPv4.Protocol方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。