diff mbox

[v2,1/3] ping: report success on localhost ping

Message ID 1462183549-5408-1-git-send-email-nikunj@linux.vnet.ibm.com
State Superseded
Headers show

Commit Message

Nikunj A Dadhania May 2, 2016, 10:05 a.m. UTC
Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
---
 clients/net-snk/app/netapps/ping.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Nikunj A Dadhania May 2, 2016, 10:21 a.m. UTC | #1
Nikunj A Dadhania <nikunj@linux.vnet.ibm.com> writes:
> diff --git a/clients/net-snk/app/netapps/ping.c b/clients/net-snk/app/netapps/ping.c
> index 4facf06..3e4d440 100644
> --- a/clients/net-snk/app/netapps/ping.c
> +++ b/clients/net-snk/app/netapps/ping.c
> @@ -35,13 +35,15 @@ struct ping_args {
>  		unsigned int integer;
>  	} gateway_ip;
>  	unsigned int timeout;
> +	/* Netmask 192.168.1.10/24 format */
> +	unsigned int netmask;
>  };
>
>  static void
>  usage(void)
>  {
>  	printf
> -	    ("\nping device-path:[device-args,]server-ip,[client-ip],[gateway-ip][,timeout]\n");
> +	    ("\nping device-path:[device-args,]server-ip,[client-ip[\\nn]],[gateway-ip][,timeout]\n");
>
>  }
>
> @@ -82,7 +84,7 @@ parse_args(const char *args, struct ping_args *ping_args)
>  	}
>
>  	argncpy(args, 0, buf, 64);
> -	if (!strtoip(buf, ping_args->client_ip.string)) {
> +	if (!strtoip_netmask(buf, ping_args->client_ip.string, &ping_args->netmask)) {
>  		/* this should have been the client (our) IP address */
>  		return -1;
>  	} else {
> @@ -112,6 +114,7 @@ ping(int argc, char *argv[])
>  	int fd_device;
>  	struct ping_args ping_args;
>  	uint8_t own_mac[6];
> +	uint32_t netmask;
>
>  	memset(&ping_args, 0, sizeof(struct ping_args));
>
> @@ -163,6 +166,9 @@ ping(int argc, char *argv[])
>
>  	} else {
>  		memcpy(&fn_ip.own_ip, &ping_args.client_ip.integer, 4);
> +		if (ping_args.netmask)
> +			set_ipv4_netmask(ping_args.netmask);

Missed the following:

+               else
+                       set_ipv4_netmask(0xFFFFFF00UL);

is this a safe assumption when user has not provided any netmask
variable?

Regards
Nikunj
Thomas Huth May 2, 2016, 8:04 p.m. UTC | #2
On 02.05.2016 12:21, Nikunj A Dadhania wrote:
> Nikunj A Dadhania <nikunj@linux.vnet.ibm.com> writes:
>> diff --git a/clients/net-snk/app/netapps/ping.c b/clients/net-snk/app/netapps/ping.c
>> index 4facf06..3e4d440 100644
>> --- a/clients/net-snk/app/netapps/ping.c
>> +++ b/clients/net-snk/app/netapps/ping.c
...
>> @@ -163,6 +166,9 @@ ping(int argc, char *argv[])
>>
>>  	} else {
>>  		memcpy(&fn_ip.own_ip, &ping_args.client_ip.integer, 4);
>> +		if (ping_args.netmask)
>> +			set_ipv4_netmask(ping_args.netmask);
> 
> Missed the following:
> 
> +               else
> +                       set_ipv4_netmask(0xFFFFFF00UL);
> 
> is this a safe assumption when user has not provided any netmask
> variable?

I think in this case you should set the netmask according to whether
it's a class A, class B or class C network:

 Class A: 255.0.0.0
 Class B: 255.255.0.0
 Class C: 255.255.255.0

  Thomas
diff mbox

Patch

diff --git a/clients/net-snk/app/netapps/ping.c b/clients/net-snk/app/netapps/ping.c
index 2c7dadb..4facf06 100644
--- a/clients/net-snk/app/netapps/ping.c
+++ b/clients/net-snk/app/netapps/ping.c
@@ -180,6 +180,12 @@  ping(int argc, char *argv[])
 	       ((fn_ip.server_ip >> 8) & 0xFF), (fn_ip.server_ip & 0xFF));
 
 
+	// Report success on localhost ping
+	if (memcmp(&fn_ip.server_ip, &fn_ip.own_ip, 4) == 0) {
+		printf("success\n");
+		return 0;
+	}
+
 	ping_ipv4(fd_device, fn_ip.server_ip);
 
 	set_timer(TICKS_SEC / 10 * ping_args.timeout);