Novell Home

IPExtendedIFInfo api sample (CLIB)

From Developer Community

Shows how to use IPExtendedIFInfo to get the primary IP/Subnet for each NIC in the system. Then shows how to call SSGetLanConfiguration with the number for additional information about the NIC.

Sample Code

#include <stdio.h>
#include <sys/socket.h> //inet_ntoa
#include <netinet/in.h> //in_addr
#include <arpa/inet.h>  //inet_ntoa
#include <nit/nwservst.h> //SSGetLANConfiguration, GetLANConfigInfoStructure

NETINET_DEFINE_CONTEXT //inet_ntoa scrach space

#include <ip_route.h>

int main(int argc, char **argv)
{
	LONG rcode;
	struct ip_if_info ifinfo;
	struct in_addr tmp;
	ip_extended_if_info extendedInfo;
	GetLANConfigInfoStructure lanInfo;

	memset((char *)&tmp, 0, sizeof(struct in_addr));
	memset((char *)&lanInfo, 0, sizeof(GetLANConfigInfoStructure));

	extendedInfo.iex_signature  = 'IEXI';
	extendedInfo.iex_version 	= 1 << 16 | 0;
	extendedInfo.iex_length 	= sizeof(ip_extended_if_info);
	extendedInfo.iex_if_id 		= 0;

	while(IPExtendedIFInfo(&extendedInfo) == 0)
	{
		tmp.S_un.S_addr = extendedInfo.iex_local_addr.ip_long;
		printf("Address: %s\n", inet_ntoa(tmp));
		tmp.S_un.S_addr = extendedInfo.iex_net_mask.ip_long;
		printf("netmask: %s\n", inet_ntoa(tmp));
		printf("Adapter: %ld\n", extendedInfo.iex_board_num); 
		rcode = SSGetLANConfiguration(extendedInfo.iex_board_num,(BYTE *)&lanInfo, sizeof(lanInfo));
		if(!rcode){
			printf("Lan adapter information:\n");
			printf("LogicalName = %s\n", lanInfo.LANConfig.DriverLogicalName);
			printf("NodeAddress = %s\n", lanInfo.LANConfig.DriverNodeAddress);
			printf("Slot = %d\n", lanInfo.LANConfig.DriverSlot);
		}
	}
}

--Benjamin Fjeldsted

Novell® Making IT Work As One

© 2009 Novell, Inc. All Rights Reserved.