Page 1 of 1

ExamineIPAddresses() on OSX

Posted: Thu Jun 04, 2015 3:21 pm
by mikejs
Bit of a weird one, this. I have two Macs - a Mac mini and an iMac, both late 2012 vintage. Both running the current Yosemite (10.10.3).

On one of them (where I have pb 5.31 and xcode installed), ExamineIPAddresses() works and allows me to list the available (ipv4) IP addresses. On the other, ExamineIPAddresses() returns 0, which tells me it didn't work, but gives no indication as to why it didn't work. (And, yes, I've called InitNetwork() first).

Both machines have wired connections to the same switch and have IP addresses (as reported via ifconfig) on the same subnet.

Some code that reproduces the problem (on one mac but not the other):

Code: Select all

OpenConsole()
InitNetwork()
result=ExamineIPAddresses()
If result
  Repeat
  ip=NextIPAddress()
  if ip
    PrintN("IP: "+IPString(ip))
  endif
  Until ip=0
Else
  PrintN("ExamineIPAddresses returned 0")
EndIf
I've compiled the above and run the resulting binary on both Macs. One reports the IPs correctly, the other prints "ExamineIPAddresses returned 0" to the terminal.

Anyone any ideas as to what could cause that? Or how to get more diagnostic info?

As a fallback, I've tried using RunProgram("ifconfig", "en0") and parsing the output, and I can read the IP successfully that way, but that's a horrible hack...

Re: ExamineIPAddresses() on OSX

Posted: Fri Jun 05, 2015 10:27 am
by Wolfram
Try this. may be it is a problem of the InitNetwork().

Code: Select all

OpenConsole()
If Not InitNetwork()
  result=ExamineIPAddresses()
  If result
    Repeat
      ip=NextIPAddress()
      If ip
        PrintN("IP: "+IPString(ip))
        Debug IPString(ip)
      EndIf
    Until ip=0
  Else
    PrintN("ExamineIPAddresses returned 0")
  EndIf
Else
  PrintN("InitNet Error")
  
EndIf

Re: ExamineIPAddresses() on OSX

Posted: Fri Jun 05, 2015 11:24 am
by mikejs
Wolfram wrote:Try this. may be it is a problem of the InitNetwork().
I think that should be

Code: Select all

If InitNetwork()
, rather than

Code: Select all

If Not InitNetwork()
...

In any case - InitNetwork is working - i.e. InitNetwork returns non-zero, then ExamineIPAddresses returns zero (at least on the machine with the problem).

However, I've done some more tinkering with this in the meantime, and I don't think this is a PB issue any more (although I'd still quite like to know what's causing it).

The iMac is set up with two partitions. One is installed with OS X managed by Casper (http://www.jamfsoftware.com/), and is either the same as used in our student Mac centres, or the test version of that. The other is a cut down OS X boot used as the basis for a netboot image used by Casper Imaging.

The odd behaviour happens when the imac is booted into the student image, but not when booted into the cut down image. i.e. I can have both varieties of behaviour on the same hardware depending which partition I boot from. Also, if I reimage the student partition back to 10.8.5, I still have the problem. It's not a rights problem (I can sudo it and get the same results).

The mac mini isn't managed by casper, and is a reasonably vanilla install (although it is joined to our domain). All works fine.

So, it looks like something unusual about the casper managed environment, independent of the OS X version, although what on earth could cause that specific behaviour and allow everything else I've tried to work normally (including ifconfig), I've no idea.

Re: ExamineIPAddresses() on OSX

Posted: Fri Jun 05, 2015 11:39 am
by Wolfram
mikejs wrote:
Wolfram wrote:Try this. may be it is a problem of the InitNetwork().
I think that should be

Code: Select all

If InitNetwork()
, rather than

Code: Select all

If Not InitNetwork()
...

Sorry, of cause :oops:
Or like my teacher said: I just did it, to see you are following me.

Re: ExamineIPAddresses() on OSX

Posted: Fri Jun 05, 2015 12:07 pm
by mikejs
No problem - just made me check I hadn't misread the help file... :)