zoukankan      html  css  js  c++  java
  • Get host name and port(Object-c)

    /**************************************************************************
    @param pChHostName: [output]Get system proxy host name
    @param pChPort: [output]Get system proxy port
    @param iProxyType:[input]ProxyType: 1(HTTP);2(HTTPS);....
    **************************************************************************/
    bool MacGetProxyHostNameAndPort(int iProxyType, char *pChHostName, char *pChPort)
    {
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    
        bool bRet = false;
        NSDictionary *proxyConfiguration = NSMakeCollectable([(NSDictionary*) SCDynamicStoreCopyProxies(NULL) autorelease]);
    
        if (!proxyConfiguration)
        {
            [pool release];
            return bRet;
        }
    
        //Init proxy type
        NSString *nsStrProxyEnable = nil;
        NSString *nsStrProxyHostName = nil;
        NSString *nsStrProxyPort = nil;
        if (2 == iProxyType)
        {
            nsStrProxyEnable = (NSString*)[proxyConfiguration objectForKey:@"HTTPSEnable"];
            nsStrProxyHostName = (NSString*)[proxyConfiguration objectForKey:@"HTTPSProxy"];
            nsStrProxyPort = [NSString stringWithFormat:@"%d", [[proxyConfiguration objectForKey:@"HTTPSPort"] intValue]];
        }
        else
        {
            nsStrProxyEnable = (NSString*)[proxyConfiguration objectForKey:@"HTTPEnable"];
            nsStrProxyHostName = (NSString*)[proxyConfiguration objectForKey:@"HTTPProxy"];
            nsStrProxyPort = [NSString stringWithFormat:@"%d", [[proxyConfiguration objectForKey:@"HTTPPort"] intValue]];
        }
    
        int iProxyEnable = [nsStrProxyEnable intValue];
        if (1 == iProxyEnable)
        {
            const char *pHostName = [nsStrProxyHostName UTF8String];
            int iLen = [nsStrProxyHostName length];    
            memset(pChHostName, 0, 200);
            memcpy(pChHostName, pHostName, iLen);
    
            const char *pPort = [nsStrProxyPort UTF8String];
            iLen = [nsStrProxyPort length];    
            memset(pChPort, 0, 200);
            memcpy(pChPort, pPort, iLen);
            bRet = true;
        }
    
        [pool drain];
        return bRet;
    }
    ps:本博文只用于日常备注及学习交流,请勿用于任何商业用途,涉及网摘等资料如有侵犯原作者权利,请联系确保及时更正!
  • 相关阅读:
    Pandas系列
    Pandas快速入门
    Pandas数据结构
    机器学习三剑客之Matplotlib
    机器学习三剑客之Pandas
    机器学习三剑客之Numpy
    NumPy IO文件操作
    NumPy使用 Matplotlib 绘制直方图
    nyoj 37 回文字符串
    判断一个字符串是不是回文串
  • 原文地址:https://www.cnblogs.com/sz-leez/p/4080153.html
Copyright © 2011-2022 走看看