Declaration
std::string localhost(socket_int s); template <class Socket> std::string localhost(Socket& s); std::string localhost();
Overview
localhost() 関数は自ホストの IP アドレスを取得するための関数です. 引数にコネクション確立済みのソケットが指定された場合,そのソケットを用いて IP アドレスを取得します.引数なしで localhost() が呼ばれた場合は, IP アドレスを取得するためのダミーのコネクションを確立し, そのダミーソケットを用いて IP アドレスを取得します.
Example
#include <iostream>
#include "clx/resolver.h"
int main(int argc, char* argv[]) {
/*
* clx::localhost(socket_int s);
* clx::localhost(Socket& s);
* clx::localhost();
*
* 現在,通信を行っている(connect の完了している)ソケットが存在
* する場合は,そのソケットを用いてローカルホストの IP アドレスを
* 取得する.通信を行っているソケットが存在しない場合は,引数なし
* で localhost を呼び出す.
*/
std::cout << clx::localhost() << std::endl;
return 0;
}
Result 192.168.0.2