ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

getdomainname() API

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • getdomainname() API

    I have a program that's been using the gethostname() API successfully for many years:
    Code:
    d gethostname     pr            10i 0 extProc('gethostname')
    d  name                      32767a   options(*varsize)    
    d  length                       10i 0 value                
                                                                ​
    d host            s            256a            
    d cstring         s             +1    like(host)​
    
    c                   callp     gethostname(cstring:%size(cstring))
    c                   eval      host        = %str(%addr(cstring))  ​
    This gets the hostname as host.domain.com. Now I need to get just the domain name:
    Code:
    d getDomainName   pr            10i 0 extProc('getdomainname')
    d  name                      32767a   options(*varsize)      
    d  length                       10i 0 value                    ​
                                                                ​
    d domain         s            256a            
    d cstring         s             +1    like(domain)​
    
      getDomainName(cstring:%size(cstring));
      domain = %str(%addr(cstring));                    ​

    This gets a blank value. No messages in the job log, getdomainname() returns 0, and errno is 0. Any ideas what I'm doing wrong? Thanks!

  • #2
    Well I guess nevermind; after putzing around with getdomainname() for hours and getting nowhere, I spent 10 minutes rewriting it to use QtocRtvTCPA; works like a charm.

    Comment


    • #3
      Glad you found a way round it. According to the docs the return value is: "A NULL string when a sethostname() has not been previously issued since the last initial program load."

      This does not seem to be a requirement for gethostname which may explain why it works but gethostname doesn't.

      By the way - although your code works you are not really coding the prototypes correctly​. It should be like this:

      Code:
      Dcl-PR gethostname Int(10) extProc('gethostname');
         pname Pointer value;
         length Int(10) value;
      End-PR;​
      
      rc = gethostname(pname : %size(host));
      If ( rc < 0 );
         pErrNo = GetErrno();
         ptext = strerror( ErrorNo );
      Else;
         host = %str( pname );
      EndIf;​
      If you want to assume it will always work then you don't need the rc = bit.

      P.S.On my system the domain request returns a null string but like you I get the host name.

      Comment


      • #4
        What are you trying to retrieve, exactly?

        At least, in my experience, getdomainname() works with NIS -- the Network Information Service -- to get the name of the NIS domain you are in. Typically, you would have code that sets your NIS domain during startup (via the setdomainname API or similar) and then you'd start the NIS service, and later you could use getdomainname() to query it.

        I'm guessing that's not really what you're trying to do, you don't often see NIS used on IBM i. (It's a Unix technology, typically used to share stuff like userids/passwords across a group of computers.) -- since you're talking about QtocRtvTCPA, you probably are looking for the DNS domain name rather than the NIS one?

        Comment

        Working...
        X