Skip navigation.
 
mlHow to get AirPort Connection Status
FROM : Rashmi Vyshnavi
DATE : Thu Sep 18 06:50:23 2008

I want to know when my computer connects/disconnects to WiFi/AirPort
network.
Is there a way to get the status of connection to a WiFi network. I tried
using System Configuration API,but I could not get the status. Here is the
snippet
--
static void MyNetworkConnectionCallBack(SCNetworkConnectionRef
connection,SCNetworkConnectionStatus stat,void *info)
{
printf("Call back called \n");
SCNetworkConnectionStatus status = SCNetworkConnectionGetStatus(connection);
switch(status) {
case kSCNetworkConnectionInvalid:
printf("Connection invalid\n");
break;
case kSCNetworkConnectionDisconnected:
printf("Connection disconnected\n");
break;
case kSCNetworkConnectionConnecting:
printf("Connection connecting\n");
break;
case kSCNetworkConnectionConnected:
printf("Connection connected\n");
break;
case kSCNetworkConnectionDisconnecting:
printf("Connection disconnecting\n");
break;
}

}

int main (int argc, const char * argv[]) {
CFDictionaryRef userOptions;
bool scResult;
SCNetworkConnectionContext scncctx = {0, NULL, NULL, NULL, NULL};

CFStringRef currentServiceId;

scResult = SCNetworkConnectionCopyUserPreferences(NULL, &currentServiceId,
&userOptions);


SCNetworkConnectionRef connection = nil;
connection = SCNetworkConnectionCreateWithServiceID (NULL,
currentServiceId,
MyNetworkConnectionCallBack, &scncctx );
SCNetworkConnectionStatus status =
SCNetworkConnectionGetStatus(connection);
if(status == kSCNetworkConnectionConnected)
printf("connected \n");
else
  printf("current status :%d\n", status);

SCNetworkConnectionScheduleWithRunLoop(connection,CFRunLoopGetCurrent(),kCFRunLoopDefaultMode);



CFRunLoopRun();

return 0;
}
--
Am able to get connection status if I connect to a modem, but it fails when
connected
to a WiFi/AirPort network.

Thanks,
Rashmi

Related mailsAuthorDate
mlHow to get AirPort Connection Status Rashmi Vyshnavi Sep 18, 06:50
mlRe: How to get AirPort Connection Status Jason Coco Sep 18, 10:40
mlRe: How to get AirPort Connection Status Michael Ash Sep 18, 17:21
mlRe: How to get AirPort Connection Status Bob Clark Sep 18, 22:45
mlRe: How to get AirPort Connection Status Rashmi Vyshnavi Oct 2, 12:55