- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- get client "hostname" in C?
Operating System - HP-UX
1823943
Members
3551
Online
109667
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
Forums
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
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
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
тАО12-10-2004 06:34 AM
тАО12-10-2004 06:34 AM
get client "hostname" in C?
What is the most sensible way to get the hostname of a client for use inside a C program? That is, if a client that has an IP address connects to a host via telnet and executes a program containing gethostname(), it will return the name of the host, of course. Is there something similar for the client name?
{HP-UX 11i, HP C/ANSI C, aC++}
{HP-UX 11i, HP C/ANSI C, aC++}
if only we knew...
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-10-2004 06:55 AM
тАО12-10-2004 06:55 AM
Re: get client "hostname" in C?
Not really. You have to understand that you could be N levels deep in indirection (ie telnet to HostA then telnet to HostB then telnet to HostC ... --- which of those do you want?
If you can assume that you are only I level deep then
build up a command like this:
who -um | awk '{split($NF,x," "); print x[1]
and stuff that into a popen and read it.
That will probably be the most portable way to do this.
If you can assume that you are only I level deep then
build up a command like this:
who -um | awk '{split($NF,x," "); print x[1]
and stuff that into a popen and read it.
That will probably be the most portable way to do this.
If it ain't broke, I can fix that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-10-2004 09:47 AM
тАО12-10-2004 09:47 AM
Re: get client "hostname" in C?
Ooops,
who -um | awk '{split($NF,x," "); print x[1]
should be:
who -um | awk '{split($NF,x,":"); print x[1]
who -um normally reports just the hostname (or IP address) in the last field but if this is a CDE session you would see hostname:0.0 (or IP_Address:0.0). The split on ":" and then printing the first elemnt of the array regardless or whether the colon is found assure you that only the hostname (or IP Address id hostname is unknown) is returned.
who -um | awk '{split($NF,x," "); print x[1]
should be:
who -um | awk '{split($NF,x,":"); print x[1]
who -um normally reports just the hostname (or IP address) in the last field but if this is a CDE session you would see hostname:0.0 (or IP_Address:0.0). The split on ":" and then printing the first elemnt of the array regardless or whether the colon is found assure you that only the hostname (or IP Address id hostname is unknown) is returned.
If it ain't broke, I can fix that.
- Tags:
- who
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-12-2004 02:53 AM
тАО12-12-2004 02:53 AM
Re: get client "hostname" in C?
If the user connects via telnet or the like, presumeably stdin will be a socket. That being the case, the application may be able to call getpeername() on stdin/stdout. If someone runs that same application from the console the getpeername() call will of course return an error - that the fd is not a socket most likely.
Armed with the IP address of the peer (remote/client) one can call getnodeinfo() to return the hostname information available for that IP address. That call should be in all the 11i releases, IIRC. Or you can use the older, non-IPV6-aware gethostbyaddr() call.
Armed with the IP address of the peer (remote/client) one can call getnodeinfo() to return the hostname information available for that IP address. That call should be in all the 11i releases, IIRC. Or you can use the older, non-IPV6-aware gethostbyaddr() call.
there is no rest for the wicked yet the virtuous have no pillows
- Tags:
- getpeername
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.
Company
Learn About
News and Events
Support
© Copyright 2025 Hewlett Packard Enterprise Development LP