struct arphdr *arp_header;
grub_net_link_level_address_t target_hw_addr;
char *aux, arp_data[128];
+ grub_err_t err;
int i;
/* Check cache table. */
nb.head = arp_data;
nb.end = arp_data + sizeof (arp_data);
grub_netbuff_clear (&nb);
-
grub_netbuff_reserve (&nb, 128);
- grub_netbuff_push (&nb, sizeof (*arp_header) + 2 * (6 + 4));
+
+ if ((err = grub_netbuff_push (&nb, sizeof (*arp_header) + 2 * (6 + 4))) != GRUB_ERR_NONE)
+ return err;
+
arp_header = (struct arphdr *) nb.data;
arp_header->hrd = grub_cpu_to_be16 (GRUB_NET_ARPHRD_ETHERNET);
arp_header->pro = grub_cpu_to_be16 (GRUB_NET_ETHERTYPE_IP);
struct grub_net_card *card;
FOR_NET_CARDS (card)
if (card->driver && !grub_strcmp (card->driver->name, "ofnet"))
- card->driver->fini (card);
+ {
+ card->driver->fini (card);
+ card->driver = NULL;
+ }
grub_net_card_driver_unregister (&ofdriver);
grub_getbootp = NULL;
}
grub_uint16_t ethertype)
{
struct etherhdr *eth;
+ grub_err_t err;
- grub_netbuff_push (nb, sizeof (*eth));
+ if ((err = grub_netbuff_push (nb, sizeof (*eth))) != GRUB_ERR_NONE)
+ return err;
eth = (struct etherhdr *) nb->data;
grub_memcpy (eth->dst, target_addr.mac, 6);
grub_memcpy (eth->src, inf->hwaddress.mac, 6);
struct llchdr *llch;
struct snaphdr *snaph;
grub_uint16_t type;
+ grub_err_t err;
eth = (struct etherhdr *) nb->data;
type = grub_be_to_cpu16 (eth->type);
- grub_netbuff_pull (nb, sizeof (*eth));
+ if ((err = grub_netbuff_pull (nb, sizeof (*eth))) != GRUB_ERR_NONE)
+ return err;
if (type <= 1500)
{
if (llch->dsap == 0xaa && llch->ssap == 0xaa && llch->ctrl == 0x3)
{
- grub_netbuff_pull (nb, sizeof (*llch));
+ if ((err = grub_netbuff_pull (nb, sizeof (*llch))) != GRUB_ERR_NONE)
+ return err;
snaph = (struct snaphdr *) nb->data;
type = snaph->type;
}
grub_net_recv_ip_packets (struct grub_net_buff *nb)
{
struct iphdr *iph = (struct iphdr *) nb->data;
- grub_netbuff_pull (nb, sizeof (*iph));
+ grub_err_t err;
+
+ if ((err = grub_netbuff_pull (nb, sizeof (*iph))) != GRUB_ERR_NONE)
+ return err;
switch (iph->protocol)
{
grub_netbuff_free (struct grub_net_buff *nb)
{
grub_free (nb->head);
- return 0;
+ return GRUB_ERR_NONE;
}
grub_err_t
grub_netbuff_clear (struct grub_net_buff *nb)
{
nb->data = nb->tail = nb->head;
- return 0;
+ return GRUB_ERR_NONE;
}
grub_netbuff_clear (&nb);
grub_netbuff_reserve (&nb, 1500);
- grub_netbuff_push (&nb, sizeof (*tftph));
+ if ((err = grub_netbuff_push (&nb, sizeof (*tftph))) != GRUB_ERR_NONE)
+ return err;
tftph = (struct tftphdr *) nb.data;
rrq += grub_strlen ("0") + 1;
hdrlen = sizeof (tftph->opcode) + rrqlen;
- grub_netbuff_unput (&nb, nb.tail - (nb.data + hdrlen));
-
+ if ((err = grub_netbuff_unput (&nb, nb.tail - (nb.data + hdrlen))) != GRUB_ERR_NONE)
+ return err;
file->device->net->socket->out_port = TFTP_SERVER_PORT;
err = grub_net_send_udp_packet (file->device->net->socket, &nb);
grub_netbuff_clear (nb);
break;
case TFTP_DATA:
- grub_netbuff_pull (nb, sizeof (tftph->opcode) +
- sizeof (tftph->u.data.block));
-
+ if ((err = grub_netbuff_pull (nb, sizeof (tftph->opcode) +
+ sizeof (tftph->u.data.block))) != GRUB_ERR_NONE)
+ return err;
if (grub_be_to_cpu16 (tftph->u.data.block) == data->block + 1)
{
data->block++;
sock->status = 2;
/* Prevent garbage in broken cards. */
if (size > 1024)
- grub_netbuff_unput (nb, size - 1024);
+ if ((err = grub_netbuff_unput (nb, size - 1024)) != GRUB_ERR_NONE)
+ return err;
}
else
grub_netbuff_clear (nb);
}
grub_netbuff_clear (&nb_ack);
grub_netbuff_reserve (&nb_ack, 128);
- grub_netbuff_push (&nb_ack, sizeof (tftph->opcode)
- + sizeof (tftph->u.ack.block));
+ if ((err = grub_netbuff_push (&nb_ack, sizeof (tftph->opcode)
+ + sizeof (tftph->u.ack.block))) != GRUB_ERR_NONE)
+ return err;
tftph = (struct tftphdr *) nb_ack.data;
tftph->opcode = grub_cpu_to_be16 (TFTP_ACK);
struct grub_net_buff *nb)
{
struct udphdr *udph;
+ grub_err_t err;
- grub_netbuff_push (nb, sizeof (*udph));
+ if ((err = grub_netbuff_push (nb, sizeof (*udph))) != GRUB_ERR_NONE)
+ return err;
udph = (struct udphdr *) nb->data;
udph->src = grub_cpu_to_be16 (socket->in_port);