- 论坛徽章:
- 0
|
在内核文件ipconfig.c里找到了这么一段,不知道该怎么设置dhcp
/*
* Send DHCP/BOOTP request to single interface.
*/
static void __init ic_bootp_send_if(struct ic_device *d, unsigned long jiffies_diff)
{
struct net_device *dev = d->dev;
struct sk_buff *skb;
struct bootp_pkt *b;
struct iphdr *h;
/* Allocate packet */
skb = alloc_skb(sizeof(struct bootp_pkt) + LL_ALLOCATED_SPACE(dev) + 15,
GFP_KERNEL);
if (!skb)
return;
skb_reserve(skb, LL_RESERVED_SPACE(dev));
b = (struct bootp_pkt *) skb_put(skb, sizeof(struct bootp_pkt));
memset(b, 0, sizeof(struct bootp_pkt));
/* Construct IP header */
skb_reset_network_header(skb);
h = ip_hdr(skb);
h->version = 4;
h->ihl = 5;
h->tot_len = htons(sizeof(struct bootp_pkt));
h->frag_off = htons(IP_DF);
h->ttl = 64;
h->protocol = IPPROTO_UDP;
h->daddr = htonl(INADDR_BROADCAST);
h->check = ip_fast_csum((unsigned char *) h, h->ihl);
/* Construct UDP header */
b->udph.source = htons(6 ;
b->udph.dest = htons(67);
b->udph.len = htons(sizeof(struct bootp_pkt) - sizeof(struct iphdr));
/* UDP checksum not calculated -- explicitly allowed in BOOTP RFC */
/* Construct DHCP/BOOTP header */
b->op = BOOTP_REQUEST;
if (dev->type < 256) /* check for false types */
b->htype = dev->type;
else if (dev->type == ARPHRD_IEEE802_TR) /* fix for token ring */
b->htype = ARPHRD_IEEE802;
else if (dev->type == ARPHRD_FDDI)
b->htype = ARPHRD_ETHER;
else {
printk("Unknown ARP type 0x%04x for device %s\n", dev->type, dev->name);
b->htype = dev->type; /* can cause undefined behavior */
}
/* server_ip and your_ip address are both already zero per RFC2131 */
b->hlen = dev->addr_len;
memcpy(b->hw_addr, dev->dev_addr, dev->addr_len);
b->secs = htons(jiffies_diff / HZ);
b->xid = d->xid;
/* add DHCP options or BOOTP extensions */
#ifdef IPCONFIG_DHCP
if (ic_proto_enabled & IC_USE_DHCP)
ic_dhcp_init_options(b->exten);
else
#endif
ic_bootp_init_ext(b->exten);
/* Chain packet down the line... */
skb->dev = dev;
skb->protocol = htons(ETH_P_IP);
if (dev_hard_header(skb, dev, ntohs(skb->protocol),
dev->broadcast, dev->dev_addr, skb->len) < 0 ||
dev_queue_xmit(skb) < 0)
printk("E" ;
} |
|