mirror of
https://github.com/samhocevar/rinetd.git
synced 2025-03-14 20:00:11 +08:00
Add a helper function to retrieve socket type from protocol.
This commit is contained in:
parent
7ef50421c0
commit
f58db7ea8d
@ -32,6 +32,10 @@ void setSocketDefaults(SOCKET fd) {
|
||||
#endif
|
||||
}
|
||||
|
||||
int getSocketType(int protocol) {
|
||||
return protocol == IPPROTO_UDP ? SOCK_DGRAM : SOCK_STREAM;
|
||||
}
|
||||
|
||||
uint16_t getPort(struct addrinfo* ai) {
|
||||
switch (ai->ai_family) {
|
||||
case AF_INET:
|
||||
|
@ -81,4 +81,5 @@ static inline int GetLastError(void) {
|
||||
#endif /* _WIN32 */
|
||||
|
||||
void setSocketDefaults(SOCKET fd);
|
||||
int getSocketType(int protocol);
|
||||
uint16_t getPort(struct addrinfo* ai);
|
||||
|
@ -278,7 +278,7 @@ void addServer(char *bindAddress, char *bindPort, int bindProtocol,
|
||||
{
|
||||
.ai_family = AF_UNSPEC,
|
||||
.ai_protocol = bindProtocol,
|
||||
.ai_socktype = bindProtocol == IPPROTO_TCP ? SOCK_STREAM : SOCK_DGRAM,
|
||||
.ai_socktype = getSocketType(bindProtocol),
|
||||
.ai_flags = AI_PASSIVE,
|
||||
};
|
||||
struct addrinfo *servinfo;
|
||||
@ -733,9 +733,7 @@ static void handleAccept(ServerInfo const *srv)
|
||||
This, too, is nonblocking. Why wait
|
||||
for anything when you don't have to? */
|
||||
struct sockaddr_in saddr;
|
||||
cnx->local.fd = socket(PF_INET,
|
||||
srv->toProtocol == IPPROTO_TCP ? SOCK_STREAM : SOCK_DGRAM,
|
||||
srv->toProtocol);
|
||||
cnx->local.fd = socket(PF_INET, getSocketType(srv->toProtocol), srv->toProtocol);
|
||||
if (cnx->local.fd == INVALID_SOCKET) {
|
||||
syslog(LOG_ERR, "socket(): %m\n");
|
||||
if (cnx->remote.protocol == IPPROTO_TCP)
|
||||
|
Loading…
Reference in New Issue
Block a user