Tuesday, April 12, 2011

How to disable other adapters

netsh interface isatap set state disabled
netsh interface teredo set state disabled
netsh in 6to4 set state disable

Sunday, April 3, 2011

How to use pcap library in Borland C++Builder

[Compile]

1. In Borland C++Builder,  before you include pcap.h file, add the following codes.

#include "winsock2.h"
#define HAVE_U_INT8_T // for preventing Multiple declaration for 'int8_t'
#define WPCAP
#define HAVE_REMOTE
#include "pcap.h"

2. If you don't want to define HAVE_U_INT8_T, add the following codes in bittype.h.

#if SIZEOF_CHAR == 1
typedef unsigned char u_int8_t;
#ifndef __BORLANDC__
typedef signed char int8_t;
#endif // __BORLANDC__
#elif SIZEOF_INT == 1
typedef unsigned int u_int8_t;
#ifndef __BORLANDC__
typedef signed int int8_t;
#endif // __BORLANDC__
#else  /* XXX */
#error "there's no appropriate type for u_int8_t"
#endif


[Link]

In WinPcap/Lib folders, copy Packet.lib and wpcap.lib in any folders.

coff2omf Packet.lib Packet2007.lib
del Packet.lib
move Packet2007.lib Packet.lib




coff2omf wpcap.lib wpcap2007.lib
del wpcap.lib
move wpcap2007.lib wpcap.lib

Saturday, April 2, 2011

카카오톡 망 부하를 계산해 봅시다.

http://goo.gl/Yqsxk

이통사 기술팀의 내부 자료에 따르면 카카오톡 서버는 10분 주기로 280byte의 신호를 송신한다. 가입자 상태 확인 등 4개 신호가 시간당 6차례, 하루 24시간 전송된다. 카카오톡 가입자 1인당 자신도 모르게 매달 1만 7280건(4X6X24X30)의 트래픽이 발생한다. 가입자 1000만명으로 계산하면 매달 1728억건. 한달 추산 데이터 트래픽은 4만 5061기가바이트(GB·44TB)에 이른다.


44TB가 많은 것처럼 뉘앙스를 풍기는 군요. 자, 그럼 이 44TB가 많은 것인지, 아닌지를 비교해서 분석해 봅시다.


요즘에는 네떡 카드가 좋아 져서 Gbps(1초에 Giga bit를 처리해 주는)급 NIC Card가 많이 나왔습니다. 일반 가정 환경에서는 실제로 그만큼은 쓰지는 못하고, 큰 규모의 네트워크 대역이되면 Gbps급으로 사용이 되는 경우를 볼 수 있습니다. 한달동안 계속해서 그 10배인 10Gbps가 흐른다고 가정을 하고 네트워크 대역폭을 계산해 보겠습니다.


1초 : 10 Gb
하루 : 10 Gb * 86400 = 864000 Gb (하루는 86400초)

한달 : 864000 Gb * 30 =  25920000 Gb ( 한달은 30일)

25920000 Gb = 3240000 GB =
약 3614 TB


예를 들어 국내 특정 ISP가 동시 처리 능력이 100Gbps라고 가정을 하면 한달에 처리하는 대역폭은 약 3만 TB가 됩니다. CDN 서비스를 하는 곳은 동시 600Gbps를 처리할 수가 있다고 들었습니다(2009년도 자료).


100 Gbps를 처리하는 ISP에서의 네떡은 3만 TB / 카카오톡에서 차지하는 네떡은 44TB


돈으로 3만원과 44원을 비교하면 44 TB가 얼마나 작은 것인지 금방 알 수 있습니다. 결론적으로 이통사가 카카오톡을 싫어 하는 이유는 "트래픽은 절대 아니라는 것"이 기사에 의해 저절로 밝혀진 꼴입니다.

Tuesday, March 15, 2011

Simple c++ question. Is "T" class or template?




#include <iostream>

template <class T> // (1)
class B
{
public:
  void foo(T* t); // (2)
};
 
