當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Client.SendPacket方法代碼示例

本文整理匯總了Golang中github.com/d2g/dhcp4client.Client.SendPacket方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.SendPacket方法的具體用法?Golang Client.SendPacket怎麽用?Golang Client.SendPacket使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/d2g/dhcp4client.Client的用法示例。


在下文中一共展示了Client.SendPacket方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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


注:本文中的github.com/d2g/dhcp4client.Client.SendPacket方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。