strnlen() is used for formatting messages in debug.c. As strnlen() is
unknown in C99, the compiler emits a warning even if configure has
detected the presence of strnlen() in glibc and has set HAVE_STRNLEN
accordingly. To overcome this, the symbol _GNU_SOURCE now is set when
HAVE_STRNLEN and __GNUC__ are defined but not _GNU_SOURCE. This works
not only for glibc prior 2.10 but also for newer versions that conform
to POSIX.1-2008 (see strnlen(1)).
The switch {} construct in the function coap_dispatch{} doesn't had a
'default:' directive so the compiler is complaining about that with a
warning.
src/net.c: In function 'coap_dispatch':
src/net.c:1545:5: warning: switch missing default case [-Wswitch-default]
switch (rcvd->pdu->hdr->type) {
^
Directory examples/contiki now contains a small example server for
Contiki and a Makefile for platform minimal-net.
Build:
make contiki # clones Contiki
make server # creates the minimal-net coap server
Run:
Unfortunately, you have to run the server with sudo unless you
set CAP_NET_ADMIN for both, the server executable, and ifconfig
(sudo setcap cap_net_admin+pei ...).
sudo ./server
Then, add the server's interface address to the tap0 device and
optionally set a default route:
sudo ip -6 a a aaaa::1000 dev tap0
sudo ip -6 r a aaaa::/64 dev tap0
Although everything should work now, it does not. I had to send
router advertisements on tap0:
sudo radvd -C ./radvd.conf
Note that on Debian (and Ubuntu, and ...), radvd will not start
when IPv6 forwarding is disabled (which is usually the case on
end systems). Trying to enable like this did not work for me:
sudo sysctl -w net.ipv6.conf.tap0.forwarding=1
sudo sysctl -w net.ipv6.conf.tap0.mc_forwarding=1
Workaround (ugly): get the radvd sources, compile them and use that.
To get rid of the awful (and buggy!) ALIGNPTR stuff that used to
be in coap_pdu_clear(), a new memory type COAP_PDU_BUF has been
introduced for Contiki. This allows storing the message payload
in its own memory chunk similar to the way it is stored for lwIP.
On POSIX systems we always have a file device as integer. So picking up
the 'socketfd' within the struct. Otherwise the compiler doesn't really
now what member to pick and gives up.
src/net.c: In function 'coap_new_context':
src/net.c:369:13: error: incompatible types when assigning to type 'int' from type 'union <anonymous>'
c->sockfd = c->endpoint->handle;
^
this sidesteps the copying parts of coap_parse_pdu, using the directo
allocation of the pdu payload data from the package's pbuf, whose
reference is consumed.
the old implementation stuffed the pdu struct in front of the
transport-level pbuf, and preserved it on the stack while the packages
were sent.
this had two advantages:
* saving ram
* preserving the other implementation's structure of pdu->hdr == pdu+1
(ie. starting right after the pdu struct)
but two disadvantages:
* bad readability and pointer juggling in the send routine
* relying on the send function to block until the package is out (which
works for simple implementations of lwip drivers but not dma etc)
if something really assumes the contiguous memory structure, it will
show (unfortunately by corrupting other pdu structs), and chances are
people use ->hdr anyway.
this is required for the packages incoming via an endpoint to find their
way back to the context.
the relationship between context and endpoint is still to be documented.
* resolve file resolution conflicts between lwip and libcoap in favor of
lwip by rearranging the makefile
* cover the config.h of a configured base libcoap with the local one
using the deprecated -I- gcc switch
* enable etharp (no idea why it wouldn't work ootb, the complete
server.c lwip-contrib copy needs to be reviewed)
* disable optimizations for easier debugging, enable -g3 for macro
expansions
those things need to reside in mem.h (instead of living implementation
dependently inside mem.c) because coap_malloc_type(MY_TYPE, ...) is
converted to memp_malloc(MEMP_MY_TYPE) and thus needs to be done in the
preprocessor. (the alternative would be to switch on the MY_TYPE enum,
which would be harder to maintain).
they are now only accessed using helper functions, for a package looks
different in lwip.
in addition, the local_interface is now passed to coap_handle_message
not as an argument (because that would mean mixing different arguments
in the population of the node's local interface), but as a part of the
incoming package (as assigned in coap_network_read).