#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    16
    Rep Power
    0

    Code Needed: Linux GetComputername Function


    hi all...

    i need to know abt GetComputerName function in linux c++ ..how it work,the parameter needed,the condition,the header or bla bla..if can..post me the sample code..thanks for helping me..
  2. #2
  3. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    man uname
  4. #3
  5. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,616
    Rep Power
    4247
    Use gethostname(). You might want to read the man page for gethostname for more information :)
    Code:
    #include <unistd.h>
    #include <sys/param.h>
    
    int main(void)
    {
      char name[MAXHOSTNAMELEN];
      size_t namelen = MAXHOSTNAMELEN;
    
      if (gethostname(name, namelen) != -1)
        printf("%s\n", name);
      return 0;
    }
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    16
    Rep Power
    0
    iitzit the function work same as getcomputername?

IMN logo majestic logo threadwatch logo seochat tools logo