Skip to content

Commit

Permalink
netutils/netcat: Add netcat tool
Browse files Browse the repository at this point in the history
Check readme for usage and demo:

[![weboftwins-osvehicle-2020-rzr](
https://files.mastodon.social/media_attachments/files/105/163/916/892/863/178/original/05468e28b4463f95.png
)](
https://mastodon.social/@rzr/105225153152922220#weboftwins-osvehicle-2020-rzr
"weboftwins-osvehicle-2020-rzr")

Change-Id: I2eac915954ca6cf585f01addb53df581631a7ae6
Bug: apache/nuttx#1999
Relate-to: rzr/aframe-smart-home#3
Origin: https://github.com/CrossStream/nuttx-apps/tree/sandbox/rzr/review/master/netutils/netcat
Forwarded: apache#482
Signed-off-by: Philippe Coval <rzr@users.sf.net>
  • Loading branch information
rzr committed Nov 17, 2020
1 parent c1b11a1 commit 5dabc2e
Show file tree
Hide file tree
Showing 5 changed files with 415 additions and 0 deletions.
52 changes: 52 additions & 0 deletions netutils/netcat/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#############################################################################
#
# netutils/netcat/Kconfig
# netcat networking application
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
#############################################################################

# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#

config NETUTILS_NETCAT
bool "NetCat tool"
default n
select NET
select NET_TCP
---help---
Enable the NetCat TCP/IP swiss army tool

if NETUTILS_NETCAT

config NETUTILS_NETCAT_PROGNAME
string "Program name"
default "netcat"
---help---
This is the name of the program that will be use when the NSH ELF
program is installed.

config NETUTILS_NETCAT_PRIORITY
int "netcat task priority"
default 100

config NETUTILS_NETCAT_STACKSIZE
int "netcat stack size"
default DEFAULT_TASK_STACKSIZE

endif
25 changes: 25 additions & 0 deletions netutils/netcat/Make.defs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#############################################################################
#
# netutils/netcat/Make.defs
# netcat sample networking application
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
#############################################################################

ifeq ($(CONFIG_NETUTILS_NETCAT),y)
CONFIGURED_APPS += netutils/netcat
endif
38 changes: 38 additions & 0 deletions netutils/netcat/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#############################################################################
#
# netutils/netcat/Makefile
# Netcat networking application
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
#############################################################################

include $(APPDIR)/Make.defs
-include $(SDKDIR)/Make.defs

# built-in application info

PROGNAME = $(CONFIG_NETUTILS_NETCAT_PROGNAME)
PRIORITY = $(CONFIG_NETUTILS_NETCAT_PRIORITY)
STACKSIZE = $(CONFIG_NETUTILS_NETCAT_STACKSIZE)

# Example

ASRCS =
CSRCS =
MAINSRC = netcat_main.c

include $(APPDIR)/Application.mk
69 changes: 69 additions & 0 deletions netutils/netcat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Network Utilities / `netcat` tool

netcat TCP/IP swiss army knife

It was reimplemented from scratch for NuttX


## DEMO ##

[![weboftwins-osvehicle-2020-rzr](
https://files.mastodon.social/media_attachments/files/105/163/916/892/863/178/original/05468e28b4463f95.png
)](
https://mastodon.social/@rzr/105225153152922220#weboftwins-osvehicle-2020-rzr
"weboftwins-osvehicle-2020-rzr")

* https://purl.org/rzr/weboftwins

## USAGE ##

Usage is straigtforward:

nsh> help ; netcat
Usage: netcat [-l] [destination] [port] [file]

nsh> renew eth0 ; ifconfig

eth0 Link encap:Ethernet HWaddr 52:13:FF:FF:FF:FF at UP
inet addr:192.168.1.42 DRaddr:192.168.1.254 Mask:255.255.255.0

In the following examples, following configuration is used:

- target (nuttx) is 192.168.1.42
- host (linux) is 192.168.1.55

### Server ###

As a server on NuttX and Linux's netcat as client

nsh> netcat -l

sh> cat /proc/version | netcat 192.168.1.42 31337
Linux ...

Default port is 31337 but it can changed.

nsh> renew eth0 ; ifconfig ; netcat -l
log: net: listening on :31337
Linux ...

### Client ###

Start Server on GNU/Linux:

sh> ip addr show && netcat -l 31337

Client side on nuttx, we create

nsh> help ; renew eth0 ; ifconfig
nsh> netcat 192.168.1.55 31337 /proc/version

### Using pipes ###

mkfifo /dev/fifo
netcat 192.168.1.55 31337 /proc/fifo
help > /dev/fifo

fxos8700cq > /dev/fifo &
fxos8700cq [7:100]
netcat 192.168.1.55 31337 /dev/fifo
Loading

0 comments on commit 5dabc2e

Please sign in to comment.