From patchwork Wed Dec 21 05:49:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: xuewenqian X-Patchwork-Id: 9482505 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7F26660772 for ; Wed, 21 Dec 2016 05:49:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6D9C4280B0 for ; Wed, 21 Dec 2016 05:49:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5F9DD280FC; Wed, 21 Dec 2016 05:49:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C841A280B0 for ; Wed, 21 Dec 2016 05:49:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751597AbcLUFto (ORCPT ); Wed, 21 Dec 2016 00:49:44 -0500 Received: from cn.fujitsu.com ([59.151.112.132]:9199 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751095AbcLUFto (ORCPT ); Wed, 21 Dec 2016 00:49:44 -0500 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="14125746" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 21 Dec 2016 13:49:31 +0800 Received: from email.frdc.cn.fujitsu.com (unknown [10.167.174.30]) by cn.fujitsu.com (Postfix) with ESMTP id 06C95467049D; Wed, 21 Dec 2016 13:49:31 +0800 (CST) Received: from localhost.localdomain (unknown [10.167.175.108]) by email.frdc.cn.fujitsu.com (Postfix) with ESMTP id E0E2C1C0B8D; Wed, 21 Dec 2016 13:49:30 +0800 (CST) From: wsn.iot.xwq@cn.fujitsu.com To: linux-wpan@vger.kernel.org Cc: stefan@osg.samsung.com, aar@pengutronix.de, Xue Wenqian Subject: [PATCH wpan-tools v2] wpan-ping: Add the filtering function for frame receiving Date: Wed, 21 Dec 2016 05:49:04 +0000 Message-Id: <1482299344-4128-1-git-send-email-wsn.iot.xwq@cn.fujitsu.com> X-Mailer: git-send-email 1.7.10.4 MIME-Version: 1.0 X-yoursite-MailScanner-ID: 06C95467049D.A14EA X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: wsn.iot.xwq@cn.fujitsu.com Sender: linux-wpan-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wpan@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Xue Wenqian The filtering for wpan-ping client and server is made by checking frame header. Signed-off-by: Xue Wenqian --- wpan-ping/wpan-ping.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/wpan-ping/wpan-ping.c b/wpan-ping/wpan-ping.c index e6df2b4..f825b22 100644 --- a/wpan-ping/wpan-ping.c +++ b/wpan-ping/wpan-ping.c @@ -303,6 +303,10 @@ static int measure_roundtrip(struct config *conf, int sd) { } gettimeofday(&start_time, NULL); ret = recv(sd, buf, conf->packet_len, 0); + if (buf[0] != NOT_A_6LOWPAN_FRAME) { + printf("Non-wpanping packet was received\n"); + continue; + } if (seq_num != ((buf[2] << 8)| buf[3])) { printf("Sequenze number did not match\n"); continue; @@ -386,11 +390,13 @@ static void init_server(int sd) { #if DEBUG dump_packet(buf, len); #endif - /* Send same packet back */ - len = sendto(sd, buf, len, 0, (struct sockaddr *)&src, addrlen); - if (len < 0) { - perror("sendto"); - continue; + if (buf[0] == NOT_A_6LOWPAN_FRAME) { + /* Send same packet back */ + len = sendto(sd, buf, len, 0, (struct sockaddr *)&src, addrlen); + if (len < 0) { + perror("sendto"); + continue; + } } } free(buf);