- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: how to get current host's hostname by gethostn...
Operating System - HP-UX
1753341
Members
4968
Online
108792
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
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
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
тАО02-20-2002 01:55 AM
тАО02-20-2002 01:55 AM
I don't know how to use gethostname(),Do anyone can help me? Thanks!!!
Please give me a sample about gethostname().
Please give me a sample about gethostname().
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-20-2002 02:16 AM
тАО02-20-2002 02:16 AM
Solution
Few things to remember:
1. Include
2. Allocate sufficient space for the hostname. For example, declare char chHostName[50]
You can get the max hostname from /usr/include/sys/param.h - look for MAXHOSTNAMELEN
3. If the return value is not 0, check the errno for dagnostics.
1. Include
2. Allocate sufficient space for the hostname. For example, declare char chHostName[50]
You can get the max hostname from /usr/include/sys/param.h - look for MAXHOSTNAMELEN
3. If the return value is not 0, check the errno for dagnostics.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-20-2002 02:58 AM
тАО02-20-2002 02:58 AM
Re: how to get current host's hostname by gethostname?
Hi,
gethostname() is a system call used by other commands to get the hostname:
uname
sethostname
hostname
to get the hosts hostname, use simply
# hostname
--> name_of_host is the output
Allways stay on the bright side of life!
Peter
gethostname() is a system call used by other commands to get the hostname:
uname
sethostname
hostname
to get the hosts hostname, use simply
# hostname
--> name_of_host is the output
Allways stay on the bright side of life!
Peter
I'm learning here as well as helping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2002 03:39 AM
тАО02-21-2002 03:39 AM
Re: how to get current host's hostname by gethostname?
Here is an example program using gethostname() called gethost.c
#include
#include
main()
{
char hostname[64];
if (gethostname(hostname, sizeof(hostname)) < 0)
{
perror("gethostname");
exit(1);
}
else
{
fprintf(stdout, "HOSTNAME = %s\n", hostname);
}
exit(0);
}
Hope this helps.
Cheers,
Joseph.
#include
#include
main()
{
char hostname[64];
if (gethostname(hostname, sizeof(hostname)) < 0)
{
perror("gethostname");
exit(1);
}
else
{
fprintf(stdout, "HOSTNAME = %s\n", hostname);
}
exit(0);
}
Hope this helps.
Cheers,
Joseph.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP