mirror of
https://github.com/shadowsocks/shadowsocks-libev.git
synced 2026-11-02 16:03:45 +00:00
clean up
This commit is contained in:
+19
-14
@@ -11,10 +11,12 @@ void winsock_init(void)
|
||||
int ret;
|
||||
wVersionRequested = MAKEWORD(1, 1);
|
||||
ret = WSAStartup(wVersionRequested, &wsaData);
|
||||
if (ret != 0) {
|
||||
if (ret != 0)
|
||||
{
|
||||
FATAL("Could not initialize winsock");
|
||||
}
|
||||
if (LOBYTE(wsaData.wVersion) != 1 || HIBYTE(wsaData.wVersion) != 1) {
|
||||
if (LOBYTE(wsaData.wVersion) != 1 || HIBYTE(wsaData.wVersion) != 1)
|
||||
{
|
||||
WSACleanup();
|
||||
FATAL("Could not find a usable version of winsock");
|
||||
}
|
||||
@@ -28,11 +30,12 @@ void winsock_cleanup(void)
|
||||
void ss_error(const char *s)
|
||||
{
|
||||
LPVOID *msg = NULL;
|
||||
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, WSAGetLastError(),
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
(LPTSTR) &msg, 0, NULL);
|
||||
if (msg != NULL) {
|
||||
if (msg != NULL)
|
||||
{
|
||||
LOGE("%s: %s", s, (char *)msg);
|
||||
LocalFree(msg);
|
||||
}
|
||||
@@ -43,7 +46,8 @@ int setnonblocking(int fd)
|
||||
u_long iMode = 0;
|
||||
long int iResult;
|
||||
iResult = ioctlsocket(fd, FIONBIO, &iMode);
|
||||
if (iResult != NO_ERROR) {
|
||||
if (iResult != NO_ERROR)
|
||||
{
|
||||
LOGE("ioctlsocket failed with error: %ld\n", iResult);
|
||||
}
|
||||
return iResult;
|
||||
@@ -61,15 +65,16 @@ const char *inet_ntop(int af, const void *src, char *dst, socklen_t size)
|
||||
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;
|
||||
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;
|
||||
}
|
||||
return (WSAAddressToString((struct sockaddr *)&ss, sizeof(ss), NULL, dst, &s) == 0) ? dst : NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user