Networking Forums

Networking Forums > Computer Networking > Linux Networking > Linux API to create logical interface on a physical interface?

Reply
Thread Tools Display Modes

Linux API to create logical interface on a physical interface?

 
 
Zarko Coklin
Guest
Posts: n/a

 
      07-12-2004, 12:20 AM
I am trying to find an API to create a logical interface on a physical
interface. For people familiar with Solaris I am trying to find
replacement for:
ioctl(fd, SIOCLIFADDIF, &if_req,sizeof(struct ifreq)

Does anybody know how to do that on Linux? Comments/code
samples/references are highly appreciated.

Thanks,
Zarko Coklin
 
Reply With Quote
 
 
 
 
Zarko Coklin
Guest
Posts: n/a

 
      07-13-2004, 10:20 PM
Let me put it in a different way. How to create and ethernet interface
using Linux APIs? What is correct function to use? (init_etherdev,
etrax_ethernet_init or some other less kernel-ish) function?
 
Reply With Quote
 
Zarko Coklin
Guest
Posts: n/a

 
      07-18-2004, 01:50 AM
(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;
}
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create a demand dial interface with netsh in Windows 2008 fails cyber09 Windows Networking 0 12-09-2008 07:25 PM
physical vs. logical network interfaces stf Linux Networking 3 02-09-2008 04:14 PM
ISC DHCP - Two subnets on one physical interface. Dan Linux Networking 2 07-31-2007 06:48 PM
one physical interface, 3 virtual interfaces, and inetd CptDondo Linux Networking 1 11-16-2006 07:54 PM
Nomadix: Web Interface to create users info@digitaltutor.info Wireless Internet 0 04-12-2006 11:21 AM



1 2 3 4 5 6 7 8 9 10 11