분류없음2009/05/21 13:14

이올린에 북마크하기(0) 이올린에 추천하기(0)
Posted by 강지훈
Linux2009/05/01 02:51

우분투 새 배포판인 9.04를 VirtualBox에 설치 한 후, GuestAddition을 설치하고 재부팅을 하면, 에러가 발생하게된다.

이 문제를 해결 하기 위해서는 다음과 같은 절차를 수행하면 해결 가능하다.


1. 게스트확장설치를 메뉴에서 선택한 후, 마운트가 되면 해당 디렉토리로 이동한다. (보통은 /media/cdrom)

$ cd /media/cdrom


2. 바로 설치 하지 말고, 특정 폴더에 풀어준다.

/media/cdrom$  sudo ./VBoxLinuxAddition-x86.run --target ~/temp


3. 압축을 풀어놓은 디렉토리로 이동한 후, install.sh를 에디터로 연다. 415라인 정도에 있는 다음 내용을 수정한다.

/media/cdrom$ cd ~/temp
~/temp$ sudo vim ./install.sh

-------
- 415 : 1.5.99.* | 1.6
+ 415 : 1.5.99.* | 1.6.0


4. install.sh를 실행하여 설치한다.

~/temp$ sudo ./install.sh

출처 : http://pcandme.net/57
이올린에 북마크하기(0) 이올린에 추천하기(0)
Posted by 강지훈
분류없음2009/01/15 22:09
#include <stdarg.h>

static inline void error_exit(const char* fmt, const char* msg, ...)
{
    va_list args;
    va_start(args, msg);
    vfprintf(stderr, fmt, args);
    va_end(args);

    exit(1);
}

이올린에 북마크하기(0) 이올린에 추천하기(0)
Posted by 강지훈
분류없음2008/12/09 14:43
VI에서 Ctrl+]와 같은 기능

이클립스에선 ctrl + shift + p

이용규님 땡큐. ㅋㅋ
이올린에 북마크하기(0) 이올린에 추천하기(0)
Posted by 강지훈
분류없음2008/12/02 20:06

언젠가부터.. 회사 내 컴퓨터가 오른쪽 숫자키가 먹통이 되어있었는데..

난 거의 한달동안을 이렇게 불편한채로 그냥 써왔다. -_-;; 좀 게으름이 쩐당.;;

한영키가 속썩여 오늘 이런저런 셋팅을 해주던 중, 알아본 결과..

ctrl + shift + numlock 이 켜져있었던 것이다. 덜덜;

숫자패드로 마우스커서를 움직이는 기능을 제공하는 것이었는데,

난 몰르고 있었다. -_-

이올린에 북마크하기(0) 이올린에 추천하기(0)
Posted by 강지훈
Linux2008/11/26 09:38
/**
 * euckrToUtf8()
 *
 * @author     Ji-hoon Kang(luvflo@gmail.com)
 * @date    2008-11-26
 *
 * @description
 *     iconv를 사용하여 EUC-KR 문자열을 UTF-8으로 변환합니다.
 *
 */
string XpgUtil::euckrToUtf8(const char* szBuff)
{
    string retv;

    char* outbuf = NULL;
    char* out = NULL;

    size_t ileft = strlen(szBuff);
    size_t oleft = ileft * 2; //TODO: 임시로.. 확인 후 수정요망..

    out = outbuf = (char*)calloc(1, oleft + 1);

    iconv_t cd = iconv_open("UTF-8", "EUC-KR");
    if(cd < 0) {
        perror(":");
        if(out){
            free(out);
            out=outbuf=NULL;
        }
        return retv;
    }

    int err = iconv(cd, (char**)&szBuff, &ileft, &outbuf, &oleft);
    iconv_close(cd);
    *outbuf = 0;

    if(err >= 0) retv.assign(out);
    if(out){
        free(out);
        out=outbuf=NULL;
    }

    return retv;
}

이올린에 북마크하기(0) 이올린에 추천하기(0)
Posted by 강지훈
Linux/cURL2008/11/11 10:27
/*
 * curl_redirection example
 *
 * @date    2008. 11. 10
 * @author    ji-hoon Kang(luvflo@gmail.com)
 */

#include <stdio.h>
#include <memory.h>
#include <curl/curl.h>

typedef struct _ftpFile
{
    char    filename[FILENAME_MAX];
    FILE*     stream;
}FtpFile;


static size_t header_callback(void* ptr, size_t size, size_t nmemb, void* stream)
{
    char* buff = (char*)ptr;
    const char* content_disposition = "Content-Disposition: attachment;filename=";

    if(strstr(buff, content_disposition) )
    {
        FtpFile* pFileInfo = (FtpFile*)stream;
        memset(pFileInfo->filename, 0, sizeof(pFileInfo->filename));
        memcpy(pFileInfo->filename, buff+strlen(content_disposition), strlen(buff) - strlen(content_disposition) - 2);

        printf("catched filename : %s length : %d\n", pFileInfo->filename, strlen(pFileInfo->filename));
    }
    return size * nmemb;
}


static size_t write_callback(void* buffer, size_t size, size_t nmemb, void* stream)
{
    FtpFile* out = (FtpFile*)stream;
    if(out && !out->stream && out->filename)
    {
        out->stream = fopen(out->filename, "wb");
        if(!out->stream)
            return -1;
    }
    return fwrite(buffer, size, nmemb, out->stream);
}


/**
 * @param     hCurl - curl handle
 * @param    sURL -
 * @param    sLocalDir -
 * @return     'CURLE_OK' ok, otherwise failure.
 */
static CURLcode download(CURL* hCurl, const char* sURL, const char* sLocalDir)
{
    FtpFile     localfile;
    memset(&localfile, 0, sizeof(FtpFile));

    curl_easy_setopt(hCurl, CURLOPT_HEADERFUNCTION, header_callback);
    curl_easy_setopt(hCurl, CURLOPT_HEADERDATA, &localfile);
    curl_easy_setopt(hCurl, CURLOPT_URL, sURL);
    curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, write_callback);
    curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, &localfile);
    curl_easy_setopt(hCurl, CURLOPT_VERBOSE, 1);

    CURLcode res =  curl_easy_perform(hCurl);
    if(localfile.stream) fclose(localfile.stream);
    return res;
}


int main(int argc, char** argv)
{
    const char* sURL = "http://fmov.pann.com/mmediaDownload.jsp?FileID=12992569";
    const char* sLocalDir = "/home/david/Download";

    CURL*         hCurl = NULL;

    curl_global_init(CURL_GLOBAL_ALL);
    hCurl = curl_easy_init();

    download(hCurl, sURL, sLocalDir);

    curl_easy_cleanup(hCurl);
    curl_global_cleanup();

    return 0;
}



curl의 get_easy_info()에서 redirect url을 얻어오는 방법이 아닌, jsp page header에서 실제 다운로드 받는 파일 이름을 가져오는 예제이다.
다운로드 받는 시점에, 리다이렉션되는 파일의 실제 파일이름을 얻어오고자 할때 사용했던 방법이다.

이올린에 북마크하기(0) 이올린에 추천하기(0)
Posted by 강지훈
Linux2008/11/10 09:43
#include <stdio.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <memory.h>
#include <netinet/ether.h>
#include <net/if.h>

/**
 * @param szMAC[out] - mac address value.
 * @param nLen[out] - size of mac address
 * @return 0 ok, otherwise failure.
 *
 * @author Ji-hoon Kang(luvflo@gmail.com)
 * @date    2008-11-07
 */
int GetMacAddr(char* szMac, int* nLen)
{
    const char*  default_eth = "eth0";
    char*   mac_addr = NULL;
    struct ifreq  ifrq;
    int    fd = socket(AF_INET, SOCK_DGRAM, 0);

    memset(&ifrq, 0, sizeof(ifrq));
    strcpy(ifrq.ifr_name , default_eth);

    if(ioctl(fd, SIOCGIFHWADDR, &ifrq)<0)
    {
        close(fd);
        fprintf(stderr, "%s:%d> ERROR getMacAddr", __FILE__, __LINE__);
        return 1;
    }
 
    struct sockaddr *sa = &(ifrq.ifr_hwaddr);
    mac_addr = (char*)ether_ntoa((struct ether_addr*)sa->sa_data );
    if(mac_addr == NULL) return 1;

    memset(szMac, 0, sizeof(szMac));
    sprintf(szMac, "%s", mac_addr);
    *nLen = strlen(szMac);

    close(fd);
    return 0;
}

