Rev | Line | |
---|
[9] | 1 | /* getdomainname() Author: Kees J. Bot
|
---|
| 2 | * 2 Dec 1994
|
---|
| 3 | */
|
---|
| 4 | #define nil 0
|
---|
| 5 | #include <sys/types.h>
|
---|
| 6 | #include <sys/utsname.h>
|
---|
| 7 | #include <unistd.h>
|
---|
| 8 | #include <string.h>
|
---|
| 9 |
|
---|
| 10 | int getdomainname(char *domain, size_t size)
|
---|
| 11 | {
|
---|
| 12 | char nodename[256];
|
---|
| 13 | char *dot;
|
---|
| 14 |
|
---|
| 15 | if (gethostname(nodename, sizeof(nodename)) < 0)
|
---|
| 16 | return -1;
|
---|
| 17 | nodename[sizeof(nodename)-1]= 0;
|
---|
| 18 | if ((dot= strchr(nodename, '.')) == nil) dot= ".";
|
---|
| 19 |
|
---|
| 20 | strncpy(domain, dot+1, size);
|
---|
| 21 | if (size > 0) domain[size-1]= 0;
|
---|
| 22 | return 0;
|
---|
| 23 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.