strncmp() and if() does not agree...what am I missing?? (raw sockets)

I'm trying to build a simple echo server/client that works on ethernet level(using raw sockets). The server side by itself works and shows all incoming packets on eth0. The client works and sends ethernet packets on eth0 (I checked this with wireshark and can see the packets going out.) I now want to make a filter to only look at the packets I'm interested. (This is based on the destination/source addresses.) In the code below, could someone please explain to me why strncmp returns zero(meaning the strings match) but yet the "if(ethernet_header->h_dest == mac)" fails to execute (don't match). Both the variables "mac" and "ethernet_header->h_dest" is the same type and length. Some more background: - This is done on linux 64bit (ubuntu) - I'm using eth0 on the same machine for sending/receiving....I don't think this should be a problem? I just don't understand why strcmp returns a match and if doesn't. What am I missing?? void ParseEthernetHeader(unsigned char *packet, int len) { struct ethhdr *ethernet_header; unsigned char mac[ETH_ALEN] = {0x01, 0x55, 0x56, 0x88, 0x32, 0x7c}; if (len > sizeof(struct ethhdr)) { ethernet_header = (struct ethhdr *) packet; int result = strncmp(ethernet_header->h_dest, mac, ETH_ALEN); printf("Result: %d\n", result); if(ethernet_header->h_dest == mac) { /* First set of 6 bytes are Destination MAC */ PrintInHex("Destination MAC: ", ethernet_header->h_dest, 6); printf("\n"); /* Second set of 6 bytes are Source MAC */ PrintInHex("Source MAC: ", ethernet_header->h_source, 6); printf("\n"); /* Last 2 bytes in the Ethernet header are the protocol it carries */ PrintInHex("Protocol: ", (void *) ðernet_header->h_proto, 2); printf("\n\n"); printf("Length: %d\n",len); } } else { printf("Packet size too small (length: %d)!\n",len); } }

以上就是strncmp() and if() does not agree...what am I missing?? (raw sockets)的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » CSS3 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