AIX platform: network interface list


 
Thread Tools Search this Thread
Operating Systems AIX AIX platform: network interface list
# 1  
Old 11-13-2009
AIX platform: network interface list

Hi,

I am trying to list all the interface present in the given system.
Here is sample program.
i.e. cat 1.c

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/dlpi.h>
#include <net/if.h>
/*#include <sys/sockio.h>*/
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <strings.h>
#include <errno.h>
#include <netdb.h>


void num_of_interfaces(void);


void
in_getaddr(char *s, struct sockaddr *saddr)
{
struct sockaddr_in *sin = (struct sockaddr_in *) saddr;
struct hostent *hp;
struct netent *np;
int error;
char str[BUFSIZ];

(void) memset(sin, 0, sizeof (*sin));
(void) strncpy(str, s, sizeof(str));

hp = getipnodebyname(str, AF_INET, 0, &error);
if (!hp) {
perror("getipnodebyname");
return;
}
freehostent(hp);

sin->sin_family = AF_INET;
(void) memcpy(&sin->sin_addr, hp->h_addr, hp->h_length);
}

void num_of_interfaces()
{

struct ifreq lifr;
int n;
char *buf;
int s = socket(AF_INET, SOCK_DGRAM, 0);
//struct ifnum lifn;
struct ifconf lifc;
struct ifreq *lifrp;
struct ifreq lifrl; /* Local lifreq struct */
int numifs;
unsigned bufsize;
// int64_t lifc_flags = LIFC_NOXMIT;

// lifn.lifn_family = AF_UNSPEC;
// lifn.lifn_flags = lifc_flags;
// if (ioctl(s, SIOCGLIFNUM, (char *)&lifn) < 0) {
/* Could not determine number of interfaces */
// exit(2);
//}
numifs = 10;
// printf("numifs is %d\n",numifs);
bufsize = numifs * sizeof (struct ifreq);
if ((buf = (char *)malloc(bufsize)) == NULL) {
/* out of memory */
close(s);
exit(1);
}
memset(buf, 0, sizeof(bufsize));

// lifc.ifc_family = AF_UNSPEC;
// lifc.ifc_flags = lifc_flags;
lifc.ifc_len = bufsize;
lifc.ifc_buf = buf;


if (ioctl(s, SIOCGIFCONF, (char *)&lifc) < 0) {
free(buf);
exit(1);
}
lifrp = lifc.ifc_req;

for (n = numifs ; n > 0; n--, lifrp++) {

(void) close(s);
if (s == -1) {
exit(1);
}
/* print the name of the interface */
printf("%s\n", lifrp->ifr_name);
}
if (buf != NULL)
free(buf);
}

int
main (int argc, char *argv[])
{
int errors = 0,choice=0;
choice=atoi(argv[1]);
if (choice == 0)
num_of_interfaces();
return 0;
}

output:
bash-3.00$ ./a.out 0
en0


Actual machine has 4 interface but it is listing first one only.
Pls let me know what could be the problem.
# 2  
Old 11-13-2009
Quote:
Originally Posted by jgobbur
Hi,

I am trying to list all the interface present in the given system.
[...]
To list all interfaces in the given system use
# lsdev -c if
or
# lsdev -Cc if
when you are below AIX 5.2.
Use grep to subdivide Defined and Available interfaces. Why do you want to reinvent the wheel?
# 3  
Old 11-13-2009
I wanted to know how impl. in C
# 4  
Old 11-13-2009
Quote:
Originally Posted by jgobbur
I wanted to know how impl. in C
Do you know the AIX programming guides? They are availble from the pSeries Information Center: Programming for AIX
You also might use truss to find out what lsdev is doing under the hood.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Adding a network interface to a bonded interface

I have a RHEL 5 system with a bonded interface configure using only one network port (eth0). So I have config file for ifcfg-bond0 and ifcfg-eth. I'd like to configure eth5 to be the second SLAVE in the bond. My question is, after I modify ifcfg-eth5, can I add eth5 to the bond0 interface without... (1 Reply)
Discussion started by: westmoreland
1 Replies

2. Solaris

No network cable But Network interface is UP and Running

I've one Netra 240 After changing main board and system configuration card reader, Network is not accessible any more, Network interfaces are always UP and Running even when there is no cable connected to Network interfaces. I tried to restart and plumb/unplumb with no luck. ifconfig -a... (7 Replies)
Discussion started by: samer.odeh
7 Replies

3. IP Networking

network interface -

Hello, Please, how can i create a network interface with a routable IP address on linux (ubuntu) ? AND How can i desactivate an interface? Thank you so much for help. (1 Reply)
Discussion started by: chercheur857
1 Replies

4. IP Networking

Network interface-

Hello, Please what's the difference between: AND Thank you so much (3 Replies)
Discussion started by: chercheur857
3 Replies

5. UNIX and Linux Applications

Access to network interface (Mac-network)

Hi, I'm a italian student. For my thesis I develop a gateway with protocol 6lowpan. For that I must access to network interface to develope my personal stack based on standard 802.15.4. Can you help me? I need an explanation for that. (0 Replies)
Discussion started by: berny88
0 Replies

6. Linux

Help Me: How to set ARP stale time interval on linux platform for Ipv6 interface

Hi, Can any one please help me increase the arp stale time of an ipv6 interface on linux platform ? I have tried increasing the variable gc_stale_time but that doesnt work. Thanks (2 Replies)
Discussion started by: dkothapa
2 Replies

7. Solaris

configure zones to have different network interface and network

i need to configure a zone to use different interface (bge2) than global and have connected to completely different network switch & to use its own defaultrouter and hosts file .. is it possible ..if so ..how ? Thanks (9 Replies)
Discussion started by: skamal4u
9 Replies

8. AIX

How restart the network interface in AIX?

Hi All, Please let me know the command to restart the network interface and enable it on boot in AIX, similar to /etc/init.d/network restart in Redhat. Thanks, Sunil.K please watch out to post in the right subforum! (9 Replies)
Discussion started by: sunilrk07
9 Replies

9. Programming

retrieving network interface list

Hello I have a problem with retreiving network interface list using IOCTLs. I have 4 interfaces: $ ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope... (1 Reply)
Discussion started by: xyzt
1 Replies

10. UNIX for Dummies Questions & Answers

Network Interface

Hi ! Does anyone know how can i get information about my network interface ... if it works in half or full duplex mode !! Thx in adivance ! Witt (4 Replies)
Discussion started by: witt
4 Replies
Login or Register to Ask a Question