* see http://www.aarongifford.com/ */
#include "sha2/sha2.h"
- typedef DTLS_SHA256_CTX dtls_hash_ctx;
+ typedef dtls_sha256_ctx dtls_hash_ctx;
typedef dtls_hash_ctx *dtls_hash_t;
- #define DTLS_HASH_CTX_SIZE sizeof(DTLS_SHA256_CTX)
+ #define DTLS_HASH_CTX_SIZE sizeof(dtls_sha256_ctx)
-static inline void
+INLINE_API void
dtls_hash_init(dtls_hash_t ctx) {
- DTLS_SHA256_Init((DTLS_SHA256_CTX *)ctx);
+ dtls_sha256_init((dtls_sha256_ctx *)ctx);
}
-static inline void
+INLINE_API void
dtls_hash_update(dtls_hash_t ctx, const unsigned char *input, size_t len) {
- DTLS_SHA256_Update((DTLS_SHA256_CTX *)ctx, input, len);
+ dtls_sha256_update((dtls_sha256_ctx *)ctx, input, len);
}
-static inline size_t
+INLINE_API size_t
dtls_hash_finalize(unsigned char *buf, dtls_hash_t ctx) {
- DTLS_SHA256_Final(buf, (DTLS_SHA256_CTX *)ctx);
+ dtls_sha256_final(buf, (dtls_sha256_ctx *)ctx);
return DTLS_SHA256_DIGEST_LENGTH;
}
#endif /* WITH_SHA256 */
NULL
};
-static CAIPPacketReceivedCallback g_packetReceivedCallback = NULL;
+#if defined (_WIN32)
+#define IFF_UP_RUNNING_FLAGS (IFF_UP)
- static CAIPExceptionCallback g_exceptionCallback;
+ char* caips_get_error(){
+ static char buffer[32];
+ snprintf(buffer, 32, "%i", WSAGetLastError());
+ return buffer;
+ }
+#define CAIPS_GET_ERROR \
+ caips_get_error()
+#else
+#define IFF_UP_RUNNING_FLAGS (IFF_UP|IFF_RUNNING)
+
+#define CAIPS_GET_ERROR \
+ strerror(errno)
+#endif
+ static CAIPErrorHandleCallback g_ipErrorHandler = NULL;
- static CAIPPacketReceivedCallback g_packetReceivedCallback;
++static CAIPPacketReceivedCallback g_packetReceivedCallback = NULL;
+
static void CAHandleNetlink();
static void CAFindReadyMessage();
+#if !defined(WSA_WAIT_EVENT_0)
static void CASelectReturned(fd_set *readFds, int ret);
+#else
+static void CAEventReturned(HANDLE);
+#endif
static void CAProcessNewInterface(CAInterface_t *ifchanged);
static CAResult_t CAReceiveMessage(int fd, CATransportFlags_t flags);
}
char *secure = (endpoint->flags & CA_SECURE) ? "secure " : "";
- (void)secure; // eliminates release warning
+
- (void)secure; // eliminates release warning
- (void)cast;
++ (void)cast; // eliminates release warning
+ (void)fam;
+
struct sockaddr_storage sock;
CAConvertNameToAddr(endpoint->addr, endpoint->port, &sock);
ssize_t len = sendto(fd, data, dlen, 0, (struct sockaddr *)&sock, socklen);
if (-1 == len)
{
- (void)cast;
- (void)fam;
+ // If logging is not defined/enabled.
+ if (g_ipErrorHandler)
+ {
+ g_ipErrorHandler(endpoint, data, dlen, CA_SEND_FAILED);
+ }
OIC_LOG_V(ERROR, TAG, "%s%s %s sendTo failed: %s", secure, cast, fam, strerror(errno));
}
else
{
OIC_LOG_V(INFO, TAG, "%s%s %s sendTo is successful: %zd bytes", secure, cast, fam, len);
}
+#else
+ int err = 0;
+ int len = 0;
+ int sent = 0;
+ do {
+ len = sendto(fd, ((char*)data) + sent, dlen - sent, 0, (struct sockaddr *)&sock, socklen);
+ if (SOCKET_ERROR == len)
+ {
+ err = WSAGetLastError();
+ if ((WSAEWOULDBLOCK != err) && (WSAENOBUFS != err))
+ {
++ // If logging is not defined/enabled.
++ if (g_ipErrorHandler)
++ {
++ g_ipErrorHandler(endpoint, data, dlen, CA_SEND_FAILED);
++ }
++
+ OIC_LOG_V(ERROR, TAG, "%s%s %s sendTo failed: %i", secure, cast, fam, err);
+ }
+ }
+ else
+ {
+ sent += len;
+ if (sent != len)
+ {
+ OIC_LOG_V(DEBUG, TAG, "%s%s %s sendTo (Partial Send) is successful: "
+ "currently sent: %ld bytes, "
+ "total sent: %ld bytes, "
+ "remaining: %ld bytes",
+ secure, cast, fam, len, sent, dlen-sent);
+ }
+ else
+ {
+ OIC_LOG_V(INFO, TAG, "%s%s %s sendTo is successful: %ld bytes",
+ secure, cast, fam, len);
+ }
+ }
+ } while ((SOCKET_ERROR == len) && ((WSAEWOULDBLOCK == err) || (WSAENOBUFS == err)) || (sent < dlen));
+#endif
}
static void sendMulticastData6(const u_arraylist_t *iflist,