Sponsored Content
Full Discussion: regarding gethostname()
Top Forums Programming regarding gethostname() Post 302104986 by Perderabo on Tuesday 30th of January 2007 05:26:31 AM
Old 01-30-2007
gethostname() is a system call that simply returns the contents of a small data area in the kernel. It has a partner called sethostname() that can store something there. gethostname() returns an integer and 0 means it succeeded. It will fail if it is called incorrectly and this results in -1.

A different function called gethostbyname will return a pointer to a hostent structure. There are so many typos in the original post that I can't tell for sure what is really going on. "stuct"? "hosent"? Stuff like that is not going to compile. I'm not sure what "verify that the net is active" means but gethostbyname is not going to ping anything or "send a socket".
 

We Also Found This Discussion For You

1. Programming

gethostname warning

Hi, does anyone knows how to get rid of this annoying warning? Thank you! #include <netdb.h> main() { gethostbyname("test"); } $ gcc -static test.c /tmp/ccW9HG18.o: In function `main': test.c:(.text+0x19): warning: Using 'gethostbyname' in statically linked applications requires at... (3 Replies)
Discussion started by: paulquater
3 Replies
gethostname(3C)                                            Standard C Library Functions                                            gethostname(3C)

NAME
gethostname, sethostname - get or set name of current host SYNOPSIS
#include <unistd.h> int gethostname(char *name, int namelen); int sethostname(char *name, int namelen); DESCRIPTION
The gethostname() function returns the standard host name for the current processor, as previously set by sethostname(). The namelen argu- ment specifies the size of the array pointed to by name. The returned name is null-terminated unless insufficient space is provided. The sethostname() function sets the name of the host machine to be name, which has length namelen. This call is restricted to the superuser and is normally used only when the system is bootstrapped. Host names are limited to MAXHOSTNAMELEN characters, currently 256, defined in the <netdb.h> header. RETURN VALUES
Upon successful completion, gethostname() and sethostname() return 0. Otherwise, they return -1 and set errno to indicate the error. ERRORS
The gethostname() and sethostname() functions will fail if: EFAULT The name or namelen argument gave an invalid address. The sethostname() function will fail if: EPERM The {PRIV_SYS_ADMIN} privilege was not asserted in the effective set of the calling process. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
sysinfo(2), uname(2), gethostid(3C), attributes(5), standards(5) SunOS 5.10 22 Mar 2004 gethostname(3C)
All times are GMT -4. The time now is 03:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy