Re: [riot-devel] Easy ping

2016-09-23 Thread Baptiste Clenet
Thanks Martine!
I do need timeout, otherwise I won't know if the node is connected.
Sock is in PR so I prefer not to use it for the moment

2016-09-23 20:37 GMT+02:00 Martine Lenders :
> Hi Baptiste,
> that depends on what you mean by reachable. Even for ICMPv6 ping (which is
> used with the shell ping command) you need some "server", that handles the
> request and issues a reply. If that server is not present the node will not
> reply to pings, even if it is reachable in the sense that you can send IPv6
> packets to it and it will handle them (to see what I mean comment out the
> `USEMODULE += gnrc_icmpv6_echo` line in gnrc_networking's Makefile for the
> receiver, you will be able to still send UDP packets, but ping will always
> fail).
>
> If there is a server running somewhere you can just use conn (note that
> timeouts are not possible with conn, if you need them use sock [1] instead
> [which is also a little easier to handle]):
>
>> #include "net/af.h"
>> #include "net/conn/ip.h" /* you need to include gnrc_conn_ip to your app
>> for that */
>> #include "net/icmpv6.h"
>> #include "net/ipv6.h"
>> #include "net/protnum.h"
>> #include "byteorder.h"
>> #include "xtimer.h"
>>
>> /* ... */
>>
>> conn_ip_t c;
>> ipv6_addr_t tmp = IPV6_ADDR_UNSPECIFIED;
>> ipv6_addr_t dst = SOME_ADDR;
>> icmpv6_echo_t echo_req, echo_rep;
>> uint16_t seq = 0;
>>
>> echo_req.type = ICMPV6_ECHO_REQ;
>> echo_req.code = 0;
>> echo_req.id = byteorder_htons(SOME_ID);
>> conn_ip_create(, , sizeof(tmp), AF_INET6, PROTNUM_ICMPV6
>> while (true) {
>> int reply = 0;
>> echo_req.seq = byteorder_htons(seq++);
>> echo_req.csum.u16 = 0; /* will be recalculated by stack */
>> conn_ip_sendto(_req, sizeof(echo_req), NULL, 0, dst, sizeof(dst),
>> AF_INET6, PROTNUM_IPV6_NONXT);
>> while (!reply) {
>> if (conn_ip_recvfrom(, _rep, sizeof(echo_rep), ,
>> sizeof(tmp)) == sizeof(echo_rep)) {
>> /* could be any ICMPv6 packet so check type */
>> if (echo_rep.type == ICMPV6_ECHO_REP) {
>> printf("Received ping seq %u\n",
>> (unsigned)ntohs_byteorder(echo_rep.seq));
>> reply = 1;
>> }
>> }
>> }
>> xtimer_sleep(DELAY);
>> }
>
> Did not test the application, but I hope you get the idea.
>
> Cheers,
> Martine
>
> [1]
> https://github.com/RIOT-OS/RIOT/pull/5772/files#diff-0fb2e56aa53bfaac6b1189715662110cR89
>
>
> ___
> devel mailing list
> devel@riot-os.org
> https://lists.riot-os.org/mailman/listinfo/devel
>



-- 
Baptiste
___
devel mailing list
devel@riot-os.org
https://lists.riot-os.org/mailman/listinfo/devel


Re: [riot-devel] Easy ping

2016-09-23 Thread Martine Lenders
Hi Baptiste,
that depends on what you mean by reachable. Even for ICMPv6 ping (which is
used with the shell ping command) you need some "server", that handles the
request and issues a reply. If that server is not present the node will not
reply to pings, even if it is reachable in the sense that you can send IPv6
packets to it and it will handle them (to see what I mean comment out the
`USEMODULE += gnrc_icmpv6_echo` line in gnrc_networking's Makefile for the
receiver, you will be able to still send UDP packets, but ping will always
fail).

If there is a server running somewhere you can just use conn (note that
timeouts are not possible with conn, if you need them use sock [1] instead
[which is also a little easier to handle]):

> #include "net/af.h"
> #include "net/conn/ip.h" /* you need to include gnrc_conn_ip to your app
for that */
> #include "net/icmpv6.h"
> #include "net/ipv6.h"
> #include "net/protnum.h"
> #include "byteorder.h"
> #include "xtimer.h"
>
> /* ... */
>
> conn_ip_t c;
> ipv6_addr_t tmp = IPV6_ADDR_UNSPECIFIED;
> ipv6_addr_t dst = SOME_ADDR;
> icmpv6_echo_t echo_req, echo_rep;
> uint16_t seq = 0;
>
> echo_req.type = ICMPV6_ECHO_REQ;
> echo_req.code = 0;
> echo_req.id = byteorder_htons(SOME_ID);
> conn_ip_create(, , sizeof(tmp), AF_INET6, PROTNUM_ICMPV6
> while (true) {
> int reply = 0;
> echo_req.seq = byteorder_htons(seq++);
> echo_req.csum.u16 = 0; /* will be recalculated by stack */
> conn_ip_sendto(_req, sizeof(echo_req), NULL, 0, dst,
sizeof(dst), AF_INET6, PROTNUM_IPV6_NONXT);
> while (!reply) {
> if (conn_ip_recvfrom(, _rep, sizeof(echo_rep), ,
sizeof(tmp)) == sizeof(echo_rep)) {
> /* could be any ICMPv6 packet so check type */
> if (echo_rep.type == ICMPV6_ECHO_REP) {
> printf("Received ping seq %u\n",
(unsigned)ntohs_byteorder(echo_rep.seq));
> reply = 1;
> }
> }
> }
> xtimer_sleep(DELAY);
> }

Did not test the application, but I hope you get the idea.

Cheers,
Martine

[1]
https://github.com/RIOT-OS/RIOT/pull/5772/files#diff-0fb2e56aa53bfaac6b1189715662110cR89
___
devel mailing list
devel@riot-os.org
https://lists.riot-os.org/mailman/listinfo/devel


Re: [riot-devel] Easy ping

2016-09-23 Thread Marc Sissom
Then setup a task that runs ping.


Marc Sissom
Krypton Solutions

-Original Message-
From: devel [mailto:devel-boun...@riot-os.org] On Behalf Of Baptiste Clenet
Sent: Friday, September 23, 2016 11:36 AM
To: RIOT OS kernel developers <devel@riot-os.org>
Subject: Re: [riot-devel] Easy ping

Yes it would work, but I prefer a simple ping, two gnrc_networking running and 
one wants to ping the other one, that's all what I want.
ICMPV6 is great because I don't need to deal with the request on the second 
board.

2016-09-23 18:30 GMT+02:00 Marc Sissom <msis...@krypton-solutions.com>:
> I assume the device you are trying to reach has some purpose. If so send it a 
> purposeful packet. For example, you are running a web server on the device in 
> question, open a connection to port  80 with your telnet utility and talk to 
> it.
>
>
> Marc Sissom
> Krypton Solutions
>
> -Original Message-
> From: devel [mailto:devel-boun...@riot-os.org] On Behalf Of Baptiste 
> Clenet
> Sent: Friday, September 23, 2016 11:21 AM
> To: RIOT OS kernel developers <devel@riot-os.org>
> Subject: Re: [riot-devel] Easy ping
>
> Yes but it's not as easy as I want (shell command) Tell me the easiest 
> possible function to know if an address is reachable or not :-)
>
> 2016-09-23 17:56 GMT+02:00 Martine Lenders <m...@martine-lenders.eu>:
>> Hi Baptiste,
>> have you had a look at the implementation of the ping shell command?
>> Another way would be to (re-)implement ping using conn_ip (or sock if 
>> merged). In that case, if you want it relly easy you don't even 
>> have to implement ICMPv6 ping but can do whatever you want ;-).
>>
>> Cheers,
>> Martine
>>
>> 2016-09-23 17:18 GMT+02:00 Baptiste Clenet <bapcle...@gmail.com>:
>>> Hi,
>>>
>>> How can I easily ping a board by software (without using shell) so I 
>>> ping( IPV6_address) and I get -1 for error (not reachable) or 0 for 
>>> success?
>>>
>>> Cheers,
>>>
>>> --
>>> Baptiste
>>> ___
>>> devel mailing list
>>> devel@riot-os.org
>>> https://lists.riot-os.org/mailman/listinfo/devel
>> ___
>> devel mailing list
>> devel@riot-os.org
>> https://lists.riot-os.org/mailman/listinfo/devel
>
>
>
> --
> Baptiste
> ___
> devel mailing list
> devel@riot-os.org
> https://lists.riot-os.org/mailman/listinfo/devel
> ___
> devel mailing list
> devel@riot-os.org
> https://lists.riot-os.org/mailman/listinfo/devel



--
Baptiste
___
devel mailing list
devel@riot-os.org
https://lists.riot-os.org/mailman/listinfo/devel
___
devel mailing list
devel@riot-os.org
https://lists.riot-os.org/mailman/listinfo/devel


Re: [riot-devel] Easy ping

2016-09-23 Thread Baptiste Clenet
Yes it would work, but I prefer a simple ping, two gnrc_networking
running and one wants to ping the other one, that's all what I want.
ICMPV6 is great because I don't need to deal with the request on the
second board.

2016-09-23 18:30 GMT+02:00 Marc Sissom <msis...@krypton-solutions.com>:
> I assume the device you are trying to reach has some purpose. If so send it a 
> purposeful packet. For example, you are running a web server on the device in 
> question, open a connection to port  80 with your telnet utility and talk to 
> it.
>
>
> Marc Sissom
> Krypton Solutions
>
> -Original Message-
> From: devel [mailto:devel-boun...@riot-os.org] On Behalf Of Baptiste Clenet
> Sent: Friday, September 23, 2016 11:21 AM
> To: RIOT OS kernel developers <devel@riot-os.org>
> Subject: Re: [riot-devel] Easy ping
>
> Yes but it's not as easy as I want (shell command) Tell me the easiest 
> possible function to know if an address is reachable or not :-)
>
> 2016-09-23 17:56 GMT+02:00 Martine Lenders <m...@martine-lenders.eu>:
>> Hi Baptiste,
>> have you had a look at the implementation of the ping shell command?
>> Another way would be to (re-)implement ping using conn_ip (or sock if
>> merged). In that case, if you want it relly easy you don't even
>> have to implement ICMPv6 ping but can do whatever you want ;-).
>>
>> Cheers,
>> Martine
>>
>> 2016-09-23 17:18 GMT+02:00 Baptiste Clenet <bapcle...@gmail.com>:
>>> Hi,
>>>
>>> How can I easily ping a board by software (without using shell) so I
>>> ping( IPV6_address) and I get -1 for error (not reachable) or 0 for
>>> success?
>>>
>>> Cheers,
>>>
>>> --
>>> Baptiste
>>> ___
>>> devel mailing list
>>> devel@riot-os.org
>>> https://lists.riot-os.org/mailman/listinfo/devel
>> ___
>> devel mailing list
>> devel@riot-os.org
>> https://lists.riot-os.org/mailman/listinfo/devel
>
>
>
> --
> Baptiste
> ___
> devel mailing list
> devel@riot-os.org
> https://lists.riot-os.org/mailman/listinfo/devel
> ___
> devel mailing list
> devel@riot-os.org
> https://lists.riot-os.org/mailman/listinfo/devel



