Logo Search packages:      
Sourcecode: ucarp version File versions  Download package


#include <config.h>
#include "ucarp.h"
#include "garp.h"
#include "log.h"

# include <dmalloc.h>

int gratuitous_arp(const int dev_desc_fd, const int enable_virtual)
    static unsigned char arp[28] = {
            0x00, 0x01,
            0x08, 0x00,
            0x06, 0x04,
            0x00, 0x02,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00,
            0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
            0xff, 0xff, 0xff, 0xff
    unsigned char *pkt;
    struct ether_header *eh_ptr;

    memcpy(&arp[8], hwaddr, sizeof hwaddr);    
    if (enable_virtual == 0) {
        arp[7] = 0x01;
        memcpy(&arp[24], &vaddr.s_addr, (size_t) 4U);
        memset(&arp[14], 0xff, ETHER_ADDR_LEN);
    } else {
        arp[7] = 0x02;
        memcpy(&arp[14], &vaddr.s_addr, (size_t) 4U);
        memset(&arp[24], 0xff, ETHER_ADDR_LEN);        
    if ((pkt = ALLOCA(sizeof *eh_ptr + sizeof arp)) == NULL) {
        logfile(LOG_ERR, _("out of memory to send gratuitous ARP"));
        return -1;
    memcpy(pkt + sizeof *eh_ptr, arp, sizeof arp);
        struct ether_header eh;
        memcpy(&eh, pkt, sizeof eh);
        memcpy(&eh.ether_shost, &arp[8], ETHER_ADDR_LEN);
        memcpy(&eh.ether_dhost, &arp[18], ETHER_ADDR_LEN);
        eh.ether_type = htons(ETHERTYPE_ARP);
        memcpy(pkt, &eh, sizeof eh);
    if (write(dev_desc_fd, pkt, sizeof *eh_ptr + sizeof arp) < 0) {
#ifdef DEBUG
        logfile(LOG_DEBUG, "write() in garp: %s", strerror(errno));
        return -1;
    return 0;

Generated by  Doxygen 1.6.0   Back to index