summaryrefslogtreecommitdiff
path: root/src/socket_tcp.c
diff options
context:
space:
mode:
authorJannis Hoffmann <jannis@fehcom.de>2024-07-09 13:58:20 +0200
committerJannis Hoffmann <jannis@fehcom.de>2024-07-09 13:58:20 +0200
commit249866e3d1e11dc72eaa1305f4bb479ded92ef38 (patch)
tree7118c5f58e29fe61c100e4d067bb90ba8d52589e /src/socket_tcp.c
parent96cf8dffe4f7b0b910f790066ae622dc429eb522 (diff)
reorganized file structure
Moved c files into src/. Corrected VERSION file. Removed BUILD and FILES.
Diffstat (limited to 'src/socket_tcp.c')
-rw-r--r--src/socket_tcp.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/socket_tcp.c b/src/socket_tcp.c
new file mode 100644
index 0000000..1ff050e
--- /dev/null
+++ b/src/socket_tcp.c
@@ -0,0 +1,63 @@
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <errno.h>
+#include "close.h" /* better use unistd.h ? */
+#include "ndelay.h"
+#include "socket_if.h"
+#include "error.h"
+
+#ifndef EAFNOSUPPORT
+#define EAFNOSUPPORT EINVAL
+#endif
+
+/**
+ @file socket_tcp.c
+ @author djb, fefe, feh
+ @source ucspi-tcp6
+ @brief setup TCP stream socket
+*/
+
+int socket_tcp4(void)
+{
+ int s;
+
+ s = socket(AF_INET,SOCK_STREAM,0);
+ if (s != -1)
+ if (ndelay_on(s) == -1) { close(s); return -1; }
+
+ return s;
+}
+
+int socket_tcp6(void)
+{
+ int s;
+
+ s = socket(AF_INET6,SOCK_STREAM,0);
+ if (s != -1)
+ if (ndelay_on(s) == -1) { close(s); return -1; }
+
+ return s;
+}
+
+int socket_tcp(void)
+{
+ int s;
+
+ s = socket(AF_INET6,SOCK_STREAM,0);
+ if (s == -1)
+ if (errno == EINVAL || errno == EAFNOSUPPORT || errno == EPROTO || errno == EPROTONOSUPPORT)
+ s = socket(AF_INET,SOCK_STREAM,0);
+
+ if (s != -1)
+ if (ndelay_on(s) == -1) { close(s); return -1; }
+
+ return s;
+}
+
+int socket_tcpnodelay(int s)
+{
+ int opt = 1;
+ return setsockopt(s,IPPROTO_TCP,1,&opt,sizeof(opt)); /* 1 == TCP_NODELAY */
+}