How to write a C Program to Creating pico device in C Programming Language ?
Solution:/*C Program to Creating pico device*/
#include <iostream>
#include <stdio.h>
#include <signal.h>
extern "C" {
#include "pico_stack.h"
#include "pico_config.h"
#include "pico_device.h"
#include "pico_dev_tap.h"
}
void end(int signal);
char* interface_name = "tap0";
struct pico_device *pico_device = NULL;
int main(int argc, char** argv)
{
signal(SIGTERM, &end); // NetBeans stop process signal
signal(SIGQUIT, &end);
signal(SIGHUP, &end);
signal(SIGINT, &end);
signal(SIGQUIT, &end);
signal(SIGABRT, &end);
signal(SIGSTOP, &end);
pico_stack_init();
pico_device = (struct pico_device*)pico_tap_create(interface_name);
if (!pico_device)
{
std::cout << "Error creating pico device, exiting..." << std::endl;
return -1;
}
while (true)
{
pico_stack_tick();
PICO_IDLE();
}
}
void end(int signal)
{
pico_tap_destroy(pico_device);
}