class T // (3)
{
public:
  int i;
};
 
void B<T>::foo(T* t) // (4)
{
  std::cout << t->i << std::endl;
}
 
int main()
{
  B<T> b; // (5)
  T t;
  t.i = 3;
  b.foo(&t);
}

BugTruck Seminar at Sookmyung Womens University

Sunday, March 6, 2011

How to overload new and delete operator


void* __cdecl operator new(size_t size)
{
 return malloc(size);
}

void __cdecl operator delete(void* p)
{
 free(p);
}

Wednesday, March 2, 2011

Where array count is stored when new[] is called?


[source code]
 
#include <new> // for size_t
#include <stdio.h>

class A 
{
public:
  A() {}
  virtual ~A() {}
  static void* operator new (size_t size)
  {
    void* res = ::operator new(size);
    printf("new   return %p\n", res);
    return res;
  }
 
  static void operator delete (void *p)
  {
    printf("delete       %p\n", p);
    ::operator delete(p);
  }
 
  static void* operator new[](size_t size)
  {
    void* res = ::operator new(size);
    printf("new[] return %p\n", res);
    return res;
  }
 
  static void operator delete[](void *p)
  {
    printf("delete[]     %p\n", p);
    ::operator delete[](p);
  }
};
 
void foo()
{
  A* a = new A;
  printf("a=           %p\n", a);
  delete a;
}
 
void bar()
{
  A* a = new A[5];
  printf("a=           %p\n", a);
  delete []a;
}
 
int main()
{
  foo();
  printf("\n");
  bar();
}
 
 
[result]
 
new   return 00633B88 // same
a=           00633B88 // same
delete       00633B88 // same

new[] return 00631A90
a=           00631A94 // 4 byte skipped !!!
delete[]     00631A90


When new[] is called, you can figure out that array count value(5) is stored prior to new[] operator return pointer value(4 bytes offset in the above result). Of course(as you guess), when delete[] is called, the count value is used to delete all allocated objects.

Sunday, February 27, 2011

C++ to HTML

Sometimes, if you would show your C++ source code in a certain web site(e.g. blog), you'd better convert C++ source code into HTML format. Here is a good web site for this.

http://www.bedaux.net/cpp2html

The differences among auto_ptr, scoped_ptr and shared_ptr



#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp>
#include <memory>
#include <stdio.h>

#include "Int.h" // include 4 bytes int class

typedef std::auto_ptr<Int>     auto_ptr;
typedef boost::scoped_ptr<Int> scoped_ptr;
typedef boost::shared_ptr<Int> shared_ptr;

void size()
{
  printf("sizeof(auto_ptr)   is %d\n", sizeof(auto_ptr));   // 4
  printf("sizeof(scoped_ptr) is %d\n", sizeof(scoped_ptr)); // 4
  printf("sizeof(shared_ptr) is %d\n", sizeof(shared_ptr)); // 8
}

void foo_ptr(auto_ptr ap)
{
  ap->foo();
}

void foo_ptr(scoped_ptr scp)
{
  scp->foo();
}

void foo_ptr(shared_ptr shp)
{
  shp->foo();
}

void foo()
{
  {
    //
    // auto_ptr
    //
    Int* pi = new Int(5);
    auto_ptr ap(pi);

    foo_ptr(ap);     // compile ok
    ap->foo();       // runtime error
  }

  {
    //
    // scoped_ptr
    //
    Int* pi = new Int(5);
    scoped_ptr scp(pi);

    // foo_ptr(scp); // compile error
    scp->foo();      // runtime ok
  }

  {
    //
    // scoped_ptr
    //
    Int* pi = new Int(5);
    shared_ptr shp(pi);
foo_ptr(shp);    // compile ok
    shp->foo();      // runtime ok
  }
}

int main()
{
  size();
  foo();
}

Download source code : http://sites.google.com/site/gilgildownload/download/IntTest2.zip

