The IOCTL loopback driver can be found in this article (here). The sample application is provided below
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <linux/if.h>
#include <linux/sockios.h>
#define VNET_IOCTL_RESET_STATS (SIOCDEVPRIVATE + 0)
int main(int argc, char *argv[])
{
int sockfd;
struct ifreq ifr;
int value;
if (argc != 3) {
printf("Usage: %s <iface> <reset>\n", argv[0]);
return 1;
}
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if (sockfd < 0) {
perror("socket");
return 1;
}
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, argv[1], IFNAMSIZ - 1);
if (strcmp(argv[2], "reset") == 0) {
if (ioctl(sockfd, VNET_IOCTL_RESET_STATS, &ifr) < 0) {
perror("ioctl reset");
close(sockfd);
return 1;
}
printf("Stats reset successfully\n");
} else {
printf("Unknown command\n");
}
close(sockfd);
return 0;
}
The above code performs the following after the device driver is loaded.
- Opens a socket for the IOCTL
- The interface name is passed as a parameter and is added to the ifreq structure to be sent downwards
- The reset command also needs to be sent via the IOCTL API – VNET_IOCTL_RESET_STATS
- If the ioctl API function is successfully, the code spouts a success statement
The output of the application is shown below.

The output of the dmesg logs for the driver is shown below

We have steadily added more functionality to the skeleton driver in each succeeding article from our journey from a sample skeleton driver. In the following articles, we will add more functionality such as multiple queues, work queue to handle receive operation, netlink and so on. Adding multiple functionalities and its inter-working will definitely lead us to locking mechanisms.
We shall also discuss in real world examples as to how they are used. But, the primary objective to these set of articles is to showcase the simplicity of the different blocks. When different such blocks come together, the code develops its own complexity but still seen in terms of these blocks becomes very easy to comprehend.