{"id":346,"date":"2012-04-10T21:03:45","date_gmt":"2012-04-10T19:03:45","guid":{"rendered":"http:\/\/blog.the-leviathan.ch\/?p=346"},"modified":"2012-04-10T22:25:25","modified_gmt":"2012-04-10T20:25:25","slug":"accessingmanipulating-networkdevices-in-c","status":"publish","type":"post","link":"https:\/\/blog.the-leviathan.ch\/?p=346","title":{"rendered":"Accessing\/manipulating networkdevices in C"},"content":{"rendered":"<p>Howdy how<\/p>\n<p>BenBE asked me to give him some advice how to open and manipulate network devices from user space.<br \/>\nAlthough it&#8217;s not really a kernel hacking issue, as his way of asking proposed I&#8217;ll post the respective link after all, because I&#8217;ve promised.<\/p>\n<p>Usually you use APIs for such a purpose.<\/p>\n<p>In this case its the library called Libdnet and the project page can be found under the following URL:<br \/>\n<a title=\"http:\/\/libdnet.sourceforge.net\/\" href=\"http:\/\/libdnet.sourceforge.net\/\"> http:\/\/libdnet.sourceforge.net\/<\/a><\/p>\n<p>I just have taken a look into Debian&#8217;s package viewer and somehow the relevant header (\u00a0\/usr\/include\/dnet\/tun.h )<br \/>\nis missing ( packages broken\/outdated? O.o)<\/p>\n<p>Anyway, the header file would only tell us that much (Thx to benny for the tip with the highlighter! \ud83d\ude09 ):<\/p>\n<pre lang=\"c\">\/*\r\n * tun.h\r\n *\r\n * Network tunnel device.\r\n *\r\n * Copyright (c) 2001 Dug Song \r\n *\r\n * $Id: tun.h,v 1.2 2005\/01\/25 21:29:12 dugsong Exp $\r\n *\/\r\n\r\n#ifndef DNET_TUN_H\r\n#define DNET_TUN_H\r\n\r\ntypedef struct tun      tun_t;\r\n\r\n__BEGIN_DECLS\r\ntun_t      *tun_open(struct addr *src, struct addr *dst, int mtu);\r\nint         tun_fileno(tun_t *tun);\r\nconst char *tun_name(tun_t *tun);\r\nssize_t     tun_send(tun_t *tun, const void *buf, size_t size);\r\nssize_t     tun_recv(tun_t *tun, void *buf, size_t size);\r\ntun_t      *tun_close(tun_t *tun);\r\n__END_DECLS\r\n\r\n#endif \/* DNET_TUN_H *\/<\/pre>\n<p>An example can be found a little more deeper on the following site:<br \/>\n<a title=\"http:\/\/csfacwiki.cslabs.ewu.edu\/wiki\/securitylab\/index.php\/Libdnet\" href=\"http:\/\/csfacwiki.cslabs.ewu.edu\/wiki\/securitylab\/index.php\/Libdnet\"> http:\/\/csfacwiki.cslabs.ewu.edu\/wiki\/securitylab\/index.php\/Libdnet<\/a><\/p>\n<p>By using libudev for dynamic file checking and path allocation<br \/>\nyou could also make it a little more dynamic and flexible.<br \/>\n(Using hardcoded strings in order to allocate files is usually a very bad idea)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Howdy how BenBE asked me to give him some advice how to open and manipulate network devices from user space. Although it&#8217;s not really a kernel hacking issue, as his way of asking proposed I&#8217;ll post the respective link after all, because I&#8217;ve promised. Usually you use APIs for such a purpose. In this case &hellip; <a href=\"https:\/\/blog.the-leviathan.ch\/?p=346\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Accessing\/manipulating networkdevices in C<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,6],"tags":[],"class_list":["post-346","post","type-post","status-publish","format-standard","hentry","category-daily","category-tech"],"_links":{"self":[{"href":"https:\/\/blog.the-leviathan.ch\/index.php?rest_route=\/wp\/v2\/posts\/346","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.the-leviathan.ch\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.the-leviathan.ch\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.the-leviathan.ch\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.the-leviathan.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=346"}],"version-history":[{"count":13,"href":"https:\/\/blog.the-leviathan.ch\/index.php?rest_route=\/wp\/v2\/posts\/346\/revisions"}],"predecessor-version":[{"id":360,"href":"https:\/\/blog.the-leviathan.ch\/index.php?rest_route=\/wp\/v2\/posts\/346\/revisions\/360"}],"wp:attachment":[{"href":"https:\/\/blog.the-leviathan.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=346"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.the-leviathan.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=346"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.the-leviathan.ch\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=346"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}