Skip to content

Commit

Permalink
Merge pull request RIOT-OS/applications#5 from OlegHahm/sixlowapp_she…
Browse files Browse the repository at this point in the history
…ll_commands

sixlowapp: adapted to new shell handler prototype
  • Loading branch information
Lotterleben committed Apr 9, 2015
2 parents 4e4305c + afc9758 commit 03d2494
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
7 changes: 5 additions & 2 deletions sixlowapp/sixlowapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,19 @@ extern char addr_str[IPV6_MAX_ADDR_STR_LEN];
* @param[in] argc Number of arguments supplied to the function invocation.
* @param[in] argv The supplied argument list.
*
* @returns 0 on success, error code on invalide parameters
*/
void sixlowapp_send_ping(int argc, char **argv);
int sixlowapp_send_ping(int argc, char **argv);

/**
* @brief Shell command for netcat
*
* @param[in] argc Number of arguments supplied to the function invocation.
* @param[in] argv The supplied argument list.
*
* @returns 0 on success, error code on invalide parameters
*/
void sixlowapp_netcat(int argc, char **argv);
int sixlowapp_netcat(int argc, char **argv);

/**
* @brief Wrapper function for sending data of UDP
Expand Down
17 changes: 11 additions & 6 deletions sixlowapp/sixlowshell.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/

#include <stdio.h>
#include <errno.h>
#include "msg.h"
#include "thread.h"
#include "sched.h"
Expand All @@ -37,20 +38,20 @@ static char payload[MAX_PAYLOAD_SIZE];
unsigned sixlowapp_waiting_for_pong;
kernel_pid_t sixlowapp_waiter_pid;

void sixlowapp_send_ping(int argc, char **argv)
int sixlowapp_send_ping(int argc, char **argv)
{
ipv6_addr_t dest;
const char *icmp_data = ICMP_DATA;

if (argc != 2) {
puts("! Invalid number of parameters");
printf(" usage: %s destination\n", argv[0]);
return;
return EINVAL;
}

if (!inet_pton(AF_INET6, argv[1], &dest)) {
printf("! %s is not a valid IPv6 address\n", argv[1]);
return;
return EFAULT;
}

sixlowapp_ndp_workaround(&dest);
Expand All @@ -77,23 +78,25 @@ void sixlowapp_send_ping(int argc, char **argv)
addr_str,
IPV6_MAX_ADDR_STR_LEN));
}

return 0;
}

void sixlowapp_netcat(int argc, char **argv)
int sixlowapp_netcat(int argc, char **argv)
{
ipv6_addr_t dest;

if (argc < 3) {
puts("! Not enough parameters");
puts(" usage: nc [-l] [destination] [port] [text]");
return;
return EINVAL;
}

if (strlen(argv[1]) == 2) {
if (strncmp(argv[1], "-l", 2)) {
puts("! Invalid parameter");
puts(" usage: nc [-l] [destination] [port] [text]");
return;
return EINVAL;
}
else {
sixlowapp_netcat_listen_port = atoi(argv[2]);
Expand All @@ -118,6 +121,8 @@ void sixlowapp_netcat(int argc, char **argv)
}
sixlowapp_udp_send(&dest, atoi(argv[2]), payload, plen);
}

return 0;
}


0 comments on commit 03d2494

Please sign in to comment.