thomasfla / Linux-ESPNOW

An attempt at implementing a direct link between a linux station and an ESP module using ESPNOW protocol for real time robot control
BSD 2-Clause "Simplified" License
178 stars 28 forks source link

Compiling wifiRawEcho on a Pi fails because of missing SO_ATTACH_FILTER and SO_PRIORITY declaration #5

Open sheilbronn opened 1 year ago

sheilbronn commented 1 year ago

When running make in /Linux-ESPNOW/wifiRawEcho on a Raspberry Pi with Debian 11 (Bullseye) I get:

rm -f bin/*
gcc -g -Wall --std=c99 -I Includes/ -o bin/main.o -c src/main.c
src/main.c: In function ‘create_raw_socket’:
src/main.c:145:2: warning: implicit declaration of function ‘bzero’ [-Wimplicit-function-declaration]
  145 |  bzero(&s_dest_addr, sizeof(s_dest_addr));
      |  ^~~~~
src/main.c:169:44: error: ‘SO_ATTACH_FILTER’ undeclared (first use in this function)
  169 |  filter_errno = setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, bpf, sizeof(*bpf));
      |                                            ^~~~~~~~~~~~~~~~
src/main.c:169:44: note: each undeclared identifier is reported only once for each function it appears in
src/main.c:173:46: error: ‘SO_PRIORITY’ undeclared (first use in this function); did you mean ‘IFLA_PRIORITY’?
  173 |  priority_errno = setsockopt(fd, SOL_SOCKET, SO_PRIORITY, &priority, sizeof(priority));
      |                                              ^~~~~~~~~~~
      |                                              IFLA_PRIORITY
src/main.c: In function ‘main’:
src/main.c:184:2: warning: implicit declaration of function ‘nice’ [-Wimplicit-function-declaration]
  184 |  nice(PRIORITY_LVL);
      |  ^~~~
src/main.c:188:6: warning: unused variable ‘packets_received’ [-Wunused-variable]
  188 |  int packets_received = 0;
      |      ^~~~~~~~~~~~~~~~
At top level:
src/main.c:25:16: warning: ‘broadcast_mac’ defined but not used [-Wunused-variable]
   25 | static uint8_t broadcast_mac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
      |                ^~~~~~~~~~~~~
make: *** [Makefile:9: main.o] Error 1

Am I missing something (some declaration for SO_ATTACH_FILTER and SO_PRIORITY ?) that has to be installed for successfull compilation? Couldn't find any hints when google'ing... TIA!

dorucazan commented 1 year ago

Many thanks for your effort @thomasfla! Hi @sheilbronn, I wish to test this code myself, it looks exactly what I need for my project. Had the same compilation issue myself on a Raspberry Pi Zero and on my Ubuntu machine; removing --std=c99 helps a bit. Finally I changed the Makefile to:

FILES := ESPNOW_packet.o main.o
EXEFILE := echo

ESCAPE_START=\033[
ESCAPE_END=m
NOCOLOR=$(ESCAPE_START)0$(ESCAPE_END)
YELLOW=$(ESCAPE_START)1;33$(ESCAPE_END)
BLUE=$(ESCAPE_START)1;34$(ESCAPE_END)
RED=$(ESCAPE_START)0;31$(ESCAPE_END)

SDIR = src
IDIR = Includes
ODIR = bin

CC = gcc
CFLAGS  = -g -Wall -Wno-unused-variable
INCLUDES = -I ${IDIR}

build:clear clean ${ODIR} ${FILES}
    @echo -n "${YELLOW}link     ${BLUE}./${ODIR}/${EXEFILE}${NOCOLOR}..."
    @$(CC) -lm ${ODIR}/*.o -o ${ODIR}/${EXEFILE}
    @echo "done!"

$(FILES): %.o: 
    @echo -n "${YELLOW}compile  ${BLUE}./${SDIR}/$*.c${NOCOLOR}..."
    @$(CC) -c ${SDIR}/$*.c $(CFLAGS) $(INCLUDES) -o ${ODIR}/$@
    @echo "done!"

${ODIR}:
    @echo -n "${YELLOW}create   ${BLUE}./${ODIR}${NOCOLOR}..."
    @mkdir -p ${ODIR}
    @echo "done!"

clean:
    @echo -n "${YELLOW}remove   ${BLUE}./${ODIR}${NOCOLOR}..."
    @rm -rf ${ODIR}
    @echo "done!"

clear: 
    @clear
sheilbronn commented 7 months ago

Are there any updates on this, e.g. regarding compilation on Debian 12 Bookworm?