Merge pull request #2084 from cesanta/standex

updated Makefiles and symlinks
This commit is contained in:
Sergio R. Caprile authored and GitHub committed 2023-02-21 17:31:02 -03:00
commit 2c6fc99c68
29 files changed
+213 -113

No files matched your search

+26 -14
View File
@@ -1,20 +1,32 @@
PROG ?= example PROG ?= example # Program we are building
CFLAGS ?= -W -Wall -DMG_ENABLE_LINES=1 DELETE = rm -rf # Command to remove files
SSL = ? OUT ?= -o $(PROG) # Compiler argument for output file
SOURCES = main.c mongoose.c # Source code files
CFLAGS = -W -Wall -Wextra -g -I. # Build options
ifeq "$(SSL)" "MBEDTLS" # Mongoose build options. See https://mongoose.ws/documentation/#build-options
CFLAGS += -DMG_ENABLE_MBEDTLS=1 -lmbedtls -lmbedcrypto -lmbedx509 -I$(MBEDTLS)/include -I/usr/include -L$(MBEDTLS)/lib -lmbedtls -lmbedcrypto -lmbedx509 CFLAGS_MONGOOSE += -DMG_ENABLE_LINES=1
ifeq ($(OS),Windows_NT) # Windows settings. Assume MinGW compiler. To use VC: make CC=cl CFLAGS=/MD OUT=/Feprog.exe
PROG ?= example.exe # Use .exe suffix for the binary
CC = gcc # Use MinGW gcc compiler
CFLAGS += -lws2_32 # Link against Winsock library
DELETE = cmd /C del /Q /F /S # Command prompt command to delete files
OUT ?= -o $(PROG) # Build output
MAKE += WINDOWS=1 CC=$(CC)
endif endif
ifeq "$(SSL)" "OPENSSL" all: $(PROG) # Default target. Build and run program
CFLAGS += -DMG_ENABLE_OPENSSL=1 -lssl -lcrypto $(RUN) ./$(PROG) $(ARGS)
endif
all: $(PROG) $(PROG): $(SOURCES) # Build program from sources
$(DEBUGGER) ./$(PROG) $(ARGS) $(CC) $(SOURCES) $(CFLAGS) $(CFLAGS_MONGOOSE) $(CFLAGS_EXTRA) $(OUT)
$(PROG): main.c clean: # Cleanup. Delete built program and all build artifacts
$(CC) ../../mongoose.c -I../.. $(CFLAGS) $(EFLAGS) -o $(PROG) main.c $(DELETE) $(PROG) *.o *.obj *.exe *.dSYM mbedtls
clean: # see https://mongoose.ws/tutorials/tls/#how-to-build for TLS build options
rm -rf $(PROG) *.o *.dSYM *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb
mbedtls: # Pull and build mbedTLS library
git clone --depth 1 -b v2.28.2 https://github.com/mbed-tls/mbedtls $@
$(MAKE) -C mbedtls/library
+1
View File
@@ -0,0 +1 @@
../../mongoose.c
+1
View File
@@ -0,0 +1 @@
../../mongoose.h
+25 -14
View File
@@ -1,21 +1,32 @@
PROG ?= example PROG ?= example # Program we are building
CFLAGS ?= -DMG_IO_SIZE=128 DELETE = rm -rf # Command to remove files
SSL = ? OUT ?= -o $(PROG) # Compiler argument for output file
SOURCES = main.c mongoose.c # Source code files
CFLAGS = -W -Wall -Wextra -g -I. # Build options
ifeq "$(SSL)" "MBEDTLS" # Mongoose build options. See https://mongoose.ws/documentation/#build-options
CFLAGS += -DMG_ENABLE_MBEDTLS=1 -lmbedtls -lmbedcrypto -lmbedx509 CFLAGS_MONGOOSE += -DMG_IO_SIZE=128 -DMG_ENABLE_LINES=1
ifeq ($(OS),Windows_NT) # Windows settings. Assume MinGW compiler. To use VC: make CC=cl CFLAGS=/MD OUT=/Feprog.exe
PROG ?= example.exe # Use .exe suffix for the binary
CC = gcc # Use MinGW gcc compiler
CFLAGS += -lws2_32 # Link against Winsock library
DELETE = cmd /C del /Q /F /S # Command prompt command to delete files
OUT ?= -o $(PROG) # Build output
MAKE += WINDOWS=1 CC=$(CC)
endif endif
ifeq "$(SSL)" "OPENSSL" all: $(PROG) # Default target. Build and run program
CFLAGS += -DMG_ENABLE_OPENSSL=1 -lssl -lcrypto $(RUN) ./$(PROG) $(ARGS)
endif
all: $(PROG) $(PROG): $(SOURCES) # Build program from sources
$(DEBUGGER) ./$(PROG) $(ARGS) $(CC) $(SOURCES) $(CFLAGS) $(CFLAGS_MONGOOSE) $(CFLAGS_EXTRA) $(OUT)
clean: # Cleanup. Delete built program and all build artifacts
$(DELETE) $(PROG) *.o *.obj *.exe *.dSYM mbedtls
$(PROG): main.c # see https://mongoose.ws/tutorials/tls/#how-to-build for TLS build options
$(CC) ../../mongoose.c -I../.. -W -Wall $(CFLAGS) $(EXTRA_CFLAGS) -o $(PROG) main.c
clean: mbedtls: # Pull and build mbedTLS library
rm -rf $(PROG) *.o *.dSYM *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb git clone --depth 1 -b v2.28.2 https://github.com/mbed-tls/mbedtls $@
$(MAKE) -C mbedtls/library
+1
View File
@@ -0,0 +1 @@
../../mongoose.c
+1
View File
@@ -0,0 +1 @@
../../mongoose.h
+25 -15
View File
@@ -1,22 +1,32 @@
PROG ?= example PROG ?= example # Program we are building
CFLAGS ?= -DMG_ENABLE_LINES $(EXTRA) DELETE = rm -rf # Command to remove files
OUT ?= -o $(PROG) # Compiler argument for output file
SOURCES = main.c mongoose.c # Source code files
CFLAGS = -W -Wall -Wextra -g -I. # Build options
ifneq ($(MBEDTLS),) # Mongoose build options. See https://mongoose.ws/documentation/#build-options
CFLAGS += -DMG_ENABLE_MBEDTLS=1 -I$(MBEDTLS)/include -I/usr/include CFLAGS_MONGOOSE += -DMG_ENABLE_LINES=1
CFLAGS += -L$(MBEDTLS)/lib -lmbedtls -lmbedcrypto -lmbedx509
ifeq ($(OS),Windows_NT) # Windows settings. Assume MinGW compiler. To use VC: make CC=cl CFLAGS=/MD OUT=/Feprog.exe
PROG ?= example.exe # Use .exe suffix for the binary
CC = gcc # Use MinGW gcc compiler
CFLAGS += -lws2_32 # Link against Winsock library
DELETE = cmd /C del /Q /F /S # Command prompt command to delete files
OUT ?= -o $(PROG) # Build output
MAKE += WINDOWS=1 CC=$(CC)
endif endif
ifneq ($(OPENSSL),) all: $(PROG) # Default target. Build and run program
CFLAGS += -DMG_ENABLE_OPENSSL=1 -I$(OPENSSL)/include $(RUN) ./$(PROG) $(ARGS)
CFLAGS += -L$(OPENSSL)/lib -lssl -lcrypto
endif
all: $(PROG) $(PROG): $(SOURCES) # Build program from sources
$(DEBUGGER) ./$(PROG) $(ARGS) $(CC) $(SOURCES) $(CFLAGS) $(CFLAGS_MONGOOSE) $(CFLAGS_EXTRA) $(OUT)
clean: # Cleanup. Delete built program and all build artifacts
$(DELETE) $(PROG) *.o *.obj *.exe *.dSYM mbedtls
$(PROG): main.c # see https://mongoose.ws/tutorials/tls/#how-to-build for TLS build options
$(CC) ../../mongoose.c -I../.. -W -Wall $(CFLAGS) -o $(PROG) main.c
clean: mbedtls: # Pull and build mbedTLS library
rm -rf $(PROG) *.o *.dSYM *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb git clone --depth 1 -b v2.28.2 https://github.com/mbed-tls/mbedtls $@
$(MAKE) -C mbedtls/library
+1
View File
@@ -0,0 +1 @@
../../mongoose.c
+1
View File
@@ -0,0 +1 @@
../../mongoose.h
+7 -10
View File
@@ -1,28 +1,25 @@
PROG ?= example # Program we are building
DELETE = rm -rf # Command to remove files
OUT ?= -o $(PROG) # Compiler argument for output file
SOURCES = main.c mongoose.c # Source code files SOURCES = main.c mongoose.c # Source code files
CFLAGS = -W -Wall -Wextra -g -I. # Build options CFLAGS = -W -Wall -Wextra -g -I. # Build options
# Mongoose build options. See https://mongoose.ws/documentation/#build-options # Mongoose build options. See https://mongoose.ws/documentation/#build-options
CFLAGS_MONGOOSE += -DMG_ENABLE_LINES=1 CFLAGS_MONGOOSE += -DMG_ENABLE_LINES=1
ifeq ($(OS),Windows_NT) ifeq ($(OS),Windows_NT) # Windows settings. Assume MinGW compiler. To use VC: make CC=cl CFLAGS=/MD OUT=/Feprog.exe
# Windows settings. Assume MinGW compiler. To use VC: make CC=cl CFLAGS=/MD OUT=/Feprog.exe
PROG ?= example.exe # Use .exe suffix for the binary PROG ?= example.exe # Use .exe suffix for the binary
CC = gcc # Use MinGW gcc compiler CC = gcc # Use MinGW gcc compiler
CFLAGS += -lws2_32 # Link against Winsock library CFLAGS += -lws2_32 # Link against Winsock library
DELETE = cmd /C del /Q /F /S # Command prompt command to delete files DELETE = cmd /C del /Q /F /S # Command prompt command to delete files
OUT ?= -o $(PROG) # Build output OUT ?= -o $(PROG) # Build output
else
# Mac, Linux
PROG ?= example
DELETE = rm -rf
OUT ?= -o $(PROG)
endif endif
all: $(PROG) all: $(PROG) # Default target. Build and run program
$(RUN) ./$(PROG) $(ARGS) $(RUN) ./$(PROG) $(ARGS)
$(PROG): $(SOURCES) $(PROG): $(SOURCES) # Build program from sources
$(CC) $(SOURCES) $(CFLAGS) $(CFLAGS_MONGOOSE) $(CFLAGS_EXTRA) $(OUT) $(CC) $(SOURCES) $(CFLAGS) $(CFLAGS_MONGOOSE) $(CFLAGS_EXTRA) $(OUT)
clean: clean: # Cleanup. Delete built program and all build artifacts
$(DELETE) $(PROG) *.o *.obj *.exe *.dSYM $(DELETE) $(PROG) *.o *.obj *.exe *.dSYM
+22 -7
View File
@@ -1,10 +1,25 @@
PROG ?= example PROG ?= example # Program we are building
DELETE = rm -rf # Command to remove files
OUT ?= -o $(PROG) # Compiler argument for output file
SOURCES = main.c mongoose.c # Source code files
CFLAGS = -W -Wall -Wextra -g -I. # Build options
all: $(PROG) # Mongoose build options. See https://mongoose.ws/documentation/#build-options
$(DEBUGGER) ./$(PROG) $(ARGS) #CFLAGS_MONGOOSE += -DMG_ENABLE_LINES
$(PROG): main.c ifeq ($(OS),Windows_NT) # Windows settings. Assume MinGW compiler. To use VC: make CC=cl CFLAGS=/MD OUT=/Feprog.exe
$(CC) main.c ../../mongoose.c -I../.. -W -Wall -DMG_ENABLE_LINES=1 $(CFLAGS) -o $(PROG) PROG ?= example.exe # Use .exe suffix for the binary
CC = gcc # Use MinGW gcc compiler
CFLAGS += -lws2_32 # Link against Winsock library
DELETE = cmd /C del /Q /F /S # Command prompt command to delete files
OUT ?= -o $(PROG) # Build output
endif
clean: all: $(PROG) # Default target. Build and run program
rm -rf $(PROG) *.o *.dSYM *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb $(RUN) ./$(PROG) $(ARGS)
$(PROG): $(SOURCES) # Build program from sources
$(CC) $(SOURCES) $(CFLAGS) $(CFLAGS_MONGOOSE) $(CFLAGS_EXTRA) $(OUT)
clean: # Cleanup. Delete built program and all build artifacts
$(DELETE) $(PROG) *.o *.obj *.exe *.dSYM
+1
View File
@@ -0,0 +1 @@
../../mongoose.c
+1
View File
@@ -0,0 +1 @@
../../mongoose.h
+22 -7
View File
@@ -1,10 +1,25 @@
PROG ?= example PROG ?= example # Program we are building
DELETE = rm -rf # Command to remove files
OUT ?= -o $(PROG) # Compiler argument for output file
SOURCES = main.c mongoose.c # Source code files
CFLAGS = -W -Wall -Wextra -g -I. # Build options
all: $(PROG) # Mongoose build options. See https://mongoose.ws/documentation/#build-options
$(DEBUGGER) ./$(PROG) #CFLAGS_MONGOOSE += -DMG_ENABLE_LINES
$(PROG): ifeq ($(OS),Windows_NT) # Windows settings. Assume MinGW compiler. To use VC: make CC=cl CFLAGS=/MD OUT=/Feprog.exe
$(CC) ../../mongoose.c -I../.. $(CFLAGS) $(EXTRA) -o $(PROG) main.c PROG ?= example.exe # Use .exe suffix for the binary
CC = gcc # Use MinGW gcc compiler
CFLAGS += -lws2_32 # Link against Winsock library
DELETE = cmd /C del /Q /F /S # Command prompt command to delete files
OUT ?= -o $(PROG) # Build output
endif
clean: all: $(PROG) # Default target. Build and run program
rm -rf $(PROG) *.o *.dSYM *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb log.txt $(RUN) ./$(PROG) $(ARGS)
$(PROG): $(SOURCES) # Build program from sources
$(CC) $(SOURCES) $(CFLAGS) $(CFLAGS_MONGOOSE) $(CFLAGS_EXTRA) $(OUT)
clean: # Cleanup. Delete built program and all build artifacts
$(DELETE) $(PROG) *.o *.obj *.exe *.dSYM
+1
View File
@@ -21,6 +21,7 @@ static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
mg_http_serve_dir(c, ev_data, &opts); mg_http_serve_dir(c, ev_data, &opts);
} }
} }
(void) fn_data;
} }
static void log_message(const char *filename, const char *message) { static void log_message(const char *filename, const char *message) {
+1
View File
@@ -0,0 +1 @@
../../mongoose.c
+1
View File
@@ -0,0 +1 @@
../../mongoose.h
+27 -16
View File
@@ -1,22 +1,33 @@
PROG ?= example PROG ?= example # Program we are building
DEFS ?= -DMG_ENABLE_LINES=1 -DMG_ENABLE_TCPIP=1 -DMG_ENABLE_SOCKET=0 -DMG_ENABLE_PACKED_FS=1 -I../.. DELETE = rm -rf # Command to remove files
CFLAGS ?= -W -Wall $(EXTRA_CFLAGS) OUT ?= -o $(PROG) # Compiler argument for output file
LIBS ?= -lpcap SOURCES = main.c mongoose.c net.c packed_fs.c # Source code files
SOURCES = main.c ../../mongoose.c ../device-dashboard/net.c ../device-dashboard/packed_fs.c CFLAGS = -W -Wall -Wextra -g -I. # Build options
CFLAGS += -lpcap # link with libpcap
ifeq "$(SSL)" "MBEDTLS" # Mongoose build options. See https://mongoose.ws/documentation/#build-options
CFLAGS += -DMG_ENABLE_MBEDTLS=1 -lmbedtls -lmbedcrypto -lmbedx509 -I$(MBEDTLS)/include -L$(MBEDTLS)/lib CFLAGS_MONGOOSE += -DMG_ENABLE_LINES=1 -DMG_ENABLE_TCPIP=1 -DMG_ENABLE_SOCKET=0 -DMG_ENABLE_PACKED_FS=1
ifeq ($(OS),Windows_NT) # Windows settings. Assume MinGW compiler. To use VC: make CC=cl CFLAGS=/MD OUT=/Feprog.exe
PROG ?= example.exe # Use .exe suffix for the binary
CC = gcc # Use MinGW gcc compiler
CFLAGS += -lws2_32 # Link against Winsock library
DELETE = cmd /C del /Q /F /S # Command prompt command to delete files
OUT ?= -o $(PROG) # Build output
MAKE += WINDOWS=1 CC=$(CC)
endif endif
ifeq "$(SSL)" "OPENSSL" all: $(PROG) # Default target. Build and run program
CFLAGS += -DMG_ENABLE_OPENSSL=1 -lssl -lcrypto -I$(OPENSSL)/include -L$(OPENSSL)/lib
endif
all: $(PROG)
$(RUN) ./$(PROG) $(ARGS) $(RUN) ./$(PROG) $(ARGS)
$(PROG): main.c $(PROG): $(SOURCES) # Build program from sources
$(CC) $(SOURCES) $(CFLAGS) $(DEFS) -o $(PROG) $(LIBS) $(CC) $(SOURCES) $(CFLAGS) $(CFLAGS_MONGOOSE) $(CFLAGS_EXTRA) $(OUT)
clean: clean: # Cleanup. Delete built program and all build artifacts
rm -rf $(PROG) *.o *.dSYM *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb $(DELETE) $(PROG) *.o *.obj *.exe *.dSYM mbedtls
# see https://mongoose.ws/tutorials/tls/#how-to-build for TLS build options
mbedtls: # Pull and build mbedTLS library
git clone --depth 1 -b v2.28.2 https://github.com/mbed-tls/mbedtls $@
$(MAKE) -C mbedtls/library
+8 -8
View File
@@ -1,6 +1,6 @@
# MIP TCP / IP stack over pcap # Mongoose TCP/IP stack over pcap
This example allows to use Mongoose's MIP built-in TCP/IP stack on systems This example allows to use Mongoose's built-in TCP/IP stack on systems
that support pcap API, i.e. have libpcap library installed. The application that support pcap API, i.e. have libpcap library installed. The application
opens an interface and uses `pcap_next_ex()` for reading packets from the opens an interface and uses `pcap_next_ex()` for reading packets from the
interface, and `pcap_inject()` to write packets to the interface. interface, and `pcap_inject()` to write packets to the interface.
@@ -72,8 +72,8 @@ The diagram of the setup is below:
The quick and simple options are: The quick and simple options are:
- Open your loopback device (probably `lo`), in which case MIP is only reachable from your machine, and MIP also sees echoes of its own traffic. - Open your loopback device (probably `lo`), in which case Mongoose is only reachable from your machine, and it also sees echoes of its own traffic.
- Open your Ethernet/WiFi device (probably `eth0` or `enpXsY` for Ethernet), in which case MIP can access the network and the Internet but is not reachable from within your machine - Open your Ethernet/WiFi device (probably `eth0` or `enpXsY` for Ethernet), in which case Mongoose can access the network and the Internet but is not reachable from within your machine
- If you happen to have a virtual bridge interface (for linking several virtual machines together, for example) (probably `br0` or `virbr0`), you can open it, but it will behave as opening the underlying physical interface. - If you happen to have a virtual bridge interface (for linking several virtual machines together, for example) (probably `br0` or `virbr0`), you can open it, but it will behave as opening the underlying physical interface.
For best results, you should create a virtual interface, which you can use as is, attach to a virtual bridge, or forward/masquerade its traffic. For best results, you should create a virtual interface, which you can use as is, attach to a virtual bridge, or forward/masquerade its traffic.
@@ -88,13 +88,13 @@ In some systems, like for example RHEL7, _name_ is mandatory; in others you migh
### Use a virtual interface ### Use a virtual interface
This is similar to using the loopback device, MIP is only reachable from the hosting machine, but you can add forwarding and masquerading later. Once you have your virtual interface up and running with an IP address, you can configure any services on one end, let's say `my1`, while you open the other end, `my0` with MIP. This is similar to using the loopback device, Mongoose is only reachable from the hosting machine, but you can add forwarding and masquerading later. Once you have your virtual interface up and running with an IP address, you can configure any services on one end, let's say `my1`, while you open the other end, `my0` with Mongoose.
- Add an IP address to one end of the pipe - Add an IP address to one end of the pipe
```sh ```sh
$ sudo ip addr add 192.168.0.1/24 dev my1 $ sudo ip addr add 192.168.0.1/24 dev my1
``` ```
- Start your DHCP server at that interface serving that subnet, or otherwise configure MIP to use a fixed address within that subnet. - Start your DHCP server at that interface serving that subnet, or otherwise configure Mongoose to use a fixed address within that subnet.
- Now start the example opening the other end of the virtual interface: - Now start the example opening the other end of the virtual interface:
```sh ```sh
$ make -C examples/mip-pcap/ clean all ARGS="-i my0" $ make -C examples/mip-pcap/ clean all ARGS="-i my0"
@@ -119,7 +119,7 @@ As you can't access any other host than your workstation, you need to add any re
### Bridge to your network ### Bridge to your network
We will attach one end of the virtual interface to a bridge, which will also be attached to your network interface. In this case, MIP will have access to your network (and through it, to the Internet) and will also be reachable from your own workstation and other hosts in your network. You don't need to add IP addresses as in the example above, unless you don't have a DHCP server in your network, in which case you will configure MIP for a fixed address in your subnet. We will attach one end of the virtual interface to a bridge, which will also be attached to your network interface. In this case, Mongoose will have access to your network (and through it, to the Internet) and will also be reachable from your own workstation and other hosts in your network. You don't need to add IP addresses as in the example above, unless you don't have a DHCP server in your network, in which case you will configure Mongoose for a fixed address in your subnet.
- If you don't already have a virtual bridge interface, as mentioned above, you'll have to create it and attach your network interface (NIC) to it. Your IP address has to be assigned to the bridge, instead of the NIC. If you are using DHCP, the client must run on the bridge interface instead of the NIC. - If you don't already have a virtual bridge interface, as mentioned above, you'll have to create it and attach your network interface (NIC) to it. Your IP address has to be assigned to the bridge, instead of the NIC. If you are using DHCP, the client must run on the bridge interface instead of the NIC.
```sh ```sh
@@ -179,7 +179,7 @@ If you have _Docker_ running, it may introduce firewall rules that will disrupt
### Forward/Masquerade ### Forward/Masquerade
Once you have your virtual interface up and running with an IP address, you can use your Linux to NAT and forward MIP traffic to another interface, for example the one that connects you to the Internet. In this case, MIP will have access to the Internet and will also be reachable from your own workstation; but not from any other hosts in your local network (if there is one). You can use this setup with a direct connection to the Internet or being part of a network, when you want to isolate MIP from the rest of your network. Once you have your virtual interface up and running with an IP address, you can use your Linux to NAT and forward Mongoose traffic to another interface, for example the one that connects you to the Internet. In this case, Mongoose will have access to the Internet and will also be reachable from your own workstation; but not from any other hosts in your local network (if there is one). You can use this setup with a direct connection to the Internet or being part of a network, when you want to isolate Mongoose from the rest of your network.
- We assume you already have a firewall in place (you should); to configure masquerading and forwarding do: - We assume you already have a firewall in place (you should); to configure masquerading and forwarding do:
```sh ```sh
+1
View File
@@ -0,0 +1 @@
../../mongoose.c
+1
View File
@@ -0,0 +1 @@
../../mongoose.h
+1
View File
@@ -0,0 +1 @@
../device-dashboard/net.c
+1
View File
@@ -0,0 +1 @@
../device-dashboard/packed_fs.c
+26 -16
View File
@@ -1,22 +1,32 @@
PROG ?= example PROG ?= example # Program we are building
DEFS ?= -DMG_ENABLE_LINES=1 -DMG_ENABLE_TCPIP=1 -DMG_ENABLE_SOCKET=0 -DMG_ENABLE_PACKED_FS=1 -I../.. DELETE = rm -rf # Command to remove files
CFLAGS ?= -W -Wall $(EXTRA_CFLAGS) OUT ?= -o $(PROG) # Compiler argument for output file
LIBS ?= SOURCES = main.c mongoose.c net.c packed_fs.c # Source code files
SOURCES = main.c ../../mongoose.c ../device-dashboard/net.c ../device-dashboard/packed_fs.c CFLAGS = -W -Wall -Wextra -g -I. # Build options
ifeq "$(SSL)" "MBEDTLS" # Mongoose build options. See https://mongoose.ws/documentation/#build-options
CFLAGS += -DMG_ENABLE_MBEDTLS=1 -lmbedtls -lmbedcrypto -lmbedx509 -I$(MBEDTLS)/include -L$(MBEDTLS)/lib CFLAGS_MONGOOSE += -DMG_ENABLE_LINES=1 -DMG_ENABLE_TCPIP=1 -DMG_ENABLE_SOCKET=0 -DMG_ENABLE_PACKED_FS=1
ifeq ($(OS),Windows_NT) # Windows settings. Assume MinGW compiler. To use VC: make CC=cl CFLAGS=/MD OUT=/Feprog.exe
PROG ?= example.exe # Use .exe suffix for the binary
CC = gcc # Use MinGW gcc compiler
CFLAGS += -lws2_32 # Link against Winsock library
DELETE = cmd /C del /Q /F /S # Command prompt command to delete files
OUT ?= -o $(PROG) # Build output
MAKE += WINDOWS=1 CC=$(CC)
endif endif
ifeq "$(SSL)" "OPENSSL" all: $(PROG) # Default target. Build and run program
CFLAGS += -DMG_ENABLE_OPENSSL=1 -lssl -lcrypto -I$(OPENSSL)/include -L$(OPENSSL)/lib
endif
all: $(PROG)
$(RUN) ./$(PROG) $(ARGS) $(RUN) ./$(PROG) $(ARGS)
$(PROG): main.c $(PROG): $(SOURCES) # Build program from sources
$(CC) $(SOURCES) $(CFLAGS) $(DEFS) -o $(PROG) $(LIBS) $(CC) $(SOURCES) $(CFLAGS) $(CFLAGS_MONGOOSE) $(CFLAGS_EXTRA) $(OUT)
clean: clean: # Cleanup. Delete built program and all build artifacts
rm -rf $(PROG) *.o *.dSYM *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb $(DELETE) $(PROG) *.o *.obj *.exe *.dSYM mbedtls
# see https://mongoose.ws/tutorials/tls/#how-to-build for TLS build options
mbedtls: # Pull and build mbedTLS library
git clone --depth 1 -b v2.28.2 https://github.com/mbed-tls/mbedtls $@
$(MAKE) -C mbedtls/library
+6 -6
View File
@@ -1,6 +1,6 @@
# MIP TCP / IP stack on a tap interface # Mongoose TCP/IP stack on a tap interface
This example allows the use of Mongoose's MIP built-in TCP/IP stack in systems that support a TUN/TAP device. The application opens a TAP device and uses the standard socket interface to read and write on it. This example allows the use of Mongoose's built-in TCP/IP stack in systems that support a TUN/TAP device. The application opens a TAP device and uses the standard socket interface to read and write on it.
The interface can be created by the example itself, but it will also disappear when the example exits. Since we usually need to do something before, like setting up a DHCP server or establishing some connections to the rest of the world, we'll manually create a specific TAP interface and the example will open it; this way, we can have everything setup in advance. The interface can be created by the example itself, but it will also disappear when the example exits. Since we usually need to do something before, like setting up a DHCP server or establishing some connections to the rest of the world, we'll manually create a specific TAP interface and the example will open it; this way, we can have everything setup in advance.
@@ -17,13 +17,13 @@ In some systems, you might need superuser privileges to open the device with the
### Use as a virtual interface ### Use as a virtual interface
In this scenario, MIP is only reachable from the hosting machine, but you can add forwarding and masquerading later. Once you have your TAP interface up and running with an IP address, you can configure any services on it. In this scenario, Mongoose is only reachable from the hosting machine, but you can add forwarding and masquerading later. Once you have your TAP interface up and running with an IP address, you can configure any services on it.
- Add an IP address - Add an IP address
```sh ```sh
$ sudo ip addr add 192.168.0.1/24 dev tap0 $ sudo ip addr add 192.168.0.1/24 dev tap0
``` ```
- Start your DHCP server at that interface serving that subnet, or otherwise configure MIP to use a fixed address within that subnet. - Start your DHCP server at that interface serving that subnet, or otherwise configure Mongoose to use a fixed address within that subnet.
- Now start the example opening the very same TAP interface: - Now start the example opening the very same TAP interface:
```sh ```sh
$ make -C examples/mip-tap/ clean all $ make -C examples/mip-tap/ clean all
@@ -44,7 +44,7 @@ As you can't access any other host than your workstation, you need to add any re
If you happen to have a virtual bridge interface (for linking several virtual machines together, for example) (probably `br0` or `virbr0`), we can take advantage of it. If you happen to have a virtual bridge interface (for linking several virtual machines together, for example) (probably `br0` or `virbr0`), we can take advantage of it.
We will attach one end of the virtual interface to a bridge, which will also be attached to your network interface. In this case, MIP will have access to your network (and through it, to the Internet) and will also be reachable from your own workstation and other hosts in your network. You don't need to add IP addresses as in the example above, unless you don't have a DHCP server in your network, in which case you will configure MIP for a fixed address in your subnet. We will attach one end of the virtual interface to a bridge, which will also be attached to your network interface. In this case, Mongoose will have access to your network (and through it, to the Internet) and will also be reachable from your own workstation and other hosts in your network. You don't need to add IP addresses as in the example above, unless you don't have a DHCP server in your network, in which case you will configure Mongoose for a fixed address in your subnet.
- If you don't already have a virtual bridge interface, as mentioned above, you'll have to create it and attach your network interface (NIC) to it. Your IP address has to be assigned to the bridge, instead of the NIC. If you are using DHCP, the client must run on the bridge interface instead of the NIC. - If you don't already have a virtual bridge interface, as mentioned above, you'll have to create it and attach your network interface (NIC) to it. Your IP address has to be assigned to the bridge, instead of the NIC. If you are using DHCP, the client must run on the bridge interface instead of the NIC.
```sh ```sh
@@ -109,7 +109,7 @@ If you have _Docker_ running, it may introduce firewall rules that will disrupt
### Forward/Masquerade ### Forward/Masquerade
Once you have your virtual interface up and running with an IP address, you can use your Linux to NAT and forward MIP traffic to another interface, for example the one that connects you to the Internet. In this case, MIP will have access to the Internet and will also be reachable from your own workstation; but not from any other hosts in your local network (if there is one). You can use this setup with a direct connection to the Internet or being part of a network, when you want to isolate MIP from the rest of your network. Once you have your virtual interface up and running with an IP address, you can use your Linux to NAT and forward Mongoose traffic to another interface, for example the one that connects you to the Internet. In this case, Mongoose will have access to the Internet and will also be reachable from your own workstation; but not from any other hosts in your local network (if there is one). You can use this setup with a direct connection to the Internet or being part of a network, when you want to isolate Mongoose from the rest of your network.
- We assume you already have a firewall in place (you should); to configure masquerading and forwarding do: - We assume you already have a firewall in place (you should); to configure masquerading and forwarding do:
```sh ```sh
+1
View File
@@ -0,0 +1 @@
../../mongoose.c
+1
View File
@@ -0,0 +1 @@
../../mongoose.h
+1
View File
@@ -0,0 +1 @@
../device-dashboard/net.c
+1
View File
@@ -0,0 +1 @@
../device-dashboard/packed_fs.c