2014-08-11

[Object-C] CocaAsynSocket 使用在 iOS 7.1 上面

需要用到 TCP/IP on iOS , 之前同事有人使用CocaAsynSocket來實作.
另外一個好同事, 幫我把 mac 版的測試過.
當要移轉到 iOS 時, 發生下列幾個大問題了
1. NSHost 不存在  iOS , 所以 getLocalAddresses 需要找外援
2. CocaAsynSocket 移轉到 iOS , 按下 Build 出現一堆reference 不存在
Undefined symbols for architecture i386:
  "_SSLClose", referenced from:
      -[GCDAsyncSocket closeWithError:] in GCDAsyncSocket.o
  "_SSLCopyPeerTrust", referenced from:
      -[GCDAsyncSocket ssl_continueSSLHandshake] in GCDAsyncSocket.o
  "_SSLCreateContext", referenced from:
      -[GCDAsyncSocket ssl_startTLS] in GCDAsyncSocket.o
  "_SSLGetBufferedReadSize", referenced from:
      ___33-[GCDAsyncSocket flushSSLBuffers]_block_invoke in GCDAsyncSocket.o
      -[GCDAsyncSocket doReadData] in GCDAsyncSocket.o
  "_SSLHandshake", referenced from:
      -[GCDAsyncSocket ssl_continueSSLHandshake] in GCDAsyncSocket.o
  "_SSLRead", referenced from:
      -[GCDAsyncSocket flushSSLBuffers] in GCDAsyncSocket.o
      -[GCDAsyncSocket doReadData] in GCDAsyncSocket.o
  "_SSLSetCertificate", referenced from:
      -[GCDAsyncSocket ssl_startTLS] in GCDAsyncSocket.o
  "_SSLSetConnection", referenced from:
      -[GCDAsyncSocket ssl_startTLS] in GCDAsyncSocket.o
  "_SSLSetEnabledCiphers", referenced from:
      -[GCDAsyncSocket ssl_startTLS] in GCDAsyncSocket.o
  "_SSLSetIOFuncs", referenced from:
      -[GCDAsyncSocket ssl_startTLS] in GCDAsyncSocket.o
  "_SSLSetPeerDomainName", referenced from:
      -[GCDAsyncSocket ssl_startTLS] in GCDAsyncSocket.o
  "_SSLSetPeerID", referenced from:
      -[GCDAsyncSocket ssl_startTLS] in GCDAsyncSocket.o
  "_SSLSetProtocolVersionMax", referenced from:
      -[GCDAsyncSocket ssl_startTLS] in GCDAsyncSocket.o
  "_SSLSetProtocolVersionMin", referenced from:
      -[GCDAsyncSocket ssl_startTLS] in GCDAsyncSocket.o
  "_SSLSetSessionOption", referenced from:
      -[GCDAsyncSocket ssl_startTLS] in GCDAsyncSocket.o
  "_SSLWrite", referenced from:
      -[GCDAsyncSocket doWriteData] in GCDAsyncSocket.o
  "_kCFStreamNetworkServiceType", referenced from:
      -[GCDAsyncSocket enableBackgroundingOnSocketWithCaveat:] in GCDAsyncSocket.o
  "_kCFStreamNetworkServiceTypeVoIP", referenced from:
      -[GCDAsyncSocket enableBackgroundingOnSocketWithCaveat:] in GCDAsyncSocket.o
  "_kCFStreamPropertySSLSettings", referenced from:
      -[GCDAsyncSocket cf_startTLS] in GCDAsyncSocket.o
  "_kCFStreamSSLAllowsAnyRoot", referenced from:
      -[GCDAsyncSocket ssl_startTLS] in GCDAsyncSocket.o
  "_kCFStreamSSLAllowsExpiredCertificates", referenced from:
      -[GCDAsyncSocket ssl_startTLS] in GCDAsyncSocket.o
  "_kCFStreamSSLAllowsExpiredRoots", referenced from:
      -[GCDAsyncSocket ssl_startTLS] in GCDAsyncSocket.o
  "_kCFStreamSSLCertificates", referenced from:
      -[GCDAsyncSocket ssl_startTLS] in GCDAsyncSocket.o
  "_kCFStreamSSLIsServer", referenced from:
      -[GCDAsyncSocket ssl_startTLS] in GCDAsyncSocket.o
  "_kCFStreamSSLLevel", referenced from:
      -[GCDAsyncSocket ssl_startTLS] in GCDAsyncSocket.o
  "_kCFStreamSSLPeerName", referenced from:
      -[GCDAsyncSocket ssl_startTLS] in GCDAsyncSocket.o
  "_kCFStreamSSLValidatesCertificateChain", referenced from:
      -[GCDAsyncSocket ssl_startTLS] in GCDAsyncSocket.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

解法

1.  iPhone/iPad/OSX: How to get my IP address programmatically?

2.新增 Library for Security and CFNetwork

  • CFNetwork.framework
  • Security.framework

2014-03-10

[Linux] sudo 相關設定

如何允許一般使用者可以有sudo 權限

chmod 770 /etc/sudoers
vi /etc/sudoers
chmod 440 /etc/sudoers

/etc/sudoers 變更中, 可以針對單一User 也可以使用Group 設定

1. 使用一群Group
# Allow members of group sudo to execute any command
%sudo    ALL=(ALL:ALL) ALL

2. 變更單一User
username ALL=(ALL:ALL)  ALL

2014-01-24

[Linux] SSH Client 相關設定

已經習慣使用 Mac 作為工作平台.需要管理Linux Server.
目前多半使用 ssh 做連線的工具, 這兩天某Server 重新安裝, ssh key 有改過沒法進去.
網路上找了一下方法.

 1. 刪掉 ~/.ssh/known_hosts 裡頭相對應的IP or Server Name
 2. 刪掉 ~/.ssh/known_hosts 整個檔案. 


找尋過程中, 發現可以將 Server 相關設定寫好, 不用每次敲server name and username
vi ~/.ssh/config
======================
Host $SessionName
    Hostname $ConnectionName
    User $username

======================

$SessionName 你可以記住的代稱
$ConnectionName 連線的主機名稱或IP
$username Login Name




參考資料
1. http://blog.xuite.net/yctseng/notes/24912310-ssh
2. 使用SSH CONFIG