Merge changes from PR #47 related to windows platform support.
Add full windows platform support including correct error checking and working regression tests and examples.
Remove need to build applications using libcoap with -DWITH_POSIX and to include coap_config.h. This applies to the examples as well.
The loop was always exiting after analysing the first observer,
so in case there were more and the first one on the list of
observers didn't match the one we wanted to remove, the
observer never got removed.
Signed-off-by: Pawel Winogrodzki <pawelwi@microsoft.com>
Option Delta and Option Length were being encoded incorrectly
the value 269 and ended up being encoded the same way as 13.
For details please see RFC-7252 "Option Format"
( https://tools.ietf.org/html/rfc7252#page-17 ).
Signed-off-by: Pawel Winogrodzki <pawelwi@microsoft.com>
PR #65 reports wrong encoding of option value 269. The new
unit test t_encode_option9() tests for correct encoding
according to [RFC 7252, Section 3.1](https://tools.ietf.org/html/rfc7252#section-3.1).
For platform posix, the function coap_is_mcast() was moved to address.c
as it has become too large to be inlined by the compiler. This
modification updates the map files accordingly.
Ignoring the subtree m4/ cannot be overridden by subsequent rules.
To include the ax_*.m4 macro sets, the auto-generated files to be
ignored in the m4 directory must be listed explicitly.
This change addresses bug #58.
As IN_MULTICAST does a 32 bit comparison in host byte order,
sin_addr.s_addr needs to be converted using ntohl(). This change
also moves the coap_is_mcast() implementation to address.c because
it has become too complex for inlining.
John Carter has pointed out that non-GET requests for a resource
that does not exist caused a 4.05 response ("Method not allowed").
This fix corrects this behavior to return 4.04 in case a resource
does not exist and, for .well-known/core, 4.05 if anything but
a GET request was received.
The function cmdline_input_from_file() allocates a chunk of memory
to hold the contents of the given file. As libcoap does not offer
an interface to realloc(), we have to determine the required buffer
size before starting to read from the file, leading to a classical
TOCTOU condition.
This change mitigates the defect by first opening the file and then
calling fstat(). Note that the subsequent fread() call takes the
size of the pre-allocated buffer into account.
Free the storage allocated by coap_new_error_response() in unit tests.
This change simplifies automated leak checks as it avoids cluttering
the output with almost false positives.
Only increment block size if it can be done without causing gaps or
overlaps in the byte sequence.
The patch adds a check for alignment to ensure that no gaps appear when
a server responds with a larger block size than the original request
was using.
Ignore the block number sent by the server since that may or may not be
valid. Always recompute based on how many bytes have been sent so far.
Rationale:
Erbium (Contiki CoAP) responds to Block1 request with a Block1 option
containing the server's maximum supported Block1 size (Contiki
configuration option REST_MAX_CHUNK_SIZE). However, the block number
in the Block1 option is the same number as the block number of the
original request.
In coap_pdu_parse(), everything but the header is copied by memcmp()
from the packet to the PDU structure. An additional check ensures
that memcmp() is invoked only when there is data to copy (i.e. the
incoming CoAP message consists of more than just the base header).
On platforms other than Contiki coap_new_context() has returned NULL
when no listen address was supplied but did not free the memory that
was previously allocated for the context object.
This change re-arranges the checks to return before allocating memory.
Static code analysis tools have incorrectly reported a memory leak
in function handle_request(). To avoid this false positive, the
variable response is explicitly set to NULL after releasing the
memory with coap_delete_pdu().
coap_network_read() has used the address size reported by recvmsg()
in the msg_namelen field. As this value might be taken from the
incoming packet, coverity scan reports this value as a possible
security issue.
This fix sets the address size to the expected size and drops the
received packet if msg_namelen differs.
kFreeBSD is a modificated FreeBSD system by Debian with a FreeBSD kernel
and GNU C library (libc) used for the applications. After adding FreeBSD
support for libcoap no more changes needed to get libcoap compiled with
a kFreeBSD installation.
@john-carter has pointed out in bug #48 that valgrind reports
overlapping source and dest ranges in memcpy(). As the source
and destination in this memcpy() invocation are exactly the
same, it can be deleted safely.
For testing, the memcpy() has been replaced by an assert that
checks if these fields are alsways the same.
Processing of ancillary data for IPv4 works different on FreeBSD. This
change uses IP_RECVDSTADDR instead of IP_PKTINFO on FreeBSD.
Setting a the source address with IP_SENDSRCADDR always failed with
error 22 (Invalid argument) for sendmsg() and thus has not been
implemented. Note that for IPv4, this is not a big problem as there
is usually only one interface address even if bound to INADDR_ANY.
Deleting the pkg-config file and also the *.map and *.sym file in a
clean-local target isn't correct as we have no default automatic way to
regenerate *.map and *.sym files before the build of the libcoap is
starting.
Currently there is no need for such a automatic rebuild, the user
normaly doesn't need to do anything on those files. They even don't
should be rebuild by the users in normal cases.
Adding or removing symbols is a sensible thing and the maintenance is
probably up to the developers. Beside that there is the target
'update-map-file' that is used by the developers to (re)build this two
files if needed.
This commit is also adding a new helper target 'dist-local' with a
depency on 'update-map-file' so we are sure to have actual *.map and
*.sym file if we create a tarball for a release.
Moving the .PHONY targets to the end of the Makefile.am as this is the
typical place.
The No-Response option can be used in a request to express disinterest
or interest in certain response classes. This modification adds
No-Response handling for unicast messages and provides basic
functionality for handling multicast responses
When the No-Response became RFC 7967, the numeric value was changed
to better reflect its characteristics. This modification fixes the
reference in the documentation the option value.
The documentation for Observe and Block1/Block2 referenced
outdated Internet Drafts which have become RFCs some time ago.
This change now mentions the correct RFC numbers.