Operating System - HP-UX
1831658 Members
2184 Online
110029 Solutions
New Discussion

How do I programmatically get the hardware address for a SCSI device?

 
SOLVED
Go to solution
Philip A. Reyniers
Occasional Advisor

How do I programmatically get the hardware address for a SCSI device?

I have a C++ program that obtains information about all the SCSI devices installed on a given 11.x server. However, I need to obtain the physical hardware address for a given device using C/C++. Now, I am not referring to using CSTM or ioscan, I am looking for a method of getting the physical hardware address ( i.e. 10/0/14/0.0.0 ) from the device name ( i.e. /dev/rdsk/c0t0d0 ) using C/C++.

Thanks in advance to all that reply.

Philip A. Reyniers
If it is not broken leave it alone, if you have time try to improve it, and if you do not care then get another job.
9 REPLIES 9
Dietmar Konermann
Honored Contributor

Re: How do I programmatically get the hardware address for a SCSI device?

Philip,

tools like ioscan use the config driver (/dev/config) to obtain that kind of information. I'm afraid this API is not disclosed for general use.

Sorry...
Dietmar.

PS.: Maybe you should open a support call to get confirmation for this.
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)
Laurent Menase
Honored Contributor

Re: How do I programmatically get the hardware address for a SCSI device?

Hi Philip,

The best way to do it is a

#define BUFSZ 1024
int p[2];
char command[256];
char buf[BUFSZ];
int res;
FILE *f;
sprintf(command,"/usr/sbin/lssf %s 2>/dev/null",devfile);
f=popen(command,"r");
if (!f)
{
perror("popen");
}
if(fgets(buf,BUFSZ,f)!=0)
{
char *p,*q;
p=strstr(buf,"address");
if(p) p=strchr(p,' ');
if(p) q=strchr(++p,' ');
if(q) *q=0;

printf("%s\n",p);
} else
{
buf[0]=0;
if(ferror(f)) perror("fread");
else printf("nosuchdev?\n");
return -1
}
pclose(f);
}
Steve Shoecraft
New Member
Solution

Re: How do I programmatically get the hardware address for a SCSI device?

Attached is something that might help
Philip A. Reyniers
Occasional Advisor

Re: How do I programmatically get the hardware address for a SCSI device?

Steve,

Looking at souce you listed, I see that ioparmams.h has the following structure listed as such:

****************CODE LISTING****************
typedef struct ioconfig {
char name[MAX_NAME_LEN];
char class[MAX_NAME_LEN];
hw_path_t hw_path;
int instance;
} ioconfig_t;
***********STOP CODE LISTING****************

However, class is trated as a C++ keyword and thus will not compile. So, if I modify the source to the following:

****************CODE LISTING****************
typedef struct ioconfig {
char name[MAX_NAME_LEN];
char dclass[MAX_NAME_LEN];
hw_path_t hw_path;
int instance;
} ioconfig_t;
***********STOP CODE LISTING****************

The following compiles but cores when trying to create the union ioconfig_record rec:

****************CODE LISTING****************
#include
#include
#include
#include
#include
#include "ioparams.h"

int main( void ) {
FILE *fp;
union ioconfig_record rec;
unsigned long magic;
struct hw_path last_path;
char hw_path[14], *p;
int bytes, x;

cout << "DEBUG" << endl;

fp = fopen(IOCONFIG_FILE,"rb");
if ( !fp ) {
perror( "fopen" );
exit(0);
}
fclose(fp);
}
***********STOP CODE LISTING****************

Can you or anyone else provide some additional insight?

As always, Thanks In Advance.

Phil
If it is not broken leave it alone, if you have time try to improve it, and if you do not care then get another job.
Martha Mueller
Super Advisor

Re: How do I programmatically get the hardware address for a SCSI device?

try using lssf

lssf /dev/dsk/c6t4d0
sdisk card instance 6 SCSI target 4 SCSI LUN 0 section 0 at address 0/8/0/0.1.27.0.0.4.0 /dev/dsk/c6t4d0


Dietmar Konermann
Honored Contributor

Re: How do I programmatically get the hardware address for a SCSI device?

Phil,

I hope you've seen the comment in ioparams.h... :)

NOTE:
This header file contains information specific to the internals of the HP-UX implementation. The contents of this header file are subject to change without notice. Such changes may affect source code, object code, or binary compatibility between releases of HP-UX. Code which uses the symbols contained within this header file is inherently non-portable (even between HP-UX implementations).

Best regards...
Dietmar.
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)
Steve Shoecraft
New Member

Re: How do I programmatically get the hardware address for a SCSI device?

Phil,

Just enclose your include for ioparms as an extern "C". This seems to work fine:

#ifdef __cplusplus
#define class ioclass
extern "C" {
#endif
#include "/usr/conf/io/ioparams.h"
#ifdef __cplusplus
};
#endif
Philip A. Reyniers
Occasional Advisor

Re: How do I programmatically get the hardware address for a SCSI device?

Steve and other available members,

I would like to start out by thanking you and the others that have replied to this question. All have provided solid direction and great snips of code.

There is a lot of information to gleem from these examples. However, unless I am not seeing the entire picture, it only appears to traverse the very top-level of hardware addresses. With this said, I think I have just few more questions on the subject that I hope that you might be able to shed some light on.

The ioparams.h include file procides some external (extern) functions:

*****************CODE SNIP******************
void *io_search __(( void *token, int type, int qual, ...));

void *io_search_array __(( void *token, int type, int qual, char *key[], void *dat[] ));

int io_query __(( void *token, int type, char *key, void *ptr ));

int io_get_key_info __(( int type, char *key, char *type_name, int *size ));

************STOP CODE SNIP******************

Do you know how these functions are used and can you provide an example?

I have included the external functions into my source but have not figured out how they should be called.

Thanks In Advance For Any All Assistance,

Phil
If it is not broken leave it alone, if you have time try to improve it, and if you do not care then get another job.
Laurent Menase
Honored Contributor

Re: How do I programmatically get the hardware address for a SCSI device?

Hi Philip,

Those functions are defined in an internal lib
libIO.a which is not delivered.

really the only supportable way to do it is still to use lssf

In ioparms.h there is a
#ifdef _KERNEL
around the function proto. Which means those functions there a prototyped for kernel functions.