I am trying to send an Ethernet OAM frame using a raw socket. I was successful at that.
The submit function I wrote:
int send_frame(sock_info *info,char *buf,int length) { struct sockaddr_ll dest_addr; memset(&dest_addr,0,sizeof(struct sockaddr_ll)); dest_addr.sll_family = PF_PACKET; dest_addr.sll_protocol = htons(8902); dest_addr.sll_ifindex = info->if_index; dest_addr.sll_halen = ETH_MAC_ADDR_LEN; dest_addr.sll_pkttype = PACKET_OTHERHOST; dest_addr.sll_hatype = ARPHRD_ETHER; memset(dest_addr.sll_addr,0,8); dest_addr.sll_addr[0] = 0x00; dest_addr.sll_addr[1] = 0xE0; dest_addr.sll_addr[2] = 0x0C; dest_addr.sll_addr[3] = 0x00; dest_addr.sll_addr[4] = 0x95; dest_addr.sll_addr[5] = 0x02; return sendto(info->sock_fd, buf, length, 0, (struct sockaddr*) &dest_addr, sizeof(struct sockaddr_ll)); }
I was unable to capture the package using wirehark. After too much, I found that the buffer used for sending should have all the fields of the ethernet frame (starting from the destination address). When I added the destination address and the source address and other ethernet fields to the buffer, I was able to capture the packet using wirehark. Thus, the send function does not use the MAC address stored in dest_addr.sll_addr .
My question is: then why do I need the sll_addr field in struct sockaddr_ll ? The manuals say that this is the destination MAC address.
source share