Network Programming in C 1 Introduction C 11







































![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_h/1c854fd5535cd1f98db6a23980ff457e/image-40.jpg)





- Slides: 45

Network Programming in C #1: Introduction ネットワークプログラミング C言語 第1回「イントロダクション」 20 11年秋学期 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: Takayoshi Mibe mibe@sfc. wide. ad. jp SA: Yudai Yamagishi yummy@sfc. wide. ad. jp

Class Plan Tuesdays, 3 rd (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 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!)?

今期の授業スケジュール(予定) 第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: 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 32


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

ネットワークアプリケーションとは?(IPv 6) process TCP ICMPv 6 UDP IPv 6 NDP (ICMPv 6) transport layer MLD network layer NDP (ICMPv 6) 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_h/1c854fd5535cd1f98db6a23980ff457e/image-40.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