POSIX defines several typedefs defined in the header file <sys/types.h> and used for many arguments and return values. These typedefs are important because the standard C types can vary from machine to machine and are loosely defined by the C standard. The C language is more useful on a wide range of hardware because of this loose definition—a 16-bit machine does not have the same native word size as a 64-bit machine, and a low-level programming language should not pretend it does—but POSIX needs more guarantees, and so requires that the C library's <sys/types.h> header file define a set of consistent types for each machine that implements POSIX. Each of these typedefs can be easily distinguished from a native C type because it ends in _t. The subset used for interfaces is:
The type descriptions are intentionally vague. There is no guarantee that the types will be the same on two different Linux platforms, or even two different environments running on the same platform. It is quite likely that a 64-bit machine that supports both 64-bit and 32-bit environments will have different values in each environment for some of these types. Also, these types may change in future versions of Linux, within the scope allowed by POSIX. Discovering Run-Time CapabilitiesMany system capabilities have limits, others are optional, and some may have information associated with them. A limit on the length of the string of arguments passed to a new program protects the system from arbitrary demands for memory that could otherwise bring the system to a standstill. Not all POSIX systems implement job control. A program may wish to know the most recent version of the POSIX standard the currently running system claims to implement. The sysconf() function provides this type of system-specific information that may differ from system to system for a single executable, information that cannot be known at the time the executable is compiled. #include <unistd.h> long sysconf(int); The integer argument to sysconf() is one of a set of macros prefixed with _SC_. Here are the ones that are most likely to be useful to you:
Finding and Setting Basic System InformationThere are a few pieces of information about the system on which a program is running that can be useful. The operating system name and version, for example, can be used to change what features system programs provide. The uname() system call allow a program to discover this run-time information. #include <sys/utsname.h> int uname(struct utsname * unameBuf); The function returns nonzero on error, which occurs only if unameBuf is invalid. Otherwise, the structure it points to is filled in with NULL terminated strings describing the system the program is running on
The nodename member is what is commonly called the system host name (it is what the hostname command displays), but it should not be confused with an Internet host name. While these are the same on many systems, they are not necessarily the same thing. A system with multiple Internet addresses has multiple Internet host names, but only a single node name, so there is not a one-to-one equivalence. A more common situation is home computers on broadband Internet connections. They normally have Internet host names something like host127-56.raleigh.myisp.com, and their Internet host names change whenever they have disconnected their broadband modem for an extended period of timePeople who own those machines give them node names hat better suit their personalities, along the lines of loren or eleanor, which are not proper Internet addresses at all. If they have multiple machines behind a home gateway device, all of those machines will share a single Internet address (and a single Internet host name), but may have names like linux.mynetwork.org and freebsd.mynetwork.org, which are still not Internet host names. For all of these reasons, assuming that the system's node name is a valid Internet host name for the machine is not a good idea.
The system's node name is set using the sethostname() system call, and its NIS (YP) domain name is set by the setdomainname() system call.
#include <unistd.h> int sethostname(const char * name, size_t len); int setdomainname(const char * name, size_t len); Both of these system calls take a pointer to a string (not necessarily NULL terminated) containing the appropriate name and the length of the string.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Disclaimer
1) E-articles is not responsible for the information contained by this article as well for any and all copyright infringements by authors and writers. E-articles is a free information resource. If you suspect this article for any copyright infringement, please read the terms of service and contact us or use the "Report this article" button on this page to investigate the problem.
2) E-articles is not responsible for inaccuracies, falsehoods, or any other types of misinformation this article may contain and will not be liable for any loss or damage suffered by a user through the user's reliance on the information gained here. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||