-- 
Baptiste
___
devel mailing list
devel@riot-os.org
https://lists.riot-os.org/mailman/listinfo/devel


Re: [riot-devel] Easy ping

2016-09-23 Thread Marc Sissom
I assume the device you are trying to reach has some purpose. If so send it a 
purposeful packet. For example, you are running a web server on the device in 
question, open a connection to port  80 with your telnet utility and talk to 
it. 


Marc Sissom
Krypton Solutions

-Original Message-
From: devel [mailto:devel-boun...@riot-os.org] On Behalf Of Baptiste Clenet
Sent: Friday, September 23, 2016 11:21 AM
To: RIOT OS kernel developers <devel@riot-os.org>
Subject: Re: [riot-devel] Easy ping

Yes but it's not as easy as I want (shell command) Tell me the easiest possible 
function to know if an address is reachable or not :-)

2016-09-23 17:56 GMT+02:00 Martine Lenders <m...@martine-lenders.eu>:
> Hi Baptiste,
> have you had a look at the implementation of the ping shell command?
> Another way would be to (re-)implement ping using conn_ip (or sock if 
> merged). In that case, if you want it relly easy you don't even 
> have to implement ICMPv6 ping but can do whatever you want ;-).
>
> Cheers,
> Martine
>
> 2016-09-23 17:18 GMT+02:00 Baptiste Clenet <bapcle...@gmail.com>:
>> Hi,
>>
>> How can I easily ping a board by software (without using shell) so I 
>> ping( IPV6_address) and I get -1 for error (not reachable) or 0 for 
>> success?
>>
>> Cheers,
>>
>> --
>> Baptiste
>> ___
>> devel mailing list
>> devel@riot-os.org
>> https://lists.riot-os.org/mailman/listinfo/devel
> ___
> devel mailing list
> devel@riot-os.org
> https://lists.riot-os.org/mailman/listinfo/devel



--
Baptiste
___
devel mailing list
devel@riot-os.org
https://lists.riot-os.org/mailman/listinfo/devel
___
devel mailing list
devel@riot-os.org
https://lists.riot-os.org/mailman/listinfo/devel


Re: [riot-devel] Easy ping

2016-09-23 Thread Baptiste Clenet
Yes but it's not as easy as I want (shell command)
Tell me the easiest possible function to know if an address is
reachable or not :-)

2016-09-23 17:56 GMT+02:00 Martine Lenders :
> Hi Baptiste,
> have you had a look at the implementation of the ping shell command?
> Another way would be to (re-)implement ping using conn_ip (or sock if
> merged). In that case, if you want it relly easy you don't even
> have to implement ICMPv6 ping but can do whatever you want ;-).
>
> Cheers,
> Martine
>
> 2016-09-23 17:18 GMT+02:00 Baptiste Clenet :
>> Hi,
>>
>> How can I easily ping a board by software (without using shell) so I
>> ping( IPV6_address) and I get -1 for error (not reachable) or 0 for
>> success?
>>
>> Cheers,
>>
>> --
>> Baptiste
>> ___
>> devel mailing list
>> devel@riot-os.org
>> https://lists.riot-os.org/mailman/listinfo/devel
> ___
> devel mailing list
> devel@riot-os.org
> https://lists.riot-os.org/mailman/listinfo/devel



-- 
Baptiste
___
devel mailing list
devel@riot-os.org
https://lists.riot-os.org/mailman/listinfo/devel


Re: [riot-devel] Easy ping

2016-09-23 Thread Martine Lenders
Hi Baptiste,
have you had a look at the implementation of the ping shell command?
Another way would be to (re-)implement ping using conn_ip (or sock if
merged). In that case, if you want it relly easy you don't even
have to implement ICMPv6 ping but can do whatever you want ;-).

Cheers,
Martine

2016-09-23 17:18 GMT+02:00 Baptiste Clenet :
> Hi,
>
> How can I easily ping a board by software (without using shell) so I
> ping( IPV6_address) and I get -1 for error (not reachable) or 0 for
> success?
>
> Cheers,
>
> --
> Baptiste
> ___
> devel mailing list
> devel@riot-os.org
> https://lists.riot-os.org/mailman/listinfo/devel
___
devel mailing list
devel@riot-os.org
https://lists.riot-os.org/mailman/listinfo/devel


[riot-devel] Easy ping

2016-09-23 Thread Baptiste Clenet
Hi,

How can I easily ping a board by software (without using shell) so I
ping( IPV6_address) and I get -1 for error (not reachable) or 0 for
success?

Cheers,

-- 
Baptiste
___
devel mailing list
devel@riot-os.org
https://lists.riot-os.org/mailman/listinfo/devel