首页 > 其他 > 详细

Get host name and port(Object-c)

时间:2014-11-06 23:22:45      阅读:507      评论:0      收藏:0      [点我收藏+]

#import <SystemConfiguration/SCDynamicStoreCopySpecific.h>
#import <SystemConfiguration/SCSchemaDefinitions.h>
#import <Security/Security.h>

void GetProxyHostNameAndPort((CFStringRef proxyEnableKey, CFStringRef proxyHostNameKey, CFStringRef proxyPortKey, NSString **hostNamePtr, int *portPtr)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

//Get general proxy info
CFDictionaryRef proxyInfoCPtr = SCDynamicStoreCopyProxies(NULL);
NSDictionary *proxyInfo = (__bridge NSDictionary *) proxyInfoCPtr;
NSNumber *proxyEnabled = proxyInfo[(__bridge NSString *)proxyEnableKey];

//Check proxy enabled?
if (![proxyEnabled intValue])
{
*hostNamePtr = nil;
*portPtr = 0;

[pool release];
return;
}

*hostNamePtr = proxyInfo[(__bridge NSString *)proxyHostNameKey];
NSNumber *portNumber = proxyInfo[(__bridge NSString *)proxyPortKey];
*portPtr = [portNumber intValue];

[pool release];
return;
}

-------------------------------------------------------------
GetProxyHostNameAndPort(kSCPropNetProxiesHTTPEnable, kSCPropNetProxiesHTTPProxy, kSCPropNetProxiesHTTPPort, hostName, port);
GetProxyHostNameAndPort(kSCPropNetProxiesHTTPSEnable, kSCPropNetProxiesHTTPSProxy, kSCPropNetProxiesHTTPSPort, hostName, port);

Get host name and port(Object-c)

原文:http://www.cnblogs.com/sz-leez/p/4080153.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!