I am trying to write a program in C language using the nano ceditor in linux(ubuntu) in order to ping many devices at the same time, the goal is to retrieve roundtime information about the ping. The program looks like this :
#include <stdio.h>
main()
{
int i;
for (i=0; i<9; i++)
printf("pinging device number:%d",i);
ping6 fe80::acbd:ff:fe00:i%nstack -c 2
printf(" \n Done");
}
With ping it works normally but im using ipv6 and it doesnt work. Note: if i do the ping6 command alone it works its just when im putting it in my program Thank you
the posted code contains several problems:
Most of those problems are covered in the question comments.
The following code compiles cleanly and performs the desired function
#include <stdio.h> // printf()
#include <stdlib.h> // system()
int main( void )
{
int i;
for (i=0; i<9; i++)
{
printf("pinging device number:%d\n",i);
system( "ping6 fe80::acbd:ff:fe00:i%nstack -c 2" );
}
printf(" \n Done\n");
}
the output from the above code is:
pinging device number:0
unknown host
pinging device number:1
unknown host
pinging device number:2
unknown host
pinging device number:3
unknown host
pinging device number:4
unknown host
pinging device number:5
unknown host
pinging device number:6
unknown host
pinging device number:7
unknown host
pinging device number:8
unknown host
Done
You may be able to reach a valid host from your network.
However, remember the excerpt from the man page about not being able to perform routing.
(edit) the following code cleanly compiles and uses sprintf()
However, I find nothing that supports the 6th address :1%nstack
parameter! I would expect to only see the device number, not the text: %nstack
what am I missing?
#include <stdio.h> // printf(), sprintf()
#include <stdlib.h> // system()
int main( void )
{
int i;
char pingCmd[100] = {'\0'};
for (i=0; i<9; i++)
{
printf("\npinging device number:%d\n",i);
//system( "ping6 fe80::acbd:ff:fe00:i%nstack -c 2" );
sprintf( pingCmd, "%s%d%s", "ping6 -c 2 fe80::acbd:ff:fe00:", i, "%nstack");
printf( "%s\n", pingCmd);
system( pingCmd );
}
printf(" \n Done\n");
}
the output from the above is:
pinging device number:0
ping6 -c 2 fe80::acbd:ff:fe00:0%nstack
unknown host
pinging device number:1
ping6 -c 2 fe80::acbd:ff:fe00:1%nstack
unknown host
pinging device number:2
ping6 -c 2 fe80::acbd:ff:fe00:2%nstack
unknown host
pinging device number:3
ping6 -c 2 fe80::acbd:ff:fe00:3%nstack
unknown host
pinging device number:4
ping6 -c 2 fe80::acbd:ff:fe00:4%nstack
unknown host
pinging device number:5
ping6 -c 2 fe80::acbd:ff:fe00:5%nstack
unknown host
pinging device number:6
ping6 -c 2 fe80::acbd:ff:fe00:6%nstack
unknown host
pinging device number:7
ping6 -c 2 fe80::acbd:ff:fe00:7%nstack
unknown host
pinging device number:8
ping6 -c 2 fe80::acbd:ff:fe00:8%nstack
unknown host
Done
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.