summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sock.c21
-rw-r--r--sock.h1
2 files changed, 22 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)
*/
diff --git a/sock.h b/sock.h
index 50f7102..8f68d42 100644
--- a/sock.h
+++ b/sock.h
@@ -3,6 +3,7 @@
extern int af_socket(int af);
extern int pf_socket(void);
+extern int pf_socket_type(uint32_t type);
extern void set_nonblocking(int fd);
extern int set_nonblocking_sloppy(int fd);
extern int set_reuseaddr(int fd);