network programming in c #1: introduction ネットワークプログラミング c 言語...
DESCRIPTION
20 11 年秋学期 Rodney Van Meter [email protected]. Network Programming in C #1: Introduction ネットワークプログラミング C 言語 第1回「イントロダクション」. Today’s Lecture. This course Goals Outline Staff introductions Basics of networking Exercise. 本講義の位置づけ (2 単位 ). 先端支援系. 創造支援系. 卒業プロジェクト. 創造技法 関連科目 (コンピュータ基礎と - PowerPoint PPT PresentationTRANSCRIPT
Network Programming in C#1: IntroductionネットワークプログラミングC言語第1回「イントロダクション」
20 11年秋学期Rodney Van [email protected]
Today’s Lecture
This course Goals Outline Staff introductions
Basics of networking Exercise
本講義の位置づけ (2単位 )
創造実践 総合講座 先端発見関連科目 (インターネット)
シフト系
リフレッシャー科目
研究会
卒業プロジェクト先端支援系創造支援系
創造融発創造技法
関連科目(コンピュータ基礎とプログラミング)
プログラミングスキル
先端開拓関連科目(インターネットシステム構成法)
先端導入
関連科目(ネットワークアーキテクチャ)(インターネットオペレーション)
Goals Who can take this class?
Almost anyone Learn basic structure of network services Programming in C
Learn some of the “joseki” (定石 ) of C Build experience with programming
Doing is more important than listening! Software engineering in a team
Makefiles, version control, interfaces, modularity, documentation, debugging,
Who’s this for?
Who might want to take this class? Almost anyone working around IT Even if your goal is to be a VC or found an NGO,
understanding this helps you talk intelligently to networking people
Who should take this class? Anyone planning to work in computer
systems (network manager/sysadmin, application or OS developer, researcher)
Prerequisites (前提 ) Minimum
Have taken classes in Information Processing (情報処理 )
「コン基礎」 or 「インターネット」 Helpful
Basics of networks (IP addresses, etc.) Basic programming (editing, compiling,
conditionals, loops, functions) Without this, your learning curve will be steep!
For those with experience, first half of semester might be a little dull...
English!
Lectures will be in English First step in GIGA Program
アイドントスピークイングリシュ! 大丈夫。俺も日本語を話せないから、一緒に頑張ろう!
This class is about doing, not listening Lectures are short, most is hands-on
TA & SAs all speak 日本語 Slides from prior years (and this year!)
available on my web page
この授業の流れ C言語によるプログラミング入門1. システムプログラミング2. ミニプロジェクトのグループ決定3. ネットワーク関連のプログラミング4. ミニプロジェクト成果発表
Class Staff Faculty
Rodney Van Meter ([email protected]) Yoshifuji 吉藤
[email protected] Assistants
TA: Takayoshi Mibe [email protected]
SA: Yudai Yamagishi [email protected]
Class Plan
Tuesdays, 3rd (13:00-14:30), ο11 First 45 minutes or so: lecture Last 45 min.: hands-one work Last 3 weeks, project work only
Hands-on work every week End-of-term presentations: 1/20
I Promise:
If you work hard, you will learn more in this class than most others here Many SFC classes are about breadth, this
one is about depth To pass, you will have to work hard!
Almost every week, you will have to work outside of class
TA, SAs and I are available to help English will be a tool, not a barrier
Term Project and Grading
Homeworks first half of semester Team project 2nd half of semester Your grade depends primarily on
project Team lives & dies together That’s the way it is in life!
Attendance Server
Every week, we will record attendance via the network
Do “by hand” first few weeks, then via program
Protocol simple to start with, more complicated later
Students’ Backgrounds What year? C programming experience? Java programming experience? Classes?
インターネットオペレーション インターネット ネットワークアーキテクチャ システムプログラミング
C Background C programming experience?
Understand edit-compile-debug cycle? What environment (Unix, Windows,
IDE, make)? Functions? Pointers (difficult concept, incredibly
important and useful)? Memory management (hard!)?
今期の授業スケジュール(予定) 第1回 9/30: Hello World! 第2回 10/7: Loops and control flow 第3回 10/14: Data structure and pointers 第4回 10/21: Pointers and Memory Management 第5回 10/28 : File I/O 第6回 11/4: IP Networking Basics 第7回 11/11: Basic Socket Programming 1 第8回 11/25: Basic Socket Programming 2 第9回 12/2: Naming: DNS Requests 第10回 12/9: RPC: Remote Procedure Calls 第11回 12/16: Project Programming 1 第1 2 回 1/6: Project Programming 2 第13回 1/13: Project Programming 3 第1 4 回 1/20: Project Demonstration
Programming Environment
CNS Linux:ccx00,ccx01
Login via SSH http://itc.sfc.keio.ac.jp/ssh/ PuTTY:
http://www.chiart.greenend.org.up/~sgtathm/putty/
http://hp.vector.co.jp/authors/VA024651/PuTTYkj.html
Submit homework via SFS
Programming Environment (2)
OK to use your own PC Windows: cygwin
注意: IPv6は動かないかも IPv6 important in this class,
cygwin support still weak? Linux, BSD, Mac: native environment
ここから本編~ネットワークの基礎
Basics of Network Architecture
Protocols Layered protocol model What’s a network application?
Protocol
In order for two computers to talk, they have to share a language and follow a set of rules: a protocol is what they promise each otherWithout a protocol, they can’t talk to each
other!
Humans Use Protocols
One speaking English, the other Japanese (probably) doesn’t work
On phone, start with 「もしもし, xx です」 or “Hello”
Same for computersUNIX-Windows間の通信無線 -有線間の通信
1) 受話器を上げる
2) 電話番号を入力
3) 着信を通知する4) 受話器を上げる
5) 会話する6) どちらかが受話器を置く
7) 回線が切れる
電話の例
OSI Layered Model
Physical Layer
Data Link Layer
Network Layer
Transport Layer
Session Layer
Presentation Layer
Application Layer
物理層
データリンク層
ネットワーク層
トランスポート層
セッション層
プレゼンテーション層
アプリケーション層
Signal
Frame
Packet
Data
・各プロトコルの関係を階層構造でモデル化
1) Physical Layer Defines physical characteristics
Signal strength/voltage, how to make numbers, etc. 電波強度、符号変調方式
Media Optical fiber, copper wire, electrical lines,
satellite, radio... Usually standardized by some group( ITU-
T, ISO …, ) 規格
X.25, IEEE, ATM, ISDN… 光) SONET, FDH…
Data Link Layer 物理的な通信媒体に対応した、フレームをやり取りするためのプロトコルを規定する層
同期,送信権の制御 CSMA/CD
識別 MAC Address
誤り検出 CRC Checksum
3) Network Layer
Independent of physical layer, how two hosts on Internet transfer data End-to-End
Path control (routing) IPv4, IPv6 Generally requires globally unique
address
4) Transport Layer
Layer that processes in a host usually use
TCP, UDP Most protocols divide service by PORT
5) Session Layer
One “session” – start to finish of communication between two apps Cooperatively managed between sender
and receiver Generally handled by applications
Most Internet apps one “session” is one transport-level connection
6) Presentation Layer
セッションでやり取りされるデータの表現方法や符号化、暗号化などを規定する層
Byte Order (“Endianness”) Least/Most Significant Bit (LSB/MSB) Htonl(), Htons()
Usually handled by applications
7) Application Layer
Agreed upon by two applications e.g., what Email contents look like
(headers, etc.)
Most applications handle layers 5 and up themselves
ネットワーク層Network Layer
データリンク層Data Link Layer
物理層Physical Layer
Internet Layered Model
エンドノード 中継ノード エンドノード
送信元から中継ノード (ルータ )を通ってあて先に到達する
アプリケーション層
Application Layer
トランスポート層Transport Layer
ネットワーク層Network Layer
データリンク層Data Link Layer
物理層Physical Layer
アプリケーション層
Application Layer
トランスポート層Transport Layer
ネットワーク層Network Layer
データリンク層Data Link Layer
物理層Physical Layer
アプリケーション層Application Layer
プレゼンテーション層Presentation Layer
セッション層Session Layer
トランスポート層Transport Layer
ネットワーク層Network Layer
データリンク層Data Link Layer
物理層Physical Layer
OSI Model & Internet Architecture
32
WebXML Webサービス
EmailNNTP・・・
WebXML Webサービス
EmailNNTP・・・
MessagingFile transferFile sharing
MessagingFile transferFile sharing
TCPTCP UDPUDP
IPIP
EthernetEthernet xDSLOptical fiber
xDSLOptical fiber
無線 LAN (WLAN)無線 LAN (WLAN)
アプリケーション
TCP
IP
Ethernet/100M
CAT5e
アプリケーション
TCP
IP
Ethernet/100M
CAT5e
データデータ
例: HTTPヘッダ
プロトコルスタックとカプセル化
TCPヘッダ
IPヘッダ
信号へ
送信側 受信側
送信側 各層がそれぞれ必要な情報(ヘッダ)を付加して下層へ渡す
受信側各層はヘッダの情報をもとに処理を行い,そのヘッダ部分を取り除いて上層へ渡す
Ethernet Frame
データデータ
ネットワークアプリケーションとは?
ARP
hardwareinterface
RARP
media
IPICMP IGMP
TCP UDP
networklayer
data linklayer
transportlayer
process process process process
ネットワークアプリケーションとは?(IPv6)
NDP(ICMPv6)
hardwareinterface
NDP(ICMPv6)
media
IPv6ICMPv6 MLD
TCP UDP
networklayer
data linklayer
transportlayer
process process process process
ここから実習~C言語に触れてみる
Practice
Getting started login to CNS via SSH Create “Hello world” program
with Makefile
“ ”こんなのできるぜ というたしなみのある人は帰っていいよ
Once this is done, you can go home!
今日の環境 CNS環境
Linux:ccx00,ccx01
sshして上記のホストにログイン http://itc.sfc.keio.ac.jp/ssh/ PuTTY:
自分のホームディレクトリにファイルを置く
はろーわーるど ???.c というファイル名 gccコマンド include printf a.outなどのおまじないを体験してみる
hello.cの例#include <stdio.h>int main (int argc, char* argv[]) { printf("%s\n", "Hello World!");}
#include <stdio.h>main(){ printf(“Hello World!\n”);}
→ gcc hoge.c→ ./a.out
Compiling
gcc hoge.c a.outというファイルが生成される
または gcc –o hoge hoge.c
hogeというファイルが生成される
Makefile
再コンパイルの煩雑さを解消 コンパイル時は make と打つだけ
基本文法ターゲット : 依存するファイル<tab>コマンド
Makefileの例all: program
program : source1.o source2.ogcc -o program source1.o source2.o
source1.o : source1.cgcc -c source1.c
source2.o : source2.cgcc -c source2.c
Makefileの簡素化 .cから .oファイルの生成ルールall : source1.o source2.o
gcc -o program source1.o source2.o
コンパイルオプションの変数化<command>%gcc -Wall -g -c source1.c<Makefile>CFLAGS = -Wallgcc ${CFLAGS} -c source1.c
Makefile: hello.cへの適用例
all: hello
hello: hello.ogcc -o hello hello.o
hello.o: hello.cgcc -c hello.c