Network Programming in C 1 Introduction C 10





































![hello. cの例 #include <stdio. h> int main (int argc, char* argv[]) { printf("%sn", "Hello hello. cの例 #include <stdio. h> int main (int argc, char* argv[]) { printf("%sn", "Hello](https://slidetodoc.com/presentation_image_h2/08d8f8b94ec4c91a7c213dd0d8130197/image-38.jpg)





- Slides: 43

Network Programming in C #1: Introduction ネットワークプログラミング C言語 第1回「イントロダクション」 20 10年秋学期 Rodney Van Meter rdv@sfc. wide. ad. jp

Today’s Lecture This course Goals Outline Staff introductions Basics of networking Exercise

Goals Who can take this class? Learn basic structure of network services Programming in C Almost anyone 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


Class Staff Faculty Rodney Van Meter (rdv@sfc. wide. ad. jp) Yoshifuji 吉藤 yoshfuji@wide. ad. jp Assistants TA: Keisuke Muda (muda@sfc. wide. ad. jp) SA: 中島明日香 asp@sfc. wide. ad. jp SA: Kaori Ishizaki: kaori@sfc. wide. ad. jp

Class Plan Tuesdays, 2 nd (11: 10 -12: 40), ε 11 No class 11/23 Only one class in January, for final presentations! You will be on your own for several weeks! 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/11

I Promise: If you work hard, you will learn more in this class than most others here To pass, you will have to work hard! Many SFC classes are about breadth, this one is about depth 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 2 nd 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!)?


Programming Environment CNS Linux: ccx 00, ccx 01 Login via SSH http: //itc. sfc. keio. ac. jp/ssh/ Pu. TTY: http: //www. chiart. greenend. org. up/~sgtathm/ putty/ http: //hp. vector. co. jp/authors/VA 024651/ Pu. TTYkj. html Submit homework via SFS

Programming Environment (2) OK to use your own PC Windows: cygwin 注意:IPv 6は動かないかも IPv 6 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 other Without a protocol, they can’t talk to each other!


OSI Layered Model アプリケーション層 Data プレゼンテーション層 Application Layer セッション層 Presentation Layer トランスポート層 Session Layer Transport Layer Network Layer Data Link Layer Physical Layer Packet Frame Signal ネットワーク層 データリンク層 物理層 ・各プロトコルの関係を階層構造でモデル化

1) Physical Layer Defines physical characteristics Media Signal strength/voltage, how to make numbers, etc. 電波強度、符号変調方式 Optical fiber, copper wire, electrical lines, satellite, radio. . . Usually standardized by some group(ITUT,ISO,…) 規格 X. 25,IEEE,ATM,ISDN… 光)SONET,FDH…


3) Network Layer Independent of physical layer, how two hosts on Internet transfer data End-to-End Path control (routing) IPv 4,IPv 6 Generally requires globally unique address

4) Transport 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


OSI Model & Internet Architecture アプリケーション層 Application Layer プレゼンテーション層 Presentation Layer セッション層 Web XML Webサービス Email NNTP ・・・ Messaging File transfer File sharing TCP UDP Session Layer トランスポート層 Transport Layer ネットワーク層 IP Network Layer データリンク層 Data Link Layer Ethernet 物理層 x. DSL Optical fiber 無線LAN (WLAN) Physical Layer 31


ネットワークアプリケーションとは? process TCP UDP IP ICMP process ARP transport layer IGMP network layer RARP hardware interface media data link layer


Practice Getting started login to CNS via SSH Create “Hello world” program with Makefile “こんなのできるぜ”というたしなみのある人は 帰っていいよ Once this is done, you can go home!


![hello cの例 include stdio h int main int argc char argv printfsn Hello hello. cの例 #include <stdio. h> int main (int argc, char* argv[]) { printf("%sn", "Hello](https://slidetodoc.com/presentation_image_h2/08d8f8b94ec4c91a7c213dd0d8130197/image-38.jpg)
hello. cの例 #include <stdio. h> int main (int argc, char* argv[]) { printf("%sn", "Hello World!"); } #include <stdio. h> main(){ printf(“Hello World!n”); } → gcc hoge. c →. /a. out



Makefileの例 all: program : source 1. o source 2. o gcc -o program source 1. o source 2. o source 1. o : source 1. c gcc -c source 1. c source 2. o : source 2. c gcc -c source 2. c

Makefileの簡素化. cから. oファイルの生成ルール all : source 1. o source 2. o gcc -o program source 1. o source 2. o コンパイルオプションの変数化 <command> %gcc -Wall -g -c source 1. c <Makefile> CFLAGS = -Wall gcc ${CFLAGS} -c source 1. c

Makefile: hello. cへの適用例 all: hello: hello. o gcc -o hello. o: hello. c gcc -c hello. c