Operating System - HP-UX
1752518 Members
5002 Online
108788 Solutions
New Discussion

getksym() : what is proper symbol name and module name ?

 
Sunny Kim
New Member

getksym() : what is proper symbol name and module name ?

Hello~
I am doing make a application to print the network usage(if_ipackets, if_opackets, if_collisions) without using glance or netstat.
For the first, I used nlist with struct ifnet.
But it returns error.
System call, nlist does not supported in HP-UX 11.00.
I read some manuals about getksym, kmem, nlist and nlist64, but I don't know which proper symbol name and module name for getksym().

Please tell me what proper symbol name and module name is for getksym() or correct source code using nlist.
There is source code using nlist below here.
--------------------------------------------
OS : HP-UX B.11.00 U 9000/800

struct ifnet ifnet;
static off_t firstif;
static int kmem_fd;
struct nlist64 lan_nl[] = {{"lan0"}};

int open_kernel()
{
strcpy(unixname, "/stand/vmunix");
if (( kmem_fd = open("/dev/kmem", O_RDONLY, 0)) == -1)
{
return -1;
}
}

void readk(off_t where, char *addr, int size)
{
if (lseek(kmem_fd, where, SEEK_SET) == -1)
if (read(kmem_fd, addr, size) == -1)
printf("error");
}

int search_lan(char *lan_name)
{
off_t ip;
char name[10];
int count = 0, found = 0;

ip = firstif;
while(ip && (count {
readk((off_t)ip, (char *)&ifnet, sizeof(ifnet));
if (ifnet.if_name != 0 )
{
readk((off_t)ifnet.if_name, name, IFNAMSIZ);
}

sprintf(name, "%.*s%d", IFNAMSIZ, name, ifnet.if_unit);

if ( strcmp(name, lan_name) == 0)
{
found = 1;
break;
}

ip = (off_t)ifnet.if_next;
count++;
}
return found;
}

void lan_meas()
{
int packet_received, packets_sent, collisions;
int ret, found;
off_t i_off;

if ( (ret = nlist64("/stand/vmunix", lan_nl)) == -1 )
{
exit(2);
}
i_off = (off_t)lan_nl[0].n_value;

readk((off_t)i_off, (char *)&firstif, sizeof(firstif));
found = search_lan(lanName); /* en, lo, tu0, tu1 */
if ( found == 1 )
{
packet_received = ifnet.if_ipackets;
packets_sent = ifnet.if_opackets;
collisions = ifnet.if_collisions;
}
else
printf(" failed to find lan \n");
}
1 REPLY 1
Steve Steel
Honored Contributor

Re: getksym() : what is proper symbol name and module name ?

 
If you want truly to understand something, try to change it. (Kurt Lewin)