sockaddr_ll problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I can send ARP requests using IPPROTO_RAW, but I want to send it using
ETH_P_ARP and sockaddr_ll as described in packet(7).

Tcpdump produces the following output that matches exactly the data
the kernel sends in this case and my IPPROTO_RAW version sends.
Also analysing with etherreal lead to the same results.
The difference is that 192.168.0.61 doesn't responds. It seems that the
packet is displayed by tcpdump, but never really transmitted.

I've appended the tcpdump output and code snippet. Why doesn't it work?

---
16:34:30.796225 arp who-has 192.168.0.61 tell 192.168.0.74 (0:90:4b:0:ae:e2)
                         0001 0800 0604 0001 0090 4b00 aee2 c0a8
                         004a 0000 0000 0000 c0a8 003d
---

---

struct arp_packet {
        u_char targ_hw_addr[ETH_HW_ADDR_LEN];
        u_char src_hw_addr[ETH_HW_ADDR_LEN];
        u_short frame_type;
        u_short hw_type;
        u_short prot_type;
        u_char hw_addr_size;
        u_char prot_addr_size;
        u_short op;
        u_char sndr_hw_addr[ETH_HW_ADDR_LEN];
        u_char sndr_ip_addr[IP_ADDR_LEN];
        u_char rcpt_hw_addr[ETH_HW_ADDR_LEN];
        u_char rcpt_ip_addr[IP_ADDR_LEN];
};


void SendARPRequest(const unsigned char ip[4]){
  struct arp_packet req;
  struct sockaddr_ll sal;
  int sock;
  int TRUEINT = 1;


  unsigned char ll_s_hw[ETH_HW_ADDR_LEN]={0x00,0x00,0x00,0x00,0x00,0x00};
  unsigned char ll_r_hw[ETH_HW_ADDR_LEN]={0x00,0x90,0x4b,0x00,0xae,0xe2};
  unsigned char s_ip[IP_ADDR_LEN]={192,168,0,74};
  unsigned char r_ip[IP_ADDR_LEN]={192,168,0,61};
  unsigned char s_hw[ETH_HW_ADDR_LEN]={0x00,0x90,0x4b,0x00,0xae,0xe2};
  unsigned char r_hw[ETH_HW_ADDR_LEN]={0x00,0x00,0x00,0x00,0x00,0x00};

  printf("Using ARP2\n");

  req.frame_type = htons(ETHERTYPE_ARP);
  req.hw_type = htons(ETHER_HW_TYPE);
  req.prot_type = htons(IP_PROTO_TYPE);
  req.hw_addr_size = ETH_HW_ADDR_LEN;
  req.prot_addr_size = IP_ADDR_LEN;
  req.op=htons(ARPOP_REQUEST);


  memcpy(req.targ_hw_addr,ll_r_hw,ETH_HW_ADDR_LEN);
  memcpy(req.src_hw_addr,ll_s_hw,ETH_HW_ADDR_LEN);

  memcpy(req.sndr_hw_addr,s_hw,ETH_HW_ADDR_LEN);
  memcpy(req.rcpt_hw_addr,r_hw,ETH_HW_ADDR_LEN);
  memcpy(req.sndr_ip_addr,s_ip,IP_ADDR_LEN);
  memcpy(req.rcpt_ip_addr,r_ip,IP_ADDR_LEN);

  bzero(&sal,sizeof(sal));
  sal.sll_family = AF_PACKET;
  sal.sll_protocol = htons(ETH_P_ARP);
  sal.sll_ifindex = 2;
  sal.sll_hatype = ARPOP_REQUEST;
  sal.sll_pkttype = PACKET_BROADCAST;
  memcpy(sal.sll_addr,ll_s_hw,ETH_HW_ADDR_LEN);
  sal.sll_halen = ETH_HW_ADDR_LEN;

  if((sock = socket(AF_PACKET,SOCK_RAW,htons(ETH_P_ARP))) < 0)  {
    perror("socket");
    exit(-1);
  }

  if(sendto(sock,&req,sizeof(req),0,(struct sockaddr *)&sal,sizeof(sal)) <
0){
        perror("sendto");
 return;
  }
}
---

-
: send the line "unsubscribe linux-net" in
the body of a message to majordomo@vger.kernel.org


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux