gethostbyname

Linux/Linux:c개발 2015. 4. 14. 09:46

<함수 prototype>

struct hostent *gethostbyname(const char *name);

int gethostbyname_r(const char *name,
               struct hostent *ret, char *buf, size_t buflen,
               struct hostent **result, int *h_errnop);


두 함수 모두 return type은 hostent  struct 이다.


<struct hostent 구조 >

struct hostent { char *h_name; /* official name of host */ char **h_aliases; /* alias list */ int h_addrtype; /* host address type */ int h_length; /* length of address */ char **h_addr_list; /* list of addresses */ 

==> 아래쪽에 in_addr구조체의 s_addr 변수 참조. 같은 형태임. 0xff01ffff의 네트웍바이트(순서대로) 형태(255.1.255.255)

} #define h_addr h_addr_list[0] /* for backward compatibility */ The members of the hostent structure are:


h_addrtype The type of address; always AF_INET or AF_INET6 at present. h_length The length of the address in bytes. h_addr_list An array of pointers to network addresses for the host (in net- HOST_NOT_FOUND The specified host is unknown. NO_ADDRESS or NO_DATA The requested name is valid but does not have an IP address. NO_RECOVERY A non-recoverable name server error occurred. TRY_AGAIN A temporary error occurred on an authoritative name server. Try again later.



<그 외 network관련 struct들 >

           struct sockaddr_in {
               sa_family_t    sin_family; /* address family: AF_INET */
               in_port_t      sin_port;   /* port in network byte order */
               struct in_addr sin_addr;   /* internet address */
           };

           /* Internet address. */
           struct in_addr {
               uint32_t       s_addr;     /* address in network byte order */  
           };

0xffffffff의 네트웍바이트 형태.=255.255.255.255


<in_addr_t  inet_addr(hostname) 함수> 이름을 0xffffffff (255.255.255.255 효과) 형태로 변환리턴.


리턴type:  typedef uint32_t in_addr_t;   

INADDR_NONE= -1 (255.255.255.255)을 리턴하는 경우. 약간문제가 될때도 있으나 거의 괜찮음.




Posted by yongary
,

c++하나를 불러쓰는 경우

 

wrapping layer를 만들어서,

c언어에서 불러쓰면 된다.

 

예) c++파일 안에서

 

extern "C" {

MyClass* myclass_new()

{

return new MyClass();

}

..몇개 함수 더 매핑.

}

이렇게만 하면,

main. c파일안에서 아래와 같이 호출이 가능하다.

 

struct MyClass *m = myclass_new();

 

 

 

그리고  build시에는 특히 c빌드시(혹은 최종 link시에)

gcc main.c -lstdc++  추가 필요....

 

 

 

참고 blog: http://ospace.tistory.com/215 

Posted by yongary
,

아주 유용하게 쓰고 있는 자동접속 script.

전문가가 ssh_stdin 을 개발해 주셔서, 이를 이용해 쓰고 있다.


===================================자동접속 + 작업 SCIRPT ==============

#!/bin/sh



PASSWD="myPasswd!"

curDir=$(pwd)

SSH_STDIN=$curDir/ssh_stdin

sshOption="-T -o StrictHostKeyChecking=no -o ConnectTimeout=1 -o NumberOfPasswordPrompts=1"



SVR_LIST="172.25.49.135 172.25.49.136"


mpList=$(eval echo $SVR_LIST)


for i in $mpList

        do


        echo "---------"$i

        echo $PASSWD | $SSH_STDIN ssh $sshOption "root@"$i "ps -ef|grep redis"

        echo $PASSWD | $SSH_STDIN ssh $sshOption "root@"$i "nstatus"

 

  #scp를 하고 싶을때는 ..  -T옵션 빼고.. $1에 파일이름 줘서.. 아래처럼. 하면 된다.

  echo $PASSWD | $SSH_STDIN scp $sshOption $1 "root@"$i":"$1

        done



=============================ssh_stdin내용=================================

#!/bin/bash


if [ -n "$SSH_ASKPASS_PASSWORD" ]; then

    cat <<< "$SSH_ASKPASS_PASSWORD"

elif [ $# -lt 1 ]; then

    echo "Usage: echo password | $0 <ssh command line options>" >&2

    exit 1

else


read SSH_ASKPASS_PASSWORD


export SSH_ASKPASS=$0

export SSH_ASKPASS_PASSWORD


[ "$DISPLAY" ] || export DISPLAY=dummydisplay:0


# use setsid to detach from tty

# exec setsid "$@" </dev/null

exec setsid "$@"

fi

Posted by yongary
,

key

javascript 2015. 4. 2. 23:07

<key event>

document.onkeydown=checkKey;

function checkKey(e){

  if(e.keyCode=='37'){  //left Key, 38:up, 39:right, 40:down

     alert('left');

  }

}



Posted by yongary
,

closure

javascript 2015. 4. 2. 09:39

클로져에 대해서 나름대로 정리해보면,

아래와 같은 함수에서 MyClass을 outter함수라고 부를때,

내부 함수 (gettitle)가  outter의 지역변수를 계속 사용할 수 있다는 개념.  

(javascript의 initialize비용이 비싸므로, closure를 이용해서 inner함수 안에서 if(!undefined) define을 할 수 있다.)

 ==> Point: 외부함수가 종료된 이후에도 사용할 수 있다.


var that=this 로 해서, this도 많이 사용한다고 한다. 이렇게 안하면 this가 전역변수인 window를 나타낼 수 있기 때문...



function MyClass(_title){

  var title=_title;

  return{   //json스타일 객체를 return.

     getTitle:function() { return title;},

  }

}


g=MyClass('ggg');

m=MyClass('mmm');


alert(g.geTtitle());   //m.getTilte()도 잘 동작.




참조: devbox

      Nonblock

Posted by yongary
,

eclipse js 환경

javascript 2015. 4. 1. 08:31

1. Web, OSGI  를 설치한다. (for Web,  install new software 에서)

  참고사이트: http://fishbear.tistory.com/2


2. JSDT 를 설치. (for JS,  eclipse marketplace 에서)

   - jsdt for jQuery 

   - angularJS eclipse(0.10.0?)

   - jsdt for ExtJS (1.7?)



속성 js Lib에서 jQuery등 추가하고..( ECMA, jQuery, ExtJS..)

$('head').   (점찍고 Ctrl+Enter로 확인)

Posted by yongary
,

HTML5

javascript 2015. 3. 31. 14:55

HTML5는 javascript의 확장판이라고 볼 수 있다.


이 중에서 쓸만한 것들을 나열해보면


1.Geolocation


2.Web Storage


3.IndexedDB + Object Store


4.Application Cache


5.WebSocket


6.File API


7.Drag & Drop 





그 외 5개+1는 천천히 알아보자

Server-Sent Event

Web Workers

WebGL

Selector API

Notifications API

Web SQL DataBase(2009년 중단된듯 )





Posted by yongary
,

1. Web에서 native 호출


 webView.addJavascriptInterface ( new MyNativeAPI(), "MyNativeAPI");


 class MyNativeAPI{

public String whoAmI() {

return "I am Yongary";

}

 }



2. native에서 웹호출

  webView.loadUrl("file://blabla");   //assets/www밑 파일

  webView.loadUrl("http://blabla");   // shouldOverrideUrlLoading 함수를 override해서 폰 default브라우저로 연동하는게 좋음

  webView.loadUrl("javascript:alert('I am from native')");

  

Posted by yongary
,

android + phoneGap

phoneGap 2015. 3. 30. 09:42

(그냥 android WebView를 이용해도 될 것 같은데.. 이부분은 좀 있다 확인하고..)


본 글은 andoid에서 phoneGap의 WebView를 추가하려면..



1. cordova.apache.org*을 다운받아서 android밑에 unzip

2. /framework/cordova-x.x.x.jar 를 만든다.  (  framework에서 run ant jar 하면 됨) 

3. .jar를 /libs 밑으로 복사



4. andoid 프로젝트에 /res/xml/main.xml 같은 layout 파일에 CordovaWebView 추가 


5. andoid 소스에 CordovaInterface implements 구현.




6. Camera이용시에  setActivityResultCallback(CordovaPlugin .. ) 및 startActivityForResult(CordovaPlugin.. ) 추가



7. ThreadPool 추가.  public ExecutorService getThreadPool()  ==> plugins이 thread를 가지기 위함.


8. /assets/www 밑에 HTML들 복사

9. /framework/res/xml 밑에 있는 config.xml을  프로젝트의 /res/xml 밑으로 복사 



원본 링크




Posted by yongary
,

Scrum

IT 2015. 3. 27. 17:21


위키kr :  Scrum(애자일 개발 프로세스)


- 매일15분씩 회의. (어제한일, 오늘한일, 장애상황)


- 스프린트 (한 주기) 관리  ( 30일 +- 1~4주)


- Sprint backlog

  다음 Sprint의 backlog도 미리 준비한다.



==========링크내용===================================

제품 책임자(Product Owner) 
제품 백 로그를 정의하여 우선순위를 정해 준다.

스크럼 마스터(ScrumMaster) 
프로젝트 관리자(코치)

스크럼 마스터는, 일반적인 관리를 수행하는 프로젝트 관리자들과는 달리 팀원을 코칭하고 프로젝트의 문제 상황을 해결하는 역할을 하며, 제품 책임자는 스프린트 목표와 백로그등의 결정에 있어 중심이 되는 상위 관리자로, 제품 책임자가 독단적으로 목표를 결정하지 않고, 고객과 관리자 및 팀원들이 모여서 목표를 정한다.

이런 과정을 거친 뒤, 개발 팀원들이 주도적으로 스프린트 목표를 달성하기 위한 작업을 정해 나가게 된다. 보통, 각 작업들은 4시간에서 16시간 정도 걸리도록 정한다. 물론, 작업을 정하고 할당하는데는 고객이나 제품 책임자와는 상관 없이 팀원 자율로 진행된다. 이와 같은 자율적인 행위를 통해서 팀원들은 의사를 활발하게 주고 받게 되고, 끈끈한 협업체계를 가지게 된다.

Posted by yongary
,