Project Alice
Loading...
Searching...
No Matches
pcp_win_defines.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2014 by Cisco Systems, Inc.
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7
8 1. Redistributions of source code must retain the above copyright notice, this
9 list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright notice,
11 this list of conditions and the following disclaimer in the documentation
12 and/or other materials provided with the distribution.
13
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#ifndef PCP_WIN_DEFINES
27#define PCP_WIN_DEFINES
28
29#include <time.h>
30#include <winsock2.h>
31#include <ws2tcpip.h>
32#include <ws2ipdef.h>
33#include <winbase.h> /*GetCurrentProcessId*/ /*link with kernel32.dll*/
34#include "stdint.h"
35/* windows uses Sleep(miliseconds) method, instead of UNIX sleep(seconds) */
36#define sleep(x) Sleep((x) * 1000)
37
38#ifdef _MSC_VER
39#define inline __inline /*In Visual Studio inline keyword only available in C++ */
40#endif
41
42typedef uint16_t in_port_t;
43
44#if 1 //WINVER<NTDDI_VISTA
45static inline const char *pcp_inet_ntop(int af, const void *src, char *dst,
46 int cnt)
47{
48 struct sockaddr_storage srcaddr;
49 size_t slen;
50
51 if (af == AF_INET) {
52 struct sockaddr_in *sa4=(struct sockaddr_in *)&srcaddr;
53 memset(sa4, 0, sizeof(struct sockaddr_in));
54 memcpy(&(sa4->sin_addr), src, sizeof(sa4->sin_addr));
55 slen=sizeof(struct sockaddr_in);
56 } else if (af == AF_INET6) {
57 struct sockaddr_in6 *sa6=(struct sockaddr_in6 *)&srcaddr;
58 memset(sa6, 0, sizeof(struct sockaddr_in6));
59 memcpy(&(sa6->sin6_addr), src, sizeof(sa6->sin6_addr));
60 slen=sizeof(struct sockaddr_in6);
61 } else {
62 return NULL;
63 }
64 srcaddr.ss_family=(ADDRESS_FAMILY)af;
65 if (WSAAddressToStringA((struct sockaddr *)&srcaddr, (DWORD)slen, 0, dst,
66 (LPDWORD) & cnt) != 0) {
67 return NULL;
68 }
69 return dst;
70}
71#define inet_ntop pcp_inet_ntop
72#endif
73
74#define ssize_t SSIZE_T
75#define strdup _strdup
76
77#define getpid GetCurrentProcessId
78
79#define snprintf _snprintf
80
81int gettimeofday(struct timeval *tv, struct timezone *tz);
82
83#define MSG_DONTWAIT 0x0
84
85#endif /*PCP_WIN_DEFINES*/
uint16_t in_port_t
int gettimeofday(struct timeval *tv, struct timezone *tz)