Initial commit of files

This commit is contained in:
2021-01-22 10:16:20 -05:00
parent 32d165ec8f
commit ed92211680
534 changed files with 68563 additions and 19 deletions

46
src/libnet/tcp_accept.c Normal file
View File

@ -0,0 +1,46 @@
//
// TCP Accept
//
#include "netlib.h"
#include "strlib.h"
int tcp_accept( int sock, struct sockaddr_storage *sa )
{
/* storage? */
struct sockaddr_storage ss;
if ( !sa )
sa = &ss;
/* tcp request */
socklen_t len = sizeof(struct sockaddr_storage);
/* accept the incoming connection */
int cs = accept(sock, (struct sockaddr *)sa, &len );
/* check for errors. if any, ignore new connection */
if (cs < 0 )
{
log_error("tcp_accept");
return -1;
}
/* turn off nagle, writes are shipped immediately */
int flag = 1;
setsockopt( cs, /* socket affected */
IPPROTO_TCP, /* set option at TCP level */
TCP_NODELAY, /* name of option */
(char *) &flag, /* the cast is historical cruft */
sizeof(int)); /* length of option value */
/* log new client */
if ( cs > 0 )
{
char szBuf[256];
ip_host2name( szBuf, sizeof(szBuf), sa );
strlcat( szBuf, " client connected", sizeof(szBuf) );
log_write( szBuf );
}
return cs;
}