mirror of
https://github.com/samhocevar/rinetd.git
synced 2025-04-26 04:50:21 +08:00
Merge some code into a new net.c source file.
This commit is contained in:
parent
6750f65c35
commit
17d17e233b
@ -8,7 +8,7 @@ man_MANS = rinetd.8
|
||||
sysconf_DATA = rinetd.conf
|
||||
|
||||
sbin_PROGRAMS = rinetd
|
||||
rinetd_SOURCES = rinetd.c rinetd.h parse.c match.c match.h
|
||||
rinetd_SOURCES = rinetd.c rinetd.h parse.c parse.h match.c match.h net.c net.h
|
||||
|
||||
GENERATED_SOURCES = parse.c
|
||||
|
||||
|
35
net.c
Normal file
35
net.c
Normal file
@ -0,0 +1,35 @@
|
||||
/* Copyright © 1997—1999 Thomas Boutell <boutell@boutell.com>
|
||||
and Boutell.Com, Inc.
|
||||
© 2003—2017 Sam Hocevar <sam@hocevar.net>
|
||||
|
||||
This software is released for free use under the terms of
|
||||
the GNU Public License, version 2 or higher. NO WARRANTY
|
||||
IS EXPRESSED OR IMPLIED. USE THIS SOFTWARE AT YOUR OWN RISK. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "net.h"
|
||||
|
||||
void setSocketDefaults(SOCKET fd)
|
||||
{
|
||||
/* Make socket non-blocking (FIXME: this uses legacy API) */
|
||||
FIONBIO_ARG_T ioctltmp = 1;
|
||||
#if _WIN32
|
||||
ioctlsocket(fd, FIONBIO, &ioctltmp);
|
||||
#else
|
||||
ioctl(fd, FIONBIO, &ioctltmp);
|
||||
#endif
|
||||
|
||||
#if defined __linux__
|
||||
int tmp = 0;
|
||||
setsockopt(fd, SOL_SOCKET, SO_LINGER, &tmp, sizeof(tmp));
|
||||
#endif
|
||||
|
||||
#if !defined __linux__ && !defined _WIN32
|
||||
int tmp = 1024;
|
||||
setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &tmp, sizeof(tmp));
|
||||
#endif
|
||||
}
|
||||
|
@ -60,7 +60,6 @@
|
||||
static inline int closesocket(int s) {
|
||||
return close(s);
|
||||
}
|
||||
# define ioctlsocket ioctl
|
||||
# define WSAEWOULDBLOCK EWOULDBLOCK
|
||||
# define WSAEAGAIN EAGAIN
|
||||
# define WSAEINPROGRESS EINPROGRESS
|
||||
@ -71,3 +70,5 @@ static inline int GetLastError(void) {
|
||||
}
|
||||
#endif /* _WIN32 */
|
||||
|
||||
void setSocketDefaults(SOCKET fd);
|
||||
|
2
parse.c
2
parse.c
@ -10,7 +10,7 @@
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "networking.h"
|
||||
#include "net.h"
|
||||
#include "types.h"
|
||||
#include "rinetd.h"
|
||||
#include "parse.h"
|
||||
|
@ -11,7 +11,7 @@
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "networking.h"
|
||||
#include "net.h"
|
||||
#include "types.h"
|
||||
#include "rinetd.h"
|
||||
#include "parse.h"
|
||||
|
26
rinetd.c
26
rinetd.c
@ -43,7 +43,7 @@
|
||||
#endif /* DEBUG */
|
||||
|
||||
#include "match.h"
|
||||
#include "networking.h"
|
||||
#include "net.h"
|
||||
#include "types.h"
|
||||
#include "rinetd.h"
|
||||
#include "parse.h"
|
||||
@ -287,8 +287,7 @@ void addServer(char *bindAddress, int bindPort, int bindProto,
|
||||
closesocket(fd);
|
||||
}
|
||||
|
||||
FIONBIO_ARG_T ioctltmp;
|
||||
ioctlsocket(fd, FIONBIO, &ioctltmp);
|
||||
setSocketDefaults(fd);
|
||||
}
|
||||
|
||||
if (getAddress(connectAddress, &iaddr) < 0) {
|
||||
@ -584,12 +583,7 @@ static void handleAccept(ServerInfo const *srv)
|
||||
return;
|
||||
}
|
||||
|
||||
FIONBIO_ARG_T ioctltmp;
|
||||
ioctlsocket(nfd, FIONBIO, &ioctltmp);
|
||||
#ifndef _WIN32
|
||||
int tmp = 0;
|
||||
setsockopt(nfd, SOL_SOCKET, SO_LINGER, &tmp, sizeof(tmp));
|
||||
#endif
|
||||
setSocketDefaults(nfd);
|
||||
} else /* if (srv->fromProto == protoUdp) */ {
|
||||
/* In UDP mode, get remote address using recvfrom() and check
|
||||
for an existing connection from this client. */
|
||||
@ -687,18 +681,8 @@ static void handleAccept(ServerInfo const *srv)
|
||||
memcpy(&saddr.sin_addr, &srv->localAddr, sizeof(struct in_addr));
|
||||
saddr.sin_port = srv->localPort;
|
||||
|
||||
if (srv->toProto == protoTcp) {
|
||||
FIONBIO_ARG_T ioctltmp = 1;
|
||||
ioctlsocket(cnx->local.fd, FIONBIO, &ioctltmp);
|
||||
|
||||
#if defined __linux__
|
||||
int tmp = 0;
|
||||
setsockopt(cnx->local.fd, SOL_SOCKET, SO_LINGER, &tmp, sizeof(tmp));
|
||||
#elif !defined _WIN32
|
||||
int tmp = 1024;
|
||||
setsockopt(cnx->local.fd, SOL_SOCKET, SO_SNDBUF, &tmp, sizeof(tmp));
|
||||
#endif
|
||||
}
|
||||
if (srv->toProto == protoTcp)
|
||||
setSocketDefaults(cnx->local.fd);
|
||||
|
||||
if (connect(cnx->local.fd, (struct sockaddr *)&saddr,
|
||||
sizeof(struct sockaddr_in)) == SOCKET_ERROR)
|
||||
|
Loading…
Reference in New Issue
Block a user