int main(int argc, char** argv)
{
    char  sMacAddr[64] = {0,};
    int  nLength = 0;
    if( GetMacAddr(sMacAddr, &nLength) )
    {
        return 1;
    }
    printf("MacAddr : %s\nString length : %d\n", sMacAddr, nLength);
    return 0;
}
이올린에 북마크하기(0) 이올린에 추천하기(0)
Posted by 강지훈
Linux2008/11/03 13:01


1. /etc/init.d/mountdevsubfs.sh 수정.

# Magic to make /proc/bus/usb work
#
#mkdir -p /dev/bus/usb/.usbfs
#domount usbfs "" /dev/bus/usb/.usbfs -obusmode=0700,devmode=0600,listmode=0644
#ln -s .usbfs/devices /dev/bus/usb/devices
#mount --rbind /dev/bus/usb /proc/bus/usb


Magic 아래쪽부터 mount 부분까지 주석 처리 되어있는 걸 없에자

수정 후

# Magic to make /proc/bus/usb work
#
mkdir -p /dev/bus/usb/.usbfs
domount usbfs "" /dev/bus/usb/.usbfs -obusmode=0700,devmode=0600,listmode=0644
ln -s .usbfs/devices /dev/bus/usb/devices
mount --rbind /dev/bus/usb /proc/bus/usb




2. /etc/udev/rules.d/40-permissions.rules 에 유저그룹 vboxusers 를 추가 해 줘야 함

# USB serial converters
SUBSYSTEM=="usb_device", GOTO="usb_serial_start"
SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", GOTO="usb_serial_start"
GOTO="usb_serial_end"
LABEL="usb_serial_start"
ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001" \
, MODE="0660", GROUP="dialout"
LABEL="usb_serial_end"


이 부분을

# USB serial converters
SUBSYSTEM=="usb_device", GOTO="usb_serial_start"
SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", GOTO="usb_serial_start"
GOTO="usb_serial_end"
LABEL="usb_serial_start"
ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001" \
,GROUP="vboxusers", MODE="0660", GROUP="dialout"
LABEL="usb_serial_end"

로 그룹 부분 설정 추가




3. usbfs 설정 하나 더 추가 (/etc/fstab)

젤 아래줄에

#usbfs
none /proc/bus/usb usbfs devgid=46,devmode=664 0 0

이올린에 북마크하기(0) 이올린에 추천하기(0)
Posted by 강지훈
분류없음2008/09/11 20:32

poco library를 살펴보다가, 좋은 아이디어가 있어서, 남긴다.

C에서의 함수포인터 처럼, C++객체의 메소드를 포인터로 넘길 수 없을까? 라는 생각을 하고 있었는데,
그것에 대한 어느정도의 해답이 된 것 같다.

객체 내에 static으로 구현된 멤버 메소드는 그냥 함수포인터 처럼 넘기는 것이 가능하다.
그렇지 않고, static이 아닌 public으로 되어있는 멤버에 대한 포인터를 넘기는 방법을 어떻게 될까?

이거.. 나만 모르고 있었던 건가 --;;.......

편의상 인라인으로 처리한다..


#include <iostream>
using namespace std;

class MyObject
{
public:
    MyObject(){};
    ~MyObject(){};
public:
    void callback()
    {
        cout << "call me" << endl;
     }
};

class JHObject
{
public:
    JHObject(){};
    ~JHObject(){};
public:
    void run(MyObject* obj, void (MyObject::*pMethod)())
    {
          (obj->*pMethod)();
    }
};

   
int main()
{
    MyObject my;
    JHObject jh;
    jh.run(&my, &MyObject::callback);
    return 0;
}



간단했다.. 역시 알면 간단, 모르면 -_- 안드로메다..;;
객체에대한 메서드를 포인터로 넘길때에는 그 메서드를 호출할 객체에 대한 포인터도
함께 넘겨야 했던 것이다...

 

이올린에 북마크하기(0) 이올린에 추천하기(0)
Posted by 강지훈