aboutsummaryrefslogtreecommitdiff
path: root/rpcapd/rpcapd.c
diff options
context:
space:
mode:
Diffstat (limited to 'rpcapd/rpcapd.c')
-rw-r--r--rpcapd/rpcapd.c76
1 files changed, 43 insertions, 33 deletions
diff --git a/rpcapd/rpcapd.c b/rpcapd/rpcapd.c
index 19da87f8..ee24432d 100644
--- a/rpcapd/rpcapd.c
+++ b/rpcapd/rpcapd.c
@@ -87,6 +87,7 @@ static int passivemode = 1; //!< '1' if we want to run in passive mode as well
static struct addrinfo mainhints; //!< temporary struct to keep settings needed to open the new socket
static char address[MAX_LINE + 1]; //!< keeps the network address (either numeric or literal) to bind to
static char port[MAX_LINE + 1]; //!< keeps the network port to bind to
+static char data_port[MAX_LINE + 1]; //!< keeps the network port to use to transfer data
#ifdef _WIN32
static HANDLE state_change_event; //!< event to signal that a state change should take place
#endif
@@ -123,16 +124,19 @@ static void printusage(FILE * f)
{
const char *usagetext =
"USAGE:"
- " " PROGRAM_NAME " [-b <address>] [-p <port>] [-4] [-l <host_list>] [-a <host,port>]\n"
- " [-n] [-v] [-d] "
+ " " PROGRAM_NAME " [-b <address>] [-p <port>] [-t <data_port>] [-4] [-l <host_list>]\n"
+ " [-a <host,port>] [-n] [-v] [-d] "
#ifndef _WIN32
"[-i] "
#endif
- "[-D] [-s <config_file>] [-f <config_file>]\n\n"
+ "[-D] [-s <config_file>]\n"
+ " [-f <config_file>]\n\n"
" -b <address> the address to bind to (either numeric or literal).\n"
" Default: binds to all local IPv4 and IPv6 addresses\n\n"
" -p <port> the port to bind to.\n"
" Default: binds to port " RPCAP_DEFAULT_NETPORT "\n\n"
+ " -t <data port>: the port to use to transfer data.\n"
+ " Default: an unused port is chosen by the operating system\n\n"
" -4 use only IPv4.\n"
" Default: use both IPv4 and IPv6 waiting sockets\n\n"
" -l <host_list> a file that contains a list of hosts that are allowed\n"
@@ -216,7 +220,7 @@ int main(int argc, char *argv[])
# define SSL_CLOPTS ""
# endif
-# define CLOPTS "b:dDhip:4l:na:s:f:v" SSL_CLOPTS
+# define CLOPTS "b:dDhip:4l:na:s:f:t:v" SSL_CLOPTS
while ((retval = getopt(argc, argv, CLOPTS)) != -1)
{
@@ -232,6 +236,9 @@ int main(int argc, char *argv[])
case 'p':
pcap_strlcpy(port, optarg, sizeof (port));
break;
+ case 't':
+ pcap_strlcpy(data_port, optarg, sizeof (data_port));
+ break;
case '4':
mainhints.ai_family = PF_INET; // IPv4 server only
break;
@@ -361,8 +368,8 @@ int main(int argc, char *argv[])
state_change_event = CreateEvent(NULL, FALSE, FALSE, NULL);
if (state_change_event == NULL)
{
- sock_geterror("Can't create state change event", errbuf,
- PCAP_ERRBUF_SIZE);
+ sock_geterrmsg(errbuf, PCAP_ERRBUF_SIZE,
+ "Can't create state change event");
rpcapd_log(LOGPRIO_ERROR, "%s", errbuf);
exit(2);
}
@@ -372,8 +379,8 @@ int main(int argc, char *argv[])
//
if (!SetConsoleCtrlHandler(main_ctrl_event, TRUE))
{
- sock_geterror("Can't set control handler", errbuf,
- PCAP_ERRBUF_SIZE);
+ sock_geterrmsg(errbuf, PCAP_ERRBUF_SIZE,
+ "Can't set control handler");
rpcapd_log(LOGPRIO_ERROR, "%s", errbuf);
exit(2);
}
@@ -427,8 +434,8 @@ int main(int argc, char *argv[])
sockctrl = dup(0);
if (sockctrl == -1)
{
- sock_geterror("Can't dup standard input", errbuf,
- PCAP_ERRBUF_SIZE);
+ sock_geterrmsg(errbuf, PCAP_ERRBUF_SIZE,
+ "Can't dup standard input");
rpcapd_log(LOGPRIO_ERROR, "%s", errbuf);
exit(2);
}
@@ -461,7 +468,7 @@ int main(int argc, char *argv[])
exit(0);
}
(void)daemon_serviceloop(sockctrl, 0, hostlist_copy,
- nullAuthAllowed, uses_ssl);
+ nullAuthAllowed, data_port, uses_ssl);
//
// Nothing more to do.
@@ -504,7 +511,7 @@ int main(int argc, char *argv[])
// LINUX WARNING: the current linux implementation of pthreads requires a management thread
// to handle some hidden stuff. So, as soon as you create the first thread, two threads are
- // created. Fom this point on, the number of threads active are always one more compared
+ // created. From this point on, the number of threads active are always one more compared
// to the number you're expecting
// Second child continues
@@ -623,7 +630,7 @@ void main_startup(void)
SOCKET sock;
struct listen_sock *sock_info;
- if ((sock = sock_open(tempaddrinfo, SOCKOPEN_SERVER, SOCKET_MAXCONN, errbuf, PCAP_ERRBUF_SIZE)) == INVALID_SOCKET)
+ if ((sock = sock_open(NULL, tempaddrinfo, SOCKOPEN_SERVER, SOCKET_MAXCONN, errbuf, PCAP_ERRBUF_SIZE)) == INVALID_SOCKET)
{
switch (tempaddrinfo->ai_family)
{
@@ -736,8 +743,8 @@ send_state_change_event(void)
if (!SetEvent(state_change_event))
{
- sock_geterror("SetEvent on shutdown event failed", errbuf,
- PCAP_ERRBUF_SIZE);
+ sock_geterrmsg(errbuf, PCAP_ERRBUF_SIZE,
+ "SetEvent on shutdown event failed");
rpcapd_log(LOGPRIO_ERROR, "%s", errbuf);
}
}
@@ -904,15 +911,15 @@ accept_connections(void)
event = WSACreateEvent();
if (event == WSA_INVALID_EVENT)
{
- sock_geterror("Can't create socket event", errbuf,
- PCAP_ERRBUF_SIZE);
+ sock_geterrmsg(errbuf, PCAP_ERRBUF_SIZE,
+ "Can't create socket event");
rpcapd_log(LOGPRIO_ERROR, "%s", errbuf);
exit(2);
}
if (WSAEventSelect(sock_info->sock, event, FD_ACCEPT) == SOCKET_ERROR)
{
- sock_geterror("Can't setup socket event", errbuf,
- PCAP_ERRBUF_SIZE);
+ sock_geterrmsg(errbuf, PCAP_ERRBUF_SIZE,
+ "Can't setup socket event");
rpcapd_log(LOGPRIO_ERROR, "%s", errbuf);
exit(2);
}
@@ -930,8 +937,8 @@ accept_connections(void)
WSA_INFINITE, FALSE);
if (ret == WSA_WAIT_FAILED)
{
- sock_geterror("WSAWaitForMultipleEvents failed", errbuf,
- PCAP_ERRBUF_SIZE);
+ sock_geterrmsg(errbuf, PCAP_ERRBUF_SIZE,
+ "WSAWaitForMultipleEvents failed");
rpcapd_log(LOGPRIO_ERROR, "%s", errbuf);
exit(2);
}
@@ -970,8 +977,8 @@ accept_connections(void)
if (WSAEnumNetworkEvents(sock_info->sock,
events[i], &network_events) == SOCKET_ERROR)
{
- sock_geterror("WSAEnumNetworkEvents failed",
- errbuf, PCAP_ERRBUF_SIZE);
+ sock_geterrmsg(errbuf, PCAP_ERRBUF_SIZE,
+ "WSAEnumNetworkEvents failed");
rpcapd_log(LOGPRIO_ERROR, "%s", errbuf);
exit(2);
}
@@ -985,10 +992,10 @@ accept_connections(void)
//
// Yes - report it and keep going.
//
- sock_fmterror("Socket error",
+ sock_fmterrmsg(errbuf,
+ PCAP_ERRBUF_SIZE,
network_events.iErrorCode[FD_ACCEPT_BIT],
- errbuf,
- PCAP_ERRBUF_SIZE);
+ "Socket error");
rpcapd_log(LOGPRIO_ERROR, "%s", errbuf);
continue;
}
@@ -1174,7 +1181,7 @@ accept_connection(SOCKET listen_sock)
// Don't check for errors here, since the error can be due to the fact that the thread
// has been killed
- sock_geterror("accept()", errbuf, PCAP_ERRBUF_SIZE);
+ sock_geterrmsg(errbuf, PCAP_ERRBUF_SIZE, "accept() failed");
rpcapd_log(LOGPRIO_ERROR, "Accept of control connection from client failed: %s",
errbuf);
return;
@@ -1198,14 +1205,16 @@ accept_connection(SOCKET listen_sock)
//
if (WSAEventSelect(sockctrl, NULL, 0) == SOCKET_ERROR)
{
- sock_geterror("WSAEventSelect()", errbuf, PCAP_ERRBUF_SIZE);
+ sock_geterrmsg(errbuf, PCAP_ERRBUF_SIZE,
+ "WSAEventSelect() failed");
rpcapd_log(LOGPRIO_ERROR, "%s", errbuf);
sock_close(sockctrl, NULL, 0);
return;
}
if (ioctlsocket(sockctrl, FIONBIO, &off) == SOCKET_ERROR)
{
- sock_geterror("ioctlsocket(FIONBIO)", errbuf, PCAP_ERRBUF_SIZE);
+ sock_geterrmsg(errbuf, PCAP_ERRBUF_SIZE,
+ "ioctlsocket(FIONBIO) failed");
rpcapd_log(LOGPRIO_ERROR, "%s", errbuf);
sock_close(sockctrl, NULL, 0);
return;
@@ -1298,7 +1307,7 @@ accept_connection(SOCKET listen_sock)
exit(0);
}
(void)daemon_serviceloop(sockctrl, 0, hostlist_copy,
- nullAuthAllowed, uses_ssl);
+ nullAuthAllowed, data_port, uses_ssl);
exit(0);
}
@@ -1358,7 +1367,7 @@ main_active(void *ptr)
{
int activeclose;
- if ((sockctrl = sock_open(addrinfo, SOCKOPEN_CLIENT, 0, errbuf, PCAP_ERRBUF_SIZE)) == INVALID_SOCKET)
+ if ((sockctrl = sock_open(activepars->address, addrinfo, SOCKOPEN_CLIENT, 0, errbuf, PCAP_ERRBUF_SIZE)) == INVALID_SOCKET)
{
rpcapd_log(LOGPRIO_DEBUG, "%s", errbuf);
@@ -1388,7 +1397,8 @@ main_active(void *ptr)
// daemon_serviceloop() will free the copy.
//
activeclose = daemon_serviceloop(sockctrl, 1,
- hostlist_copy, nullAuthAllowed, uses_ssl);
+ hostlist_copy, nullAuthAllowed, data_port,
+ uses_ssl);
}
// If the connection is closed by the user explicitly, don't try to connect to it again
@@ -1416,7 +1426,7 @@ unsigned __stdcall main_passive_serviceloop_thread(void *ptr)
// told by the client to close.
//
(void)daemon_serviceloop(params.sockctrl, 0, params.hostlist,
- nullAuthAllowed, uses_ssl);
+ nullAuthAllowed, data_port, uses_ssl);
return 0;
}