Chapter 2 unp configuration makefile echo program
This presentation is the property of its rightful owner.
Sponsored Links
1 / 35

Chapter 2. UNP configuration, MAKEFILE, Echo program PowerPoint PPT Presentation


  • 76 Views
  • Uploaded on
  • Presentation posted in: General

Chapter 2. UNP configuration, MAKEFILE, Echo program. 2006. 3. 7 백 일 우 [email protected] UNP library (1/2). W. Richard Stevens Solaris, Linux, FreeBSD 등에 설치 가능 Libunp.a, libfree.a, libroute.a, libxti.a 로 구성 ※ XTI [ X/Open Transport Interface ]

Download Presentation

Chapter 2. UNP configuration, MAKEFILE, Echo program

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Chapter 2 unp configuration makefile echo program

Chapter 2.UNP configuration, MAKEFILE, Echo program

2006. 3. 7

백 일 우

[email protected]


Unp library 1 2

UNP library (1/2)

  • W. Richard Stevens

  • Solaris, Linux, FreeBSD 등에 설치 가능

  • Libunp.a,libfree.a, libroute.a, libxti.a로 구성

    ※ XTI [ X/Open Transport Interface ]

    OSI 기본 참조 모델의 제4계층(transport layer)에서의 응용 프로그램 인터페이스(API)에 대한 X/Open의 규정. 이 API를 사용하면 제3계층 이하의 어떤 망 방식을 사용하든 관계없이 망 응용 프로그램을 작성할 수 있다.

  • 사용자가 쉽게 사용할 수 있도록 만든 Wrapper function


Unp library 2 2

UNP library (2/2)

  • 예제

    • 기본함수 정의

    • UNP library에서의 정의

      [page 11]

사용법

#include <sys/types.h>

#include <sys/socket.h>

int socket(int domain, int type, int protocol);

설명 : Socket 은 통신을 위한 종점(endpoint)를 생성하고 디스크립터를 반환한다.

반환값 : 에러시, -1이 반환된다; 그 밖의 반환값은 디스크립터 참조소켓이다.

int Socket(int family, int type, int protocol)

{

int n;

if ( (n = socket(family, type, protocol)) < 0)

err_sys("socket error");

return(n);

}


Unp library install

tar xvfz unpv13e.tar.gz

UNP library - install

  • http://www.unpbook.com/unpv13e.tar.gz

  • 압축해제

    gunzip unpv13e.tar.gz

    tar xvf unpv13e.tar

  • 설치방법

    ./configure # try to figure out all implementation differences

    cd lib # build the basic library that all programs need

    make # use "gmake" everywhere on BSD/OS systems

    cd ../libfree # continue building the basic library

    make

    cd ../libroute # only if your system supports 4.4BSD style routing sockets

    make # only if your system supports 4.4BSD style routing sockets

    cd ../libxti # only if your system supports XTI

    make # only if your system supports XTI

    cd ../intro # build and test a basic client program

    make daytimetcpcli

    ./daytimetcpcli 127.0.0.1


Chapter 2 unp configuration makefile echo program

실습시 주의사항 (1/3)

  • 실습용 서버주소 : amg.hufs.ac.kr

    [Allocation of port numbers]

  • 자신에게 정해진 port만 사용

    • port number: ‘5xxxx’부터 +10까지

      학번 뒤에 4자리

      ex) 학번이 200430128 일때  50128~50138까지


Chapter 2 unp configuration makefile echo program

실습시 주의사항 (2/3)

  • 불필요한 process가 있지 않도록 관리

    • Zombie process

      • process가 종료할 때 parent process에 의해 지워지기 위해 대기중인 상태의 process

      • memory, disk, IO, CPU time 등의 자원은 사용하지 않고, process table의 용량을 차지함

        [process transition diagram for Linux]

      • zombie process의 누적  한계치 수준의 process 생성  system crash


Chapter 2 unp configuration makefile echo program

실습시 주의사항 (3/3)

  • 해결방법

    • ‘ps’명령어로 사용중인 process 확인

    • ‘Kill’명령어로 해당 process 삭제


Hello by using unp

Hello by using UNP

  • You can enjoy UNP libraries, implementing any kinds of programs.

  • Now, Implement “Hello World” on condition as below,

    • Use UNP libraries,..

    • Whatever type of compile, No problem.

      • gcc –o xxxx.c

      • gcc -o Hello xxx.c

    • Should be done in a minute!!!

  • What about Make?

    • What is ‘make’?

    • why should we use it?

      • Advantages

      • Efficiency

      • Easy to read, and fabulous!!


Concept of make

Concept of MAKE

  • Make from ‘man’

    • GNU make utility to maintain groups of programs. The purpose of the make utility is to determine automatically which pieces of a large program need to be recompiled, and issue the commands to recompile them.

  • Necessity

    • Of many files, when we should modify or update some lines, we might have many faults in their relationship

    • If we make make files, we can miss one of them, take useless time to type


Structure basic

io.h

main.c

read.c

write.c

write.o

main.o

read.o

test

Structure - Basic

  • Basic Structure – Example1

    test : main.o read.o write.o

    gcc –o test main.o read.o write.o

    main.o : io.h main.c

    read.o : io.h read.o

    write.o : io.h write.o

    • Note : Must use ‘TAB’ key!!!

TAB


Macro

MACRO

<Example 2>

OBJECTS = main.o read.o write.o

test : $(OBJECTS)

gcc -o test $(OBJECTS) ..........

main.o : io.h main.c

gcc –c main.c All kinds of Shell commands can be used!

read.o : io.h read.c

gcc –c main.c

write.o : io.h write.c

gcc –c main.c

clean :

rm –r $(OBJECTS)

  • Can use ${..}, $(..), $.., but $(..) is recommended

  • Can swap letter OBJECTS with yours


Pre defined macro

Pre-Defined MACRO

  • ‘make –p’, see the rules, macro, environment of make

    • ASFLAGS = ‘as’ Option setting

    • AS = as

    • CFLAGS = ‘gcc’ Option setting

    • CC = cc (= gcc )

    • CPPFLAGS =‘g++’ Option setting

    • CXX = g++

    • LDLFAGS =‘ld’ Option setting

    • LD = ld

    • LFLAGS = ‘lex’ Option setting

    • LEX = lex

    • YFLAGS = ‘yacc’ Option setting

    • YACC = yacc

    • MAKE_COMMAND = make

    • RM = rm -f


Macro1

MACRO

  • Using Previous Predefined MACRO

    OBJECTS = main.o read.o write.o

    SRCS = main.c read.c write.c Not neccesary

    CC = gcc

    CFLAGS = -g –cAdd option : –g

    TARGET = test

    $(TARGET) : $(OBJECTS)

    $(CC) -o $(TARGET) $(OBJECTS)

    clean :

    rm -rf $(OBJECTS) $(TARGET) core

    main.o : io.h main.c

    read.o : io.h read.c

    write.o: io.h write.c


Suffix rule

Suffix Rule

  • Execute reasonable operations according to their Suffixes

    • Command Ex

      .SUFFIXES : .c .o

      OBJECTS = main.o read.o write.o

      SRCS = main.c read.c write.c Not neccesary

      CC = gcc

      CFLAGS = -g –cAdd option : –g

      TARGET = test

      $(TARGET) : $(OBJECTS)

      $(CC) -o $(TARGET) $(OBJECTS)

      .

      .

      % make

      gcc –g –c main.c –o main.o $(CC) $(CFLAGS) –c $< -o $@

      .

      .


Internal macro

Internal MACRO

  • Can’t define or change as you please

    • $* : Target File having No suffix

    • $@ : Current Target File

    • $< : File Updated newly than current Target File (= $?)

      main.o : main.c io.h

      gcc –c $*.cresult : $* => main

      test : $(OBJS)

      gcc –o $@ $S.cresult : $@ = test

      .c.o :

      gcc –c $< (or gcc –c $*.c)

      Result : if update main.c after main.o, main.c will be compiled by ‘$<‘


Macro substitution

Macro Substitution

  • Usage : $(MACRO_NAME : OLD = NEW)

    MY_NAME = Micheal Jackson

    YOUR_NAME = $(MY_NAME : Jack = Jook)

    >Result : Jookson

    OBJS = main.o read.o write.o

    SRCS = $(OBJS : .o = .c)

    >Result : SRCS = main.c read.c write.c

  • In fact, Very comfortable to change 100(File.o into File.c)


Gccmakedep

gccmakedep

  • Check automatically dependencies of Files, and add result to end of Makefile

    .SUFFIXES : .c .o

    CFLAGS = -O2 –g

    OBJS = main.o read.o write.o

    SRCS = $(OBJS : .o = .c)

    test : $(OBJS)

    $(CC) –o test $(OBJS)

    dep :

    gccmakedep $(SRCS)

    % make dep

    % vi Makefile

    # DO NOT DELETE

    main.o: main.c /usr/include/stdio.h /usr/include/features.h \ /usr/include/sys/cdefs.h /usr/include/libio.h \ /usr/include/_G_config.h io.h

    read.o: read.c io.h

    write.o: write.c io.h


Multiple targets

Multiple Targets

<Example>

.SUFFIXES = .c .o

CC = gcc

CFLAGS = -O2 -g

OBJS1 = main.o test1.o Define each Macro!

OBJS2 = main.o test2.o

OBJS3 = main.o test3.o

SRCS = $(OBJS1:.o=.c) $(OBJS2:.o=.c) $(OBJS3:.o=.c)

all : test1 test2 test3

test1 : $(OBJS1)

$(CC) -o test1 $(OBJS1)

test2 : $(OBJS2)

$(CC) -o test2 $(OBJS2)

test3 : $(OBJS3)

$(CC) -o test3 $(OBJS3)

dep : gccmakedep $(SRCS)


Recursive make

Recursive Make

  • For Big Program and Project

    • Want to execute ‘make’ in each folders

      .SUFFIXES = .c .o

      CC = gcc

      CFLAGS = -O2 -g

      all : DataBase Test

      DataBase:

      cd db ; $(MAKE) Move Folder db and execute ‘make’

      Test:

      cd test ; $(Make) Move Folder test and execute ‘make’

      % make

      cd db ; make

      make[1] : Entering directory`/home/raxis/TEST/src'

      gcc -O2 -g -c DBopen.c -o DBopen.o

      gcc -O2 -g -c DBread.c -o DBread.o

      gcc -O2 -g -c DBwrite.c -o DBwrite.o

      make[1] : Leaving directory `/home/windows/TEST/src'

      cd test ; make

      make[1] : Entering directory `/home/raxis/TEST/test'

      gcc -O2 -g -c test.c -o test.o

      make[1] : Leaving directory `/home/windows/TEST/test'


Stop useless compile

Stop useless Compile

  • If modify not to affect other files and any dependency, time waste that try to re-compile

    • Suppose add new line : #define PI 3.14 in header file, surely No side-effect to others and No usage!!

    • At this time, Use Command ‘make –t’

      • Meaning is touch

      • Not compile and just ‘Update_DATE’ is updated newly instead of compile


Tips for make usage

TIPs for Make Usage

  • Favorite Option for Usage

    • -C dir : First of all, Move as direction and do next command

    • -d : Print all of make process information

      • NOTE : Amount is tremendous

    • -f file : treat file as Makefile

    • -h : help

    • -t : touch

    • -v : Show version of Makefile

    • -p : Print internal values set in Makefile

      • Meaning : print_data_base

    • -k : Never stop even if makefile has errors

      • Meaning : keep_going


Make makefile in unp

make – Makefile in UNP

  • Makefile : target, 의존성(dependency), 명령(command)로 이루어진 compile 규칙들의 나열

    • target : 명령(command)이 수행되어서 나온 결과 파일을 지정

    • dependency : dependency를 갖는 파일을 지정

    • command : dependency 부분에 정의된 파일의 내용이 변경되거나 object 부분에 해당하는 파일이 없을 때 이곳에 정의된 것들이 차례대로 실행 (command는 반드시 TAB으로 시작해야함)

target … : dependency …

command


Make unp library makefile 1 2

unpv13e

각 chapter의 source code (ex> intro, select…)

config*.*

lib

libunp.a

libfree

make - UNP library의 Makefile (1/2)

  • UNP library의 directory 구조

    • config*.* : library 설치관련 파일

      ex> config.h, config.h.in, config.log, config.status, configure.in 등

    • libunp.a : UNP library archive 파일

    • lib, libfree : library에서 추가한 함수들의 object 파일


Make unp library makefile 2 2

make - UNP library의 Makefile (2/2)

  • unpv13e/mcast/Makefile


Appendix i

APPENDIX(I)

.SUFFIXES = .c .o

CC = gcc

INC = …-I/home/….Add header files’ Paths which might be included

LIBS = ….Add libraries needed

CFLAGS = -g $(INC) ….Add Options Needed

OBJS = …Object file Names

SRCS = …Source file Names

TARGET = ….Executable file Name : Target File

all : $(TARGET)

$(TARGET) : $(OBJS)

$(CC) -o $@ $(OBJS) $(LIBS)

dep :

gccmakedep $(INC) $(SRCS)

clean :

rm -rf $(OBJS) $(TARGET) core

new :

$(MAKE) clean $(MAKE)


Appendix ii

APPENDIX(II)

  • Errors and Handing

    • Makefile :17: *** missing separator. Stop.

      • Maybe miss letter TAB in 17th line

      • Command line must be started with letter TAB. NOTE!!!

    • Make: *** NO rule to make target ‘io.h’, neede by ‘read.o’. Stop.

      • Problem is dependency. Miss the file io.h

      • Handle : First, find out the file. If not exist, ……….what about ‘make dep’

    • Makefile:10: *** commands commence before first target. Stop.

      • Meaning is as above

      • Handle : If you use ‘\’, Must check whether ‘\’ is end of line or not.

        • ‘\’ Must be end of line, so if you add space letter after ‘\’ carelessly, it cause error without doubt

    • Makefile do nothing, or something strange

      • Makefile think first target is its result file, so if locate something like ‘make clean’ at first target line, makefile do wrong.


Socket address structures

Socket Address Structures

Could be a specific and real example


Echo server client program

Echo Server & Client Program


About tcp

About TCP

  • Features of TCP

    • Transport Layer present on all TCP/IP hosts

    • Provides reliable, unicast, Connection-Oreiented service

    • Adapts sending rate to Network Capacity and Provides fair access

    • Most Internet Traffic still rides over TCP

    • Application Throughput problems may be due to TCP performance(and implementaions) and not the Network

  • RFC 793

    • You can also others about TCP in RFC 793

      • http://www.ietf.org/rfc/rfc0793.txt?number=793


Protocols and api

Protocols and API


Socket programing with tcp

Socket Programing with TCP

Host or Server

Host or Server

Process

Process

Controlled

By application

developer

Controlled

By application

developer

Socket

Socket

TCP with

Buffers,

Variable

TCP with

Buffers,

Variable

Controlled

By operating

system

Internet

Controlled

By operating

system

* Socket is door between the application process and TCP


Socket programing with tcp1

Socket Programing with TCP

  • Client, welcoming socket, and connection socket

Client process

Server process

Three-way handshake

bytes

Client

socket

Connection

socket

bytes


Tcp compare with version c

TCP : Compare with version C

TCP Server

TCP Client

socket()

Passive

Open

bind()

socket()

listen()

Connection

establishment

accept()

Active

Open

connect()

Blocks until

connection from client

(3-way handshake)

write()

read()

Data(request)

write()

read()

Data(reply)

read()

close()

EOF notification

close()


Echo client

Echo Client


Assignment 1 echo server

Assignment #1 : Echo Server

  • Conditions

    • Use UNP libraries

    • Use 2 Linux Servers supported in NP(140, 142)

    • Do it by yourselves


  • Login