summaryrefslogtreecommitdiff
path: root/sock.c
diff options
context:
space:
mode:
authorDaniel Borkmann <daniel@iogearbox.net>2015-06-18 00:16:20 +0200
committerDaniel Borkmann <daniel@iogearbox.net>2015-06-18 00:16:20 +0200
commit41ce2d49645c6eb87f751c4df0b554f4388e73c3 (patch)
tree9a8e839c81c1a3c5a2b841644192b395d449b145 /sock.c
parent3e0003f06c310440d74d4ee91d37a478cb3a5095 (diff)
sock: Add dgram socket creation.
LINKTYPE_LINUX_SLL needs datagram packet sockets. We'll need this function at a later point in time. Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'sock.c')
-rw-r--r--sock.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/sock.c b/sock.c
index 7cfa4a0..cfca05e 100644
--- a/sock.c
+++ b/sock.c
@@ -8,6 +8,7 @@
#include "sock.h"
#include "die.h"
#include "str.h"
+#include "linktype.h"
#include "built_in.h"
int af_socket(int af)
@@ -33,6 +34,26 @@ int pf_socket(void)
return sock;
}
+static int pf_socket_dgram(void)
+{
+ int sock = socket(PF_PACKET, SOCK_DGRAM, 0);
+ if (unlikely(sock < 0))
+ panic("Creation of PF dgram socket failed: %s\n",
+ strerror(errno));
+
+ return sock;
+}
+
+int pf_socket_type(uint32_t type)
+{
+ switch (type) {
+ case LINKTYPE_LINUX_SLL:
+ return pf_socket_dgram();
+ default:
+ return pf_socket();
+ }
+}
+
/* Avail in kernel >= 3.14
* in commit d346a3fae3 (packet: introduce PACKET_QDISC_BYPASS socket option)
*/