當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。