Sponsored Content
Operating Systems AIX AIX platform: network interface list Post 302371010 by jgobbur on Friday 13th of November 2009 06:23:45 AM
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.
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. IP Networking

Network interface-

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

8. 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

9. 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

10. 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
GETIPNODEBYNAME(3)					     Linux Programmer's Manual						GETIPNODEBYNAME(3)

NAME
getipnodebyname, getipnodebyaddr, freehostent - get network hostnames and addresses SYNOPSIS
#include <sys/types.h> #include <sys/socket.h> #include <netdb.h> struct hostent *getipnodebyname(const char *name, int af, int flags, int *error_num); struct hostent *getipnodebyaddr(const void *addr, size_t len, int af, int *error_num); void freehostent(struct hostent *ip); DESCRIPTION
These functions are deprecated (and unavailable in glibc). Use getaddrinfo(3) and getnameinfo(3) instead. The getipnodebyname() and getipnodebyaddr() functions return the names and addresses of a network host. These functions return a pointer to the following structure: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; }; These functions replace the gethostbyname(3) and gethostbyaddr(3) functions, which could only access the IPv4 network address family. The getipnodebyname() and getipnodebyaddr() functions can access multiple network address families. Unlike the gethostby functions, these functions return pointers to dynamically allocated memory. The freehostent() function is used to release the dynamically allocated memory after the caller no longer needs the hostent structure. getipnodebyname() arguments The getipnodebyname() function looks up network addresses for the host specified by the name argument. The af argument specifies one of the following values: AF_INET The name argument points to a dotted-quad IPv4 address or a name of an IPv4 network host. AF_INET6 The name argument points to a hexadecimal IPv6 address or a name of an IPv6 network host. The flags argument specifies additional options. More than one option can be specified by bitwise OR-ing them together. flags should be set to 0 if no options are desired. AI_V4MAPPED This flag is used with AF_INET6 to request a query for IPv4 addresses instead of IPv6 addresses; the IPv4 addresses will be mapped to IPv6 addresses. AI_ALL This flag is used with AI_V4MAPPED to request a query for both IPv4 and IPv6 addresses. Any IPv4 address found will be mapped to an IPv6 address. AI_ADDRCONFIG This flag is used with AF_INET6 to further request that queries for IPv6 addresses should not be made unless the system has at least one IPv6 address assigned to a network interface, and that queries for IPv4 addresses should not be made unless the system has at least one IPv4 address assigned to a network interface. This flag may be used by itself or with the AI_V4MAPPED flag. AI_DEFAULT This flag is equivalent to (AI_ADDRCONFIG | AI_V4MAPPED). getipnodebyaddr() arguments The getipnodebyaddr() function looks up the name of the host whose network address is specified by the addr argument. The af argument specifies one of the following values: AF_INET The addr argument points to a struct in_addr and len must be set to sizeof(struct in_addr). AF_INET6 The addr argument points to a struct in6_addr and len must be set to sizeof(struct in6_addr). RETURN VALUE
A NULL pointer is returned if an error occurred, and error_num will contain an error code from the following list: HOST_NOT_FOUND The hostname or network address was not found. NO_ADDRESS The domain name server recognized the network address or name, but no answer was returned. This can happen if the network host has only IPv4 addresses and a request has been made for IPv6 information only, or vice versa. NO_RECOVERY The domain name server returned a permanent failure response. TRY_AGAIN The domain name server returned a temporary failure response. You might have better luck next time. A successful query returns a pointer to a hostent structure that contains the following fields: h_name This is the official name of this network host. h_aliases This is an array of pointers to unofficial aliases for the same host. The array is terminated by a NULL pointer. h_addrtype This is a copy of the af argument to getipnodebyname() or getipnodebyaddr(). h_addrtype will always be AF_INET if the af argument was AF_INET. h_addrtype will always be AF_INET6 if the af argument was AF_INET6. h_length This field will be set to sizeof(struct in_addr) if h_addrtype is AF_INET, and to sizeof(struct in6_addr) if h_addrtype is AF_INET6. h_addr_list This is an array of one or more pointers to network address structures for the network host. The array is terminated by a NULL pointer. CONFORMING TO
RFC 2553. NOTES
These functions were present in glibc 2.1.91-95, but were removed again. Several UNIX-like systems support them, but all call them depre- cated. SEE ALSO
getaddrinfo(3), getnameinfo(3), inet_ntop(3), inet_pton(3) COLOPHON
This page is part of release 3.44 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. Linux 2010-09-04 GETIPNODEBYNAME(3)
All times are GMT -4. The time now is 10:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy