crypto/armcap.c: detect ARMv8 capabilities [in 32-bit build].
[openssl.git] / crypto / bio / bss_dgram.c
index 0d3c1cf..ec33423 100644 (file)
@@ -66,7 +66,7 @@
 #include <openssl/bio.h>
 #ifndef OPENSSL_NO_DGRAM
 
-#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_VMS)
+#if defined(OPENSSL_SYS_VMS)
 #include <sys/timeb.h>
 #endif
 
 #define IP_MTU      14 /* linux is lame */
 #endif
 
+#if OPENSSL_USE_IPV6 && !defined(IPPROTO_IPV6)
+#define IPPROTO_IPV6 41 /* windows is lame */
+#endif
+
 #if defined(__FreeBSD__) && defined(IN6_IS_ADDR_V4MAPPED)
 /* Standard definition causes type-punning problems. */
 #undef IN6_IS_ADDR_V4MAPPED
@@ -278,7 +282,7 @@ static void dgram_adjust_rcv_timeout(BIO *b)
 
                sz.i = sizeof(timeout);
                if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
-                                          (void*)&timeout, &sz) < 0)
+                                          (void*)&timeout, &sz.i) < 0)
                        { perror("getsockopt"); }
                else
                        {
@@ -748,7 +752,7 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
 
                sz.i = sizeof(timeout);
                if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
-                       (void*)&timeout, &sz) < 0)
+                       (void*)&timeout, &sz.i) < 0)
                        { perror("getsockopt"); ret = -1; }
                else
                        {
@@ -797,7 +801,7 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
 
                sz.i = sizeof(timeout);
                if (getsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO,
-                       (void*)&timeout, &sz) < 0)
+                       (void*)&timeout, &sz.i) < 0)
                        { perror("getsockopt"); ret = -1; }
                else
                        {
@@ -805,7 +809,6 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
                        tv->tv_usec = (timeout % 1000) * 1000;
                        ret = sizeof(*tv);
                        }
-               }
 #else
                sz.i = sizeof(struct timeval);
                if ( getsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO, 
@@ -875,7 +878,7 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
                        case AF_INET6:
 #if defined(IPV6_DONTFRAG)
                                if ((ret = setsockopt(b->num, IPPROTO_IPV6, IPV6_DONTFRAG,
-                                       &sockopt_val, sizeof(sockopt_val))) < 0)
+                                       (const void *)&sockopt_val, sizeof(sockopt_val))) < 0)
                                        { perror("setsockopt"); ret = -1; }
 #elif defined(OPENSSL_SYS_LINUX) && defined(IPV6_MTUDISCOVER)
                                if ((sockopt_val = num ? IP_PMTUDISC_PROBE : IP_PMTUDISC_DONT),
@@ -951,8 +954,8 @@ BIO *BIO_new_dgram_sctp(int fd, int close_flag)
        memset(authchunks, 0, sizeof(sockopt_len));
        ret = getsockopt(fd, IPPROTO_SCTP, SCTP_LOCAL_AUTH_CHUNKS, authchunks, &sockopt_len);
        OPENSSL_assert(ret >= 0);
-       
-       for (p = (unsigned char*) authchunks + sizeof(sctp_assoc_t);
+
+       for (p = (unsigned char*) authchunks->gauth_chunks;
             p < (unsigned char*) authchunks + sockopt_len;
             p += sizeof(uint8_t))
                {
@@ -1242,7 +1245,7 @@ static int dgram_sctp_read(BIO *b, char *out, int outl)
                        ii = getsockopt(b->num, IPPROTO_SCTP, SCTP_PEER_AUTH_CHUNKS, authchunks, &optlen);
                        OPENSSL_assert(ii >= 0);
 
-                       for (p = (unsigned char*) authchunks + sizeof(sctp_assoc_t);
+                       for (p = (unsigned char*) authchunks->gauth_chunks;
                                 p < (unsigned char*) authchunks + optlen;
                                 p += sizeof(uint8_t))
                                {
@@ -1892,11 +1895,19 @@ int BIO_dgram_non_fatal_error(int err)
 
 static void get_current_time(struct timeval *t)
        {
-#ifdef OPENSSL_SYS_WIN32
-       struct _timeb tb;
-       _ftime(&tb);
-       t->tv_sec = (long)tb.time;
-       t->tv_usec = (long)tb.millitm * 1000;
+#if defined(_WIN32)
+       SYSTEMTIME st;
+       union { unsigned __int64 ul; FILETIME ft; } now;
+
+       GetSystemTime(&st);
+       SystemTimeToFileTime(&st,&now.ft);
+#ifdef __MINGW32__
+       now.ul -= 116444736000000000ULL;
+#else
+       now.ul -= 116444736000000000UI64;       /* re-bias to 1/1/1970 */
+#endif
+       t->tv_sec  = (long)(now.ul/10000000);
+       t->tv_usec = ((int)(now.ul%10000000))/10;
 #elif defined(OPENSSL_SYS_VMS)
        struct timeb tb;
        ftime(&tb);