read device name in FreeBSD

This commit is contained in:
Nikos Mavrogiannopoulos
2013-04-12 17:29:16 +02:00
parent 6c43eedf50
commit b0ff05dee9

View File

@@ -20,6 +20,7 @@
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <net/if.h>
@@ -414,6 +415,20 @@ int open_tun(main_server_st* s, struct lease_st** l)
return -1;
}
/* find device name */
{
struct stat st;
ret = fstat(tunfd, &st);
if (ret < 0) {
e = errno;
mslog(s, NULL, LOG_ERR, "%s: stat: %s\n", strerror(e));
goto fail;
}
snprintf(lease->name, sizeof(lease->name), "%s", devname(st.st_rdev, S_IFCHR));
}
set_cloexec_flag (tunfd, 1);
#endif