mirror of
https://github.com/wangyu-/udp2raw.git
synced 2025-02-07 23:59:36 +08:00
fix compile
This commit is contained in:
parent
1679c324b3
commit
ff39a562a6
46
common.cpp
46
common.cpp
@ -395,6 +395,52 @@ return 0;
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(__MINGW32__)
|
#if defined(__MINGW32__)
|
||||||
|
int inet_pton(int af, const char *src, void *dst)
|
||||||
|
{
|
||||||
|
struct sockaddr_storage ss;
|
||||||
|
int size = sizeof(ss);
|
||||||
|
char src_copy[INET6_ADDRSTRLEN+1];
|
||||||
|
|
||||||
|
ZeroMemory(&ss, sizeof(ss));
|
||||||
|
/* stupid non-const API */
|
||||||
|
strncpy (src_copy, src, INET6_ADDRSTRLEN+1);
|
||||||
|
src_copy[INET6_ADDRSTRLEN] = 0;
|
||||||
|
|
||||||
|
if (WSAStringToAddress(src_copy, af, NULL, (struct sockaddr *)&ss, &size) == 0) {
|
||||||
|
switch(af) {
|
||||||
|
case AF_INET:
|
||||||
|
*(struct in_addr *)dst = ((struct sockaddr_in *)&ss)->sin_addr;
|
||||||
|
return 1;
|
||||||
|
case AF_INET6:
|
||||||
|
*(struct in6_addr *)dst = ((struct sockaddr_in6 *)&ss)->sin6_addr;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *inet_ntop(int af, const void *src, char *dst, socklen_t size)
|
||||||
|
{
|
||||||
|
struct sockaddr_storage ss;
|
||||||
|
unsigned long s = size;
|
||||||
|
|
||||||
|
ZeroMemory(&ss, sizeof(ss));
|
||||||
|
ss.ss_family = af;
|
||||||
|
|
||||||
|
switch(af) {
|
||||||
|
case AF_INET:
|
||||||
|
((struct sockaddr_in *)&ss)->sin_addr = *(struct in_addr *)src;
|
||||||
|
break;
|
||||||
|
case AF_INET6:
|
||||||
|
((struct sockaddr_in6 *)&ss)->sin6_addr = *(struct in6_addr *)src;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
/* cannot direclty use &size because of strict aliasing rules */
|
||||||
|
return (WSAAddressToString((struct sockaddr *)&ss, sizeof(ss), NULL, dst, &s) == 0)?
|
||||||
|
dst : NULL;
|
||||||
|
}
|
||||||
char *get_sock_error()
|
char *get_sock_error()
|
||||||
{
|
{
|
||||||
static char buf[1000];
|
static char buf[1000];
|
||||||
|
3
common.h
3
common.h
@ -42,6 +42,7 @@
|
|||||||
|
|
||||||
#if defined(__MINGW32__)
|
#if defined(__MINGW32__)
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
|
#include <ws2ipdef.h>
|
||||||
typedef unsigned char u_int8_t;
|
typedef unsigned char u_int8_t;
|
||||||
typedef unsigned short u_int16_t;
|
typedef unsigned short u_int16_t;
|
||||||
typedef unsigned int u_int32_t;
|
typedef unsigned int u_int32_t;
|
||||||
@ -96,6 +97,8 @@ using namespace std;
|
|||||||
|
|
||||||
|
|
||||||
#if defined(__MINGW32__)
|
#if defined(__MINGW32__)
|
||||||
|
int inet_pton(int af, const char *src, void *dst);
|
||||||
|
const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);
|
||||||
#define setsockopt(a,b,c,d,e) setsockopt(a,b,c,(const char *)(d),e)
|
#define setsockopt(a,b,c,d,e) setsockopt(a,b,c,(const char *)(d),e)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user