1 / 8

[2011-2] 시스템 프로그래밍 Class 3- 실습 : Endian (Byte order)

[2011-2] 시스템 프로그래밍 Class 3- 실습 : Endian (Byte order). Visual C 에서 Debugging 하기 지역변수 / 조사식 Memory Call Stack 과 함수 Linux 에 접속하여 gcc 로 컴파일하기. 담당교수 : 최 윤 정 2011. 9. 6. 16 진수 0x12345678 을 little endian : Least significant byte has lowest address

buck
Télécharger la présentation

[2011-2] 시스템 프로그래밍 Class 3- 실습 : Endian (Byte order)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. [2011-2] 시스템 프로그래밍Class 3-실습 : Endian (Byte order) • Visual C에서 Debugging하기 • 지역변수 / 조사식 • Memory • Call Stack과 함수 • Linux 에접속하여 gcc로 컴파일하기 담당교수 : 최 윤 정 2011. 9. 6

  2. 16진수 0x12345678을 • little endian : Least significant byte has lowest address • (하위메모리)… 78 56 34 12… (상위메모리) • big endian : Least significant byte has highest address • (하위메모리)… 12 34 56 78… (상위메모리) • Tcp/ip : big endian • 네트워크 데이터전송시 모든 Router는 big endian 방식을 사용하기 때문에 • IP주소와 Port 번호를 big endian으로 변환해주어야 함. • htonl(), htons()

  3. show_bytes(unsigned char *, int ); typedefunsignedchar *byte_pointer; voidshow_bytes(byte_pointer start, intlen) { inti; for(i = 0; i < len; i++) printf(" %.2x", start[i]); printf("\n"); } voidshow_int(int x) { show_bytes((byte_pointer) &x, sizeof(int)); } • voidshow_float(float x) • { • show_bytes((byte_pointer) &x, sizeof(float)); • } • voidshow_pointer(void *x) • { • show_bytes((byte_pointer) &x, sizeof(void *)); • } 주소와 byte size를 인자로 받아 byte 별 데이터를 출력. 교재와 슬라이드 참조.

  4. Visual C++에서 Debugging 하기 변수/조사식에서 값 변경하기 메모리 값 찾아가기 함수 수행시Call stack 보기 Disassembly 결과 보기

  5. 리눅스 환경에서 코딩&컴파일 :Array와 Shift 연산을 이용한 변환

  6. 리눅스 시스템에 접속하기 : SSLAB 호스트이름에 주소를 입력하고 창->변환->utf-8로 setting • SSLAB의 리눅스machine에 접속한다. • putty , zterm, xshell등의ssh접속을 지원하는 에뮬레이터 • Host address = 203.252.182.127 ‘ • ID : 각자 학번 • passwordd: 각자 학번  접속후변경하세요. • #passwd //패스워드 변경명령어

  7. htonl()함수를이용한 변환 • // big endian • // htnl() 함수는 네트워크의 바이트 정렬함수입니다. • // 이 함수를 사용하여 little endian을 big endian으로 쉽게 변환합니다 • big_endian = htonl( little_endian ); • memcpy( b, &big_endian, sizeof(int) ); • printf("OX%x%x%x%x \n", b[0], b[1], b[2], b[3] ); // 0x12345678 • return 0; • } #include<stdio.h> #include<string.h> //visual c에서 컴파일할 때 #include<winsock2.h> #pragmacomment(lib, "ws2_32.lib") //linux에서 컴파일할 때 위 두줄 빼교 #include<sys/socket.h> intmain( void ) { unsignedintlittle_endian = 0x12345678; unsignedintbig_endian; char b[4]; // little endian memcpy( b, &little_endian, sizeof(int) ); printf("OX%x%x%x%x \n", b[0], b[1], b[2], b[3] ); // 0x78563412

  8. 리눅스에서 컴파일 후 • Visual 환경에서와 같은 디버깅을하기 위해서는 • 별도의 tool이 필요 -> gdb • 조사해보세요 • gdb란무엇이고 어떻게 사용하는지 • Visual 환경에서처럼 사용하려면 ? • 9월 동안 • *C의 포인터부분에 대한 재학습이 필요한 학생들은 이전 ‘1학기 프프’자료를 참고하세요 • * 기본적인 리눅스 명령어, vi 사용법 익히기

More Related