miniupnpc/receivedata.c: clean up comments
This commit is contained in:
parent
b6438f2f72
commit
8b22c4d7f4
|
@ -1,16 +1,17 @@
|
||||||
/* $Id: receivedata.c,v 1.4 2012/06/23 22:34:47 nanard Exp $ */
|
/* $Id: receivedata.c,v 1.6 2014/11/13 13:51:52 nanard Exp $ */
|
||||||
/* Project : miniupnp
|
/* Project : miniupnp
|
||||||
* Website : http://miniupnp.free.fr/
|
* Website : http://miniupnp.free.fr/
|
||||||
* Author : Thomas Bernard
|
* Author : Thomas Bernard
|
||||||
* Copyright (c) 2011-2012 Thomas Bernard
|
* Copyright (c) 2011-2014 Thomas Bernard
|
||||||
* This software is subject to the conditions detailed in the
|
* This software is subject to the conditions detailed in the
|
||||||
* LICENCE file provided in this distribution. */
|
* LICENCE file provided in this distribution. */
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
#else
|
#else /* _WIN32 */
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#if defined(__amigaos__) && !defined(__amigaos4__)
|
#if defined(__amigaos__) && !defined(__amigaos4__)
|
||||||
#define socklen_t int
|
#define socklen_t int
|
||||||
|
@ -21,10 +22,10 @@
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#if !defined(__amigaos__) && !defined(__amigaos4__)
|
#if !defined(__amigaos__) && !defined(__amigaos4__)
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#endif
|
#endif /* !defined(__amigaos__) && !defined(__amigaos4__) */
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#define MINIUPNPC_IGNORE_EINTR
|
#define MINIUPNPC_IGNORE_EINTR
|
||||||
#endif
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define PRINT_SOCKET_ERROR(x) printf("Socket error: %s, %d\n", x, WSAGetLastError());
|
#define PRINT_SOCKET_ERROR(x) printf("Socket error: %s, %d\n", x, WSAGetLastError());
|
||||||
|
@ -42,20 +43,20 @@ receivedata(int socket,
|
||||||
#if MINIUPNPC_GET_SRC_ADDR
|
#if MINIUPNPC_GET_SRC_ADDR
|
||||||
struct sockaddr_storage src_addr;
|
struct sockaddr_storage src_addr;
|
||||||
socklen_t src_addr_len = sizeof(src_addr);
|
socklen_t src_addr_len = sizeof(src_addr);
|
||||||
#endif
|
#endif /* MINIUPNPC_GET_SRC_ADDR */
|
||||||
int n;
|
int n;
|
||||||
#if !defined(_WIN32) && !defined(__amigaos__) && !defined(__amigaos4__)
|
#if !defined(_WIN32) && !defined(__amigaos__) && !defined(__amigaos4__)
|
||||||
/* using poll */
|
/* using poll */
|
||||||
struct pollfd fds[1]; /* for the poll */
|
struct pollfd fds[1]; /* for the poll */
|
||||||
#ifdef MINIUPNPC_IGNORE_EINTR
|
#ifdef MINIUPNPC_IGNORE_EINTR
|
||||||
do {
|
do {
|
||||||
#endif
|
#endif /* MINIUPNPC_IGNORE_EINTR */
|
||||||
fds[0].fd = socket;
|
fds[0].fd = socket;
|
||||||
fds[0].events = POLLIN;
|
fds[0].events = POLLIN;
|
||||||
n = poll(fds, 1, timeout);
|
n = poll(fds, 1, timeout);
|
||||||
#ifdef MINIUPNPC_IGNORE_EINTR
|
#ifdef MINIUPNPC_IGNORE_EINTR
|
||||||
} while(n < 0 && errno == EINTR);
|
} while(n < 0 && errno == EINTR);
|
||||||
#endif
|
#endif /* MINIUPNPC_IGNORE_EINTR */
|
||||||
if(n < 0) {
|
if(n < 0) {
|
||||||
PRINT_SOCKET_ERROR("poll");
|
PRINT_SOCKET_ERROR("poll");
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -63,7 +64,7 @@ receivedata(int socket,
|
||||||
/* timeout */
|
/* timeout */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#else /* !defined(_WIN32) && !defined(__amigaos__) && !defined(__amigaos4__) */
|
#else /* !defined(_WIN32) && !defined(__amigaos__) && !defined(__amigaos4__) */
|
||||||
/* using select under _WIN32 and amigaos */
|
/* using select under _WIN32 and amigaos */
|
||||||
fd_set socketSet;
|
fd_set socketSet;
|
||||||
TIMEVAL timeval;
|
TIMEVAL timeval;
|
||||||
|
@ -78,13 +79,13 @@ receivedata(int socket,
|
||||||
} else if(n == 0) {
|
} else if(n == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* !defined(_WIN32) && !defined(__amigaos__) && !defined(__amigaos4__) */
|
||||||
#if MINIUPNPC_GET_SRC_ADDR
|
#if MINIUPNPC_GET_SRC_ADDR
|
||||||
n = recvfrom(socket, data, length, 0,
|
n = recvfrom(socket, data, length, 0,
|
||||||
(struct sockaddr *)&src_addr, &src_addr_len);
|
(struct sockaddr *)&src_addr, &src_addr_len);
|
||||||
#else
|
#else /* MINIUPNPC_GET_SRC_ADDR */
|
||||||
n = recv(socket, data, length, 0);
|
n = recv(socket, data, length, 0);
|
||||||
#endif
|
#endif /* MINIUPNPC_GET_SRC_ADDR */
|
||||||
if(n<0) {
|
if(n<0) {
|
||||||
PRINT_SOCKET_ERROR("recv");
|
PRINT_SOCKET_ERROR("recv");
|
||||||
}
|
}
|
||||||
|
@ -93,12 +94,11 @@ receivedata(int socket,
|
||||||
const struct sockaddr_in6 * src_addr6 = (struct sockaddr_in6 *)&src_addr;
|
const struct sockaddr_in6 * src_addr6 = (struct sockaddr_in6 *)&src_addr;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("scope_id=%u\n", src_addr6->sin6_scope_id);
|
printf("scope_id=%u\n", src_addr6->sin6_scope_id);
|
||||||
#endif
|
#endif /* DEBUG */
|
||||||
if(scope_id)
|
if(scope_id)
|
||||||
*scope_id = src_addr6->sin6_scope_id;
|
*scope_id = src_addr6->sin6_scope_id;
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* MINIUPNPC_GET_SRC_ADDR */
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue