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


Golang dhcp4client.Client类代码示例

本文整理汇总了Golang中github.com/d2g/dhcp4client.Client的典型用法代码示例。如果您正苦于以下问题:Golang Client类的具体用法?Golang Client怎么用?Golang Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: RequestIP

func RequestIP(exampleClient *dhcp4client.Client) dhcp4.Packet {

	// discoveryPacket, _ := exampleClient.SendDiscoverPacket()
	// log.Println("Packet:%v\n", discoveryPacket)

	// offerPacket, _ := exampleClient.GetOffer(&discoveryPacket)
	// log.Println("Packet:%v\n", offerPacket)
	// log.Println("OFFERED:" + offerPacket.YIAddr().String())
	//return offerPacket.YIAddr().String()
	//requestPacket, _ := exampleClient.SendRequest(&offerPacket)
	//log.Println("Packet:%v\n", requestPacket)

	success, acknowledgementpacket, err := exampleClient.Request()
	if err != nil {
		networkError, ok := err.(*net.OpError)
		if ok && networkError.Timeout() {
			log.Println("Test Skipping as it didn't find a DHCP Server")
		}
		log.Println("Error:%v\n", err)
	}
	log.Println("Success:%v\n", success)
	log.Println("Packet:%v\n", acknowledgementpacket)

	return acknowledgementpacket

	// if !success {
	// 	log.Fatalln("We didn't sucessfully get a DHCP Lease?")
	// } else {
	// 	log.Printf("IP Received:%v\n", acknowledgementpacket.YIAddr().String())
	// 	return acknowledgementpacket.YIAddr().String()
	// }
}
开发者ID:dark-lab,项目名称:dhcpkiller,代码行数:32,代码来源:main.go

示例2: renew

func (c *client) renew(cl *dhcp4client.Client) (dhcp4.Packet, error) {
	defer trace.End(trace.Begin(""))

	rp := cl.RenewalRequestPacket(&c.ack)
	rp, err := c.setOptions(rp)
	if err != nil {
		return nil, err
	}

	rp.PadToMinSize()
	if err = cl.SendPacket(rp); err != nil {
		return nil, err
	}

	newack, err := cl.GetAcknowledgement(&rp)
	if err != nil {
		return nil, err
	}

	opts := newack.ParseOptions()
	if dhcp4.MessageType(opts[dhcp4.OptionDHCPMessageType][0]) == dhcp4.NAK {
		return nil, fmt.Errorf("received NAK from DHCP server")
	}

	return newack, nil
}
开发者ID:vmware,项目名称:vic,代码行数:26,代码来源:client.go

示例3: request

func (c *client) request(cl *dhcp4client.Client) (bool, dhcp4.Packet, error) {
	defer trace.End(trace.Begin(""))

	dp, err := c.discoverPacket(cl)
	if err != nil {
		return false, nil, err
	}

	dp.PadToMinSize()
	if err = cl.SendPacket(dp); err != nil {
		return false, nil, err
	}

	var op dhcp4.Packet
	for {
		op, err = cl.GetOffer(&dp)
		if err != nil {
			return false, nil, err
		}

		if c.isCompletePacket(dhcp.NewPacket([]byte(op))) {
			break
		}
	}

	rp, err := c.requestPacket(cl, &op)
	if err != nil {
		return false, nil, err
	}

	rp.PadToMinSize()
	if err = cl.SendPacket(rp); err != nil {
		return false, nil, err
	}

	ack, err := cl.GetAcknowledgement(&rp)
	if err != nil {
		return false, nil, err
	}

	opts := ack.ParseOptions()
	if dhcp4.MessageType(opts[dhcp4.OptionDHCPMessageType][0]) == dhcp4.NAK {
		return false, nil, fmt.Errorf("Got NAK from DHCP server")
	}

	return true, ack, nil
}
开发者ID:vmware,项目名称:vic,代码行数:47,代码来源:client.go

示例4: renew

func (c *client) renew(id ID, ack dhcp4.Packet, cl *dhcp4client.Client) (dhcp4.Packet, error) {
	rp := cl.RenewalRequestPacket(&ack)
	_, err := c.appendOptions(&rp, id)
	if err != nil {
		return nil, err
	}

	rp.PadToMinSize()
	if err = cl.SendPacket(rp); err != nil {
		return nil, err
	}

	newack, err := cl.GetAcknowledgement(&rp)
	if err != nil {
		return nil, err
	}

	opts := newack.ParseOptions()
	if dhcp4.MessageType(opts[dhcp4.OptionDHCPMessageType][0]) == dhcp4.NAK {
		return nil, fmt.Errorf("received NAK from DHCP server")
	}

	return newack, nil
}
开发者ID:kjplatz,项目名称:vic,代码行数:24,代码来源:client.go

示例5: SendDHCPDeclinePacket

func SendDHCPDeclinePacket(c *dhcp4client.Client, hw net.HardwareAddr, ip net.IP, acknowledgement dhcp4.Packet) (dhcp4.Packet, error) {
	DeclinePacket := DHCPDeclinePacket(hw, ip, acknowledgement)
	DeclinePacket.PadToMinSize()

	return DeclinePacket, c.SendPacket(DeclinePacket)
}
开发者ID:dark-lab,项目名称:dhcpkiller,代码行数:6,代码来源:main.go

示例6: requestPacket

func (c *client) requestPacket(cl *dhcp4client.Client, op *dhcp4.Packet) (dhcp4.Packet, error) {
	defer trace.End(trace.Begin(""))

	rp := cl.RequestPacket(op)
	return c.setOptions(rp)
}
开发者ID:vmware,项目名称:vic,代码行数:6,代码来源:client.go

示例7: discoverPacket

func (c *client) discoverPacket(cl *dhcp4client.Client) (dhcp4.Packet, error) {
	defer trace.End(trace.Begin(""))

	dp := cl.DiscoverPacket()
	return c.setOptions(dp)
}
开发者ID:vmware,项目名称:vic,代码行数:6,代码来源:client.go

示例8: requestPacket

func (c *client) requestPacket(id ID, cl *dhcp4client.Client, op *dhcp4.Packet) (*dhcp4.Packet, error) {
	rp := cl.RequestPacket(op)
	return c.appendOptions(&rp, id)
}
开发者ID:kjplatz,项目名称:vic,代码行数:4,代码来源:client.go

示例9: discoverPacket

func (c *client) discoverPacket(id ID, cl *dhcp4client.Client) (*dhcp4.Packet, error) {
	dp := cl.DiscoverPacket()
	return c.appendOptions(&dp, id)
}
开发者ID:kjplatz,项目名称:vic,代码行数:4,代码来源:client.go


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