C++ copy constructor and assign operator



Can you distinguish between copy constructor and assign operator in C++ code? Here's a sample for you. Be aware of knowing that even if it's code format looks assign operator format, it is not assign operator format but copy constructor one.


Download source code : https://sites.google.com/site/gilgildownload/download/IntTest.zip


class Int
{
public:
  // constructor
  Int(const int i = 0)                 { printf("C...
  Int(const Int& r)                    { printf("C...


  // destructor
  virtual ~Int()                       { printf("D...


  // assign operator
  const Int& operator = (const int i)  { printf("A...
  const Int& operator = (const Int& r) { printf("A...
};


void foo()
{
  {
    Int a(1);  // C
    Int b(2);  // C
    Int c(a);  // C
  }


  {
    Int a(3);  // C
    Int b;     // C
    b = 4;     // A
    Int c;     // C
    c = a;     // A
  }


  {
    Int a(5);  // C
    Int b = 6; // C // not assign operator
    Int c = a; // C // not assign operator
  }
}


int main()
{
  foo();
}

Wednesday, February 23, 2011

Highscore - The Boost C++ Libraries

There are so many articles and exmaples for boost.



How to build boost library as release & static & multi thread & static runtime library in visual studio

In boost directory, type the followng command.

bjam variant=release link=static threading=multi address-model=32 runtime-link=static

It may take a few minutes to build libraries, and you will get "*-mt-s-*.lib" files in library directory($root/stage/lib).

Form example,
2011-02-23 오후 11:53 720,852 libboost_date_time-vc80-mt-s-1_45.lib
2011-02-23 오후 11:54 1,893,972 libboost_filesystem-vc80-mt-s-1_45.lib
2011-02-23 오후 11:55 5,675,002 libboost_graph-vc80-mt-s-1_45.lib
2011-02-23 오후 11:48 423,886 libboost_iostreams-vc80-mt-s-1_45.lib
2011-02-23 오후 11:50 1,550,020 libboost_math_c99-vc80-mt-s-1_45.lib
2011-02-23 오후 11:50 1,570,926 libboost_math_c99f-vc80-mt-s-1_45.lib
2011-02-23 오후 11:50 1,538,966 libboost_math_c99l-vc80-mt-s-1_45.lib
2011-02-23 오후 11:49 5,769,460 libboost_math_tr1-vc80-mt-s-1_45.lib
2011-02-23 오후 11:49 5,905,880 libboost_math_tr1f-vc80-mt-s-1_45.lib
2011-02-23 오후 11:49 5,706,556 libboost_math_tr1l-vc80-mt-s-1_45.lib
2011-02-23 오후 11:51 320,242 libboost_prg_exec_monitor-vc80-mt-s-1_45.lib
2011-02-23 오후 11:50 5,050,400 libboost_program_options-vc80-mt-s-1_45.lib
2011-02-23 오후 11:50 108,922 libboost_random-vc80-mt-s-1_45.lib
2011-02-23 오후 11:54 10,374,684 libboost_regex-vc80-mt-s-1_45.lib
2011-02-23 오후 11:51 11,429,740 libboost_serialization-vc80-mt-s-1_45.lib
2011-02-23 오후 11:51 926,442 libboost_signals-vc80-mt-s-1_45.lib
2011-02-23 오후 11:53 92,208 libboost_system-vc80-mt-s-1_45.lib
2011-02-23 오후 11:52 10,232,224 libboost_test_exec_monitor-vc80-mt-s-1_45.lib
2011-02-23 오후 11:52 464,268 libboost_thread-vc80-mt-s-1_45.lib
2011-02-23 오후 11:52 11,447,096 libboost_unit_test_framework-vc80-mt-s-1_45.lib
2011-02-23 오후 11:53 46,877,338 libboost_wave-vc80-mt-s-1_45.lib
2011-02-23 오후 11:51 9,099,918 libboost_wserialization-vc80-mt-s-1_45.lib