(E-Mail Removed) (Zarko Coklin) wrote in message news:<(E-Mail Removed). com>...
> Let me put it in a different way. How to create an ethernet interface
> using Linux APIs? What is correct function to use? (init_etherdev,
> etrax_ethernet_init or some other less kernel-ish) function?
Oh, well! I am sorry no-one really replied and saved me some time :-(
I figured it out myself and am posting it so other people have chance
to get over it if/when needed. Here is code snippet that will do the
job.
Enjoy :-)
Zarko Coklin
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/in.h>
int main ()
{
struct ifreq if_req = {0};
int fd;
struct sockaddr_in sin = {0};
/* first open socket */
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
{
printf("%s:%d Failed to open socket!\n", __func__, __LINE__);
return -1;
}
/* set dummy eth. IF values. Note: Linux does not like IP 0.0.0.0
* and does not allow IF to be in 'DOWN' state like Solaris. If
'DOWN'
* IF is immediately un-plumbed !*/
strncpy(if_req.ifr_name, "eth0:5", IFNAMSIZ);
sin.sin_family = AF_INET;
sin.sin_port = 0;
if (inet_aton("123.123.123.123", &sin.sin_addr) == 0)
{
printf("Failed in inet_aton!\n");
close (fd);
return -1;
}
/* provision if_req with eth. info and create IF */
memcpy((char *)&if_req.ifr_addr, (char *)&sin, sizeof(struct
sockaddr));
if (ioctl(fd, SIOCSIFADDR, &if_req) < 0)
{
printf("%s:%d Failed to open socket!\n", __func__, __LINE__);
close (fd);
return -1;
}
close (fd);
printf("%s:%d Got here? Interface created\n", __func__, __LINE__);
return 0;
}