- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: gethostid
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2003 06:37 AM
07-23-2003 06:37 AM
I am working on getting C-knowledge, but it's not completely working yet for me :)
Can anyone help me out in receiving a machines hostid ??
#include
int long g;
g = gethostid(void);
int main(void)
{
printf ("The hostid of this machine is : %c\n, g");
}
I am missing something elemantary here. Any help will be much apreciated !!
Regs David
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2003 06:46 AM
07-23-2003 06:46 AM
Re: gethostid
neither i know C, but
gethostid returns a lon, whereas the printf is expecting a pointer to a null terminated strings.
It may be this ?
Massimo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2003 06:49 AM
07-23-2003 06:49 AM
Re: gethostid
You are probably right ( I think I understand you :)
when compiling it says :
# gcc tmp.c
tmp.c:5: conflicting types for `g'
tmp.c:4: previous declaration of `g'
tmp.c:5: parse error before "void"
Can you please let me know how the program should look like ?
Regs David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2003 06:56 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2003 07:06 AM
07-23-2003 07:06 AM
Re: gethostid
If you want to use ANSI prototypes the code would look like this:
#include
long gethostid(void);
int long g;
int main(void)
{
g=gethostid();
printf ("The hostid of this machine is : %d\n",g);
return 0;
}
...note that I added a return code since your main() declaration was of type 'int' not 'void'.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2003 07:09 AM
07-23-2003 07:09 AM
Re: gethostid
The actual value of g should be set from inside main(). The declaration should be done before and the printf of course should be %d.
Many, many thanks !!
Regs David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2003 07:09 AM
07-23-2003 07:09 AM
Re: gethostid
The actual value of g should be set from inside main(). The declaration should be done before and the printf of course should be %d.
Many, many thanks !!
Regs David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2003 11:34 AM
07-23-2003 11:34 AM
Re: gethostid
You don't need to declare gethostid explicitly because it is declared in unistd.h.
You should include stdio.h because you are calling printf.
The 11i manual entry for gethostid warns that it will be obsolete someday. You might want to shift to using confstr with _CS_MACHINE_IDENT or _CS_PARTITION_IDENT. (Those ident strings get longer on IPF systems.)
#include
#include
#include
int main(void)
{
long g;
struct utsname name;
char ident[200];
g=gethostid();
printf ("The hostid of this machine is : %ld\n",g);
uname(&name);
printf ("The idnumber of this machine is : %s\n", name.idnumber);
confstr(_CS_MACHINE_IDENT, ident, sizeof(ident));
printf ("The MACHINE_IDENT of this machine is : %s\n", ident);
confstr(_CS_PARTITION_IDENT, ident, sizeof(ident));
printf ("The PARTITION_IDENT of this partition is : %s\n", ident);
return 0;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2003 11:07 PM
07-23-2003 11:07 PM
Re: gethostid
Regs David