Novell Home

CLIB's IPGetLocalAddr & IPGetLocalAddrIncludingAux functions

From Developer Community

Demonstration of how to get all the IPAddresses on a machine using CLIB with the API's IPGetLocalAddr & IPGetLocalAddrIncludingAux. Difference between the two api's is that the *IncludingAux will also return the addresses added by the command "Add Secondary IPADDRESS"

Sample Code

/* program to get all assigned ip addresses */

#include <stdio.h>
//#include <iproute.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

extern unsigned long IPGetLocalAddrIncludingAux(unsigned long);
extern unsigned long IPGetLocalAddr(unsigned long);

NETINET_DEFINE_CONTEXT

int main() {
unsigned long ip = 0;
struct in_addr in;
   
    printf("\n");
	printf("Starting IPGetLocalAddr\n");
    while(0 != (ip = IPGetLocalAddr(ip))) {
        in.s_addr = ip;
        printf("\rfound ip: %s\n", inet_ntoa(in));
    }
	printf("\nStarting IPGetLocalAddrIncludingAux\n");
    while(0 != (ip = IPGetLocalAddrIncludingAux(ip))) {
        in.s_addr = ip;
        printf("\rfound ip: %s\n", inet_ntoa(in));
    }

    return(0);
}

--Benjamin Fjeldsted

Novell® Making IT Work As One

© 2008 Novell, Inc. All Rights Reserved.