Commit Graph
86 Commits
Author SHA1 Message Date
jcmichelou fdf3dabb0c Activate dual-stacked BSD socket logic on linux after validation. 2017-06-10 16:46:37 +02:00
jcmichelou 78148d0c20 Merge develop into win32 2017-06-10 16:19:12 +02:00
Chanhee 69197feb15 coap_io_lwip.c: fix typos in comments
Few typos are fixed.
2017-06-01 19:58:35 +09:00
jcmichelou 85ca4aab36 Fix size_t downcast to unsigned long warning. 2017-05-17 19:42:15 +02:00
jcmichelou ab958ca586 Activate dual-stacked code first only on windows since on linux it is dependent on the version of the kernel. 2017-05-12 20:02:32 +02:00
jcmichelou 78ed10b758 Add explicit platform-independent support for dual-stacked sockets (ipv6 sockets are implicitly dual-stacked on Linux by default, but not on Windows).
Correctly map / unmap ipv4 addresses into ipv6 addresses so that ipv4 queries to an ipv6 dual-stacked server actually do work.
2017-05-08 19:32:28 +02:00
jcmichelou ba68ba85c0 Do not make exported symbols different between release and debug builds, this breaks the ABI of the DLL.
Do not make reference to NDEBUG in public headers to modify the ABI. This macro is defined automatically in all windows projects and will create a lot of confusion.
2017-05-07 18:18:33 +02:00
jcmichelou 95d8e2c8e0 Use C-style prototypes for coap_statup and coap_cleanup 2017-05-06 18:25:10 +02:00
jcmichelou 3042a287bc Fix a problem with the use of control structures in sendmsg / recvmsg. These are not struct sockaddr, they are ip_pktinfo or ipv6_pktinfo, so local_interface->addr.size is irrelevant, even causing an overflow with writing zero bytes outside of the control structure on the stack, even though it happens to work because the buffer is large enough.
Prevent invalid addresses from being used as source address with sendmsg. On linux, they are just ignored, so it is the same as not specifying one, but on windows they cause an error. In both case it is simpler not to include any control info if the intent is to let the interface be chosen by the network stack.
2017-05-06 16:56:32 +02:00
jcmichelou 9b3cf894fc Use crypto secure version of rand to generate the message ids on windows. 2017-05-05 20:46:29 +02:00
jcmichelou 9b647d5d05 Add visual studio 2015 solution and project files for building libcoap on windows.
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.
2017-05-05 20:29:10 +02:00
Olaf Bergmann ac94964b45 pdu.h: new methods FETCH, PATCH, iPATCH from RFC 8132 2017-04-07 10:14:22 +02:00
Pawel Winogrodzki 6112604569 Makingcoap_transaction_id() always use the peer for ID generation. 2017-04-04 02:32:45 -07:00
Pawel Winogrodzki b130109c04 Applying agreed changes. 2017-03-29 02:51:21 -07:00
Pawel Winogrodzki 4b112431ff Changing u_short to uint16_t inside pdu.c. 2017-03-28 17:15:37 -07:00
Pawel Winogrodzki d6d7df8bfe Fixing comments inside coap_time.c and net.c. 2017-03-28 17:04:46 -07:00
Pawel Winogrodzki 48fb2443df Fixing coap_io.c comments. 2017-03-28 16:54:23 -07:00
Pawel Winogrodzki 8090dc7ba8 Fixing other sources needing <limits.h>. 2017-03-20 17:07:29 -07:00
Pawel Winogrodzki 45805772ca Adding <limits.h> to pdu.c.
It seems that POSIX builds didn't understand what
"USHRT_MAX" means and that macro is defined inside limits.h.
2017-03-20 16:59:06 -07:00
Pawel Winogrodzki a42894b053 Removing unnecessary line in coap_time.c. 2017-03-20 16:54:37 -07:00
Pawel Winogrodzki fc3e33b011 Fixing invalid coap_io.c line. 2017-03-20 16:41:27 -07:00
Pawel Winogrodzki 9adc4eb6a7 Fixing /W4 warnings for Windows builds.
Removing all of the /W4 level warnings from the code.
No functional changes.

Signed-off-by: Pawel Winogrodzki <pawelwi@microsoft.com>
2017-03-20 15:48:33 -07:00
Pawel Winogrodzki 445383a0b5 Fixing coap_remove_failed_observers() loop.
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>
2017-03-10 17:55:34 -08:00
Pawel Winogrodzki eb1fae94ed Fixing Option Delta and Option Length encoding.
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>
2017-03-08 11:09:27 +01:00
Olaf Bergmann 292b0f0790 address.[hc]: Fixed byteorder in coap_is_mcast() on platform posix
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.
2016-12-15 11:12:22 +01:00
Olaf Bergmann fb66920d5f net.c: Fix response code for unknown resources
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.
2016-12-14 19:56:14 +01:00
Olaf Bergmann 6437190232 pdu.c: check for zero length before invoking memcmp()
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).
2016-12-01 17:12:42 +01:00
Olaf Bergmann beeb6b62d4 net.c: re-arrange code to avoid memory leakage
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.
2016-12-01 16:50:11 +01:00
Olaf Bergmann 41af3304f0 net.c: explicitly clear pointer to free'd storage
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().
2016-12-01 14:50:16 +01:00
Olaf Bergmann 4721d5d527 coap_io.c: avoid use of tainted data from recvmsg
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.
2016-12-01 14:10:31 +01:00
Joakim Nohlgård ed6ca0efd6 debug: Fix off-by-1 error in coap_show_pdu block size output 2016-12-01 13:02:28 +01:00
Olaf Bergmann 0fd7695733 pdu.c: Added missing response phrases
Some response phrases were missing in the data structure coap_error
that is used to return a humna-readable error description in a
diagnostic payload.
2016-12-01 13:01:07 +01:00
Jean-Philippe Comtois 718b2dfad5 pdu.c: correct response codes for 2.xx
Fixed response codes and reason phrase for diagnostic payloads
for 2.xx responses.
2016-12-01 12:58:16 +01:00
Olaf Bergmann 8054981362 coap_io.c: removed erraneous memcpy() in coap_network_read()
@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.
2016-11-19 17:22:12 +01:00
Olaf Bergmann 92ecd52454 coap_io.c: platform-specific network I/O for FreeBSD
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.
2016-11-19 17:13:01 +01:00
Olaf Bergmann ad40407f88 net.c: improved support for RFC 7967 (No-Response option)
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
2016-11-16 22:24:26 +01:00
Olaf Bergmann c16918dfff block.c: fixed possible buffer overflow in coap_write_block_opt()
Joel Sandin has pointed out that a buffer flow was possible in
coap_write_block_opt() as the block number is encoded without
range check into the local variable buf. As the block number is
stored in 20 bits, the buffer is enlarged to 4 bytes to fix this.

As a second counter-measure against wrong block numbers, the function
coap_get_block() is modified to check the decoded Block option.
Numbers larger than 0xFFFFF (20 bits) cause this option to be ignored.
2016-09-22 14:39:12 +02:00
Olaf Bergmann cb6d3c43ed uri.[hc]: make 1st argument of coap_split_uri() const
Issue #37 [0] argued that coap_split_uri() should not change the
string that was passed as its first argument. The old behavior
was to normalize the scheme and the host part of the given URI by
converting both to lower case. This commit drops that normalization
step and leaves the original string as is. As a consequence,
implementations that employ virtual hosts now must canonicalize
the host part by themselves.

CAUTION: The constness is not (yet) reflected in the str components
of the result parameter of type coap_uri_t. Care must be taken not
to accidently change an immutable component of the coap_uri_t object.

[0] https://github.com/obgm/libcoap/issues/37
2016-07-06 12:48:21 +02:00
chrysn 6b6840599a lwip: cleanups of leftover variables and similar compiler warnings
note on coap_read removal: as the lwip implementation currently launches
the package handling right from the recv callback, a coap_read function
is not meaningful (as it is in posix or contiki where it actively
fetches the messages from the network buffer).
2016-06-22 12:38:01 +02:00
chrysn 909d863a4e lwip: Use latest version
This drops the cumbersome mintapif mechanisms from server.c, fixes
header troubles that have popped up probably during the header cleanups,
drops old workarounds and enables IPv6.
2016-06-22 12:37:27 +02:00
chrysn 0f3be6128b lwip: Drop include in coap_io.h
The include is not required, as the `struct ud_pcb *` pointer doesn't
require the struct to be known yet, but caused trouble when the include
led to an inclusion loop back again to libcoap via the lwippools. (The
loop was caught by include guards and caused undeclared type errors
because the later parts of the headers were not yet processed).
2016-06-22 12:36:23 +02:00
chrysn 0e7e269ecb net: Fix coap_new_endpoint error handling
The wrong sequence caused segfaults instead of regular error returns
using LWIP (where the error is visible eg. when binding to a different
address type than the socket was created for).

The free in the error path is fixed as well. (coap_malloc_type requires
a coap_free_type as per documentation, although some implementations
might not be strict about it).
2016-06-22 12:36:13 +02:00
Olaf Bergmann fa69aeec79 option.c: fixed off-by-one error in Uri-Query encoder
This modification fixes a bug in coap_opt_setheader() that could
have caused the function's return value to be larger than the
value passed as buffer size. As this function is called by
make_decoded_option() in uri.c, the subsequent assert() will fire
in that case. The bug occurred in the rare case that the contents
of a query option were longer 13 bytes and the buffer was smaller
than the number of bytes that were needed to encode the content
length.

This bug has been reported by Oscar Novo.
2016-06-10 13:34:51 +02:00
Olaf Bergmann 7dea55099f resource.c: bugfix: Memory leak from hash table
The function coap_delete_all_resources() did not free the hash buckets
created by HASH_ADD. Thus, the iterator must call HASH_DELETE to free
the allocated storage.

This bug has been discovered  by
Jean-Michel Julien <Jean-Michel.Julien@trilliantinc.com>
who also provided this fix. See [1] for more information.

[1] https://sourceforge.net/p/libcoap/mailman/message/34994226/
2016-04-06 12:43:27 +02:00
Olaf Bergmann 4a5f381978 src/net.c: bugfix: remove observer on cancel before invoking resource handler
When a client sends a GET request with Observe: 1, it must be removed from
the list of observers before the resource handler is called. Otherwise, it
will add an Observe option to its response.
2016-04-05 14:51:48 +02:00
Vlad Lungu 81865503a1 Use LWIP_PLATFORM_DIAG for LWIP
fprintf() is not guaranteed to be available. Or even printf().

Signed-off-by: Vlad Lungu <vlad.lungu@windriver.com>
2016-02-16 15:44:59 +01:00
Olaf Bergmann 4c299f9da6 Makefile.contiki: Fixed build flags for Contiki-3.0
Some configuration flags have been changed since Contiki version 3.
The Makefile.contiki for building a server example that uses libcoap
as a Contiki app has been fixed. The following builds now succeed:

make -f Makefile.contiki TARGET=minimal-net
make -f Makefile.contiki TARGET=econotag
make -f Makefile.contiki TARGET=mbxxx
2016-02-16 13:12:26 +01:00
Carsten Schoenert 8a8790cfc3 fixup small typos, no functional changes
There are few miss spelled words 'reponse', fixed up into the meaned word
'response'.
2016-01-29 16:31:53 +01:00
onovo1 4c5c0e6c61 Update net.c 2016-01-28 13:57:00 +02:00
Carsten Schoenert f4166a536f coap.h: adding main header file into various source files
After splitting of the platform header part within libcoap some source
files that use functions of the network stack need to include coap.h
(which is including the libcoap.h) to get the platform specific header file
for the network stack.
Sort list of included headers in alphabetical order.
2016-01-10 17:49:07 +01:00