Getting Familiar with CCN

Size: px
Start display at page:

Download "Getting Familiar with CCN"

Transcription

1 Getting Familiar with CCN 1 Project Goal In this project you will experiment with simple client/server programs in CCN to familiarize yourselves with the CCN basics. You will compile, run, and answer the questions provided later in this document. Note that in order complete this project your will need a laptop with ccnd installed and a route to to the Netsec NDN hub (ndn.netsec.colostate.edu). Some questions, however, can be answered without being connected to the NDN hub. We will provide skeleton code for you, but you will need to make some simple modifications. You should study the code well enough to understand how things work before you make any changes. The topology you will deal with is shown in Fig 1. In that topology, the NDN hub is a separate machine (the NDN hub in the Netsec lab), but everything else will run on your laptop. CCND is the CCN daemon, which you should have installed at the beginning of the class. You will start the daemon with the command ccndstart. You will run two additional servers on your laptop that will register with CCND. Each server will publish its own namespace, as shown in the picture. After publishing the namespaces, CCND should forward all matching interests to these servers following the longest match rule. CCND should also have a route to the the Netsec NDN hub. The NDN hub, which is another CCN node, will also advertise a namespace (see figure). We will configure this for you, you don t have to mess with the NDN hub. Note that once you connect, you should be able to see all the namespaces published in the NDN testbed, from CSU and other universities. You may experiment (e.g., fetching files) with those if you like. The client and server code is attached at the end of this document. You can also download it from the class web page. Note that you will need to modify the code. For example, to observe the effects of caching in CCN you should add delay to the servers returning data in response to interests. This way, data retuerned by a server will be delayed a bit, but data relayed by CCN will not. Make the delay sufficiently different for each server so you can distinquish between them. Each client and server should print a log of all interests/data it receives/serves. After you complete your code changes, install and run the programs, and answer the following questions. 1. Print all routing information and published namespaces. 2. Verify that NDN caches content at each node. You can do this by doing two consecutive requests for the same content and recording the time for each request. 3. Devise a simple experiment to show that caching makes content distribution time almost constant, irrespective of number of clients. 4. Express interest for /local/video/test. Does anything happen for /local/video? Why? 1

2 Figure 1: Topology 5. Verify NDN routes on longest prefix match. This you can do by adding two similar routes, but one is longer that the other. 6. Show that CCN does not forward duplicate interests, but it provides a response to all such interests. 7. Show that all content in CCN must be verifiable to be valid. For this, try to send unsigned content from the servers and observe what happens. Explain what you observe. 2 What to Turn In By the deadline, the instructor a tar file with the following: 1. Source files with your modified client and server programs and a Makefile 2. A README file with your notes, observations and results. Make sure you include the exact commands and parameters you used to run your experiments, the output and the answers to the questions. 3 Implementation Details This section will help you understand the client and server code we have provided to you. 2

3 3.1 The Client The client is a simple program that takes as argument the content name we are interested in. For example, we are interested in a video named /csu/video, we want invoke the client as: $./client /csu/video. The steps involved in the client are: Start by allocating memory for the interest name. The only data structure that is provided by CCN C api is ccn charbuf. struct ccn_charbuf *ccnb = ccn_charbuf_create(); CCNx does not understand plain text names, so you need to create an ccnb-encoded name from the string supplied by user. Also, you need not append ccnx : / at the beginning, the api does that for you. ccn_name_from_uri(ccnb, argv[1]); Create a client handle. We will use this handle for interacting with the CCN daemon. struct ccn *ccn = ccn_create(); Connect to the CCN daemon. ccn_connect(ccn, NULL); Allocate buffers for the result. Also, allocate another buffer for parsed content object. struct ccn_charbuf *resultbuf = ccn_charbuf_create(); struct ccn_parsed_contentobject pcobuf = 0 ; Send out the interest and wait for answer. ccn get by default sends out one interest and wait until it times out. You can pass the time to ccn get. For more advanced functions, you should use ccn express interest and handle the content on your own. int timeout_ms = 6000; ccn_get(ccn, ccnb, NULL, timeout_ms, resultbuf, &pcobuf, NULL, 0); You then wait until the reply comes back or it times out. Once it does, you can parse the answer using ccn content get value. ccn_content_get_value(ptr, length, &pcobuf, &ptr, &length); 3

4 3.2 The Server The server is more complicated. It runs on all the CCN nodes as a daemon. The server starts up and tells CCND that it is interested in all interests starting with some namespace. Once such an interest is received, ccnd forwards it to the server daemon. The server daemon does whatever it wants to do with it, that is for you to define. The steps involved in the server are: Connect to the CCN daemon. Define callback handlers for incoming data or content. Register a prefix with the CCN daemon. This is where we tell the CCN daemon what we are interested in. The CCN daemon will forward everything that matches what we are interested in. We declare a handle for upcalls that allow clients receive notifications of incoming interests and content using ccn closure. in interest is the handle in our case. We also point it to the callback function, incoming interest in our case. struct ccn_closure in_interest =.p = &incoming_interest; in_interest.data = &prefix; ccn_set_interest_filter(ccn, prefix, &in_interest); We then run the server in an infinite loop. ccn_run(ccn, -1); Once we have an interest matching our prefix, we want to handle it appropriately. We need to do this inside enum ccn_upcall_res incoming_interest(struct ccn_closure *selfp, enum ccn_upcall_kind kind, struct ccn_upcall_info *info) There can be various types of events. We will handle caseccn UP CALL INT EREST : for incoming interests. We then need to create a response content, sign it and send it back. ccn sign content. We sign it using ccn_sign_content(h, data, name, &sp, mymessage, size); ccn_put(info->h, data->buf, data->length) 4

5 3.3 Sample Code Client #include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <ccn/ccn.h> #include <ccn/uri.h> #include <ccn/keystore.h> #include <ccn/signing.h> #define DEBUG int main (int argc, char **argv) int res; //check if user supplied uri to trace if(argv[1] == NULL) printf("usage: trace URI\n"); //get the length of user provided URI int argv_length = strlen(argv[1]); //check first six chars for ccnx:/, if present, skip them int skip = 0; res = strncmp("ccnx:/", argv[1], 6); if(res == 0) skip = 5; //if URI does not begins with /, exit if (argv[1][skip]!= / ) printf("uri must begin with /\n"); 5

6 //check if uri ends with slash, append if missing char *slash = ""; if (argv[1][argv_length-1]!= / ) slash = "/"; //allocate memory for trace URI = /trace/user_input/random_number char *URI = (char *) malloc(sizeof(char)* argv_length+1); //find size of rand if(uri == NULL) fprintf(stderr, "Can not allocate memory for URI\n"); //put together the trace URI, add a random number to end of URI srand ((unsigned int)time (NULL)*getpid()); sprintf(uri, "%s%s", argv[1]+skip, slash); //allocate memory for interest struct ccn_charbuf *ccnb = ccn_charbuf_create(); if(ccnb == NULL) fprintf(stderr, "Can not allocate memory for interest\n"); //adding name to interest res = ccn_name_from_uri(ccnb, URI); if(res == -1) fprintf(stderr, "Failed to assign name to interest"); //create the ccn handle struct ccn *ccn = ccn_create(); if(ccn == NULL) fprintf(stderr, "Can not create ccn handle\n"); 6

7 //connect to ccnd res = ccn_connect(ccn, NULL); if (res == -1) fprintf(stderr, "Could not connect to ccnd... exiting\n"); #ifdef DEBUG printf("connected to CCND, return code: %d\n", res); #endif //allocate buffer for response struct ccn_charbuf *resultbuf = ccn_charbuf_create(); if(resultbuf == NULL) fprintf(stderr, "Can not allocate memory for URI\n"); //setting the parameters for ccn_get struct ccn_parsed_contentobject pcobuf = 0 ; int timeout_ms = 6000; //express interest res = ccn_get(ccn, ccnb, NULL, timeout_ms, resultbuf, &pcobuf, NULL, 0); if (res == -1) fprintf(stderr, "Did not receive answer for trace to %s\n", argv[1]); #ifdef DEBUG fprintf(stderr, "Did not receive answer for trace to URI: %s\n", URI); #endif //extract data from the response const unsigned char *ptr; size_t length; ptr = resultbuf->buf; length = resultbuf->length; ccn_content_get_value(ptr, length, &pcobuf, &ptr, &length); //check if received some data if(length == 0) 7

8 fprintf(stderr, "Received empty answer for trace to %s\n", argv[1]); #ifdef DEBUG fprintf(stderr, "Received empty answer for trace to URI: %s\n", URI); #endif //print the data printf("reply: %s\n", ptr); printf("length of data: %Zu\n", length); exit(0); 8

9 3.3.2 Server #include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <errno.h> #include <ccn/ccn.h> #include <ccn/uri.h> #include <ccn/keystore.h> #include <ccn/signing.h> #include <ccn/charbuf.h> #include <ccn/reg_mgmt.h> #include <ccn/ccn_private.h> #include <ccn/ccnd.h> #define DEBUG int construct_trace_response(struct ccn *h, struct ccn_charbuf *data, const unsigned char *interest_msg, const struct ccn_parsed_interest *pi, char *myme //printf("path:construct trace response"); //**this function takes the interest, signs the content and returns to //upcall for further handling //copy the incoming interest name in ccn charbuf struct ccn_charbuf *name = ccn_charbuf_create(); struct ccn_signing_params sp = CCN_SIGNING_PARAMS_INIT; int res; printf("received interest, name length: %d\n", size); res = ccn_charbuf_append(name, interest_msg + pi->offset[ccn_pi_b_name], pi->offset[ccn_pi_e_name] - pi->offset[ccn_pi_b_name]); // printf("%s\n", ccn_charbuf_as_string(name)); if(res == -1) fprintf(stderr, "Can not copy interest name to buffer\n"); //sign the content, check if keystore exsists res = ccn_sign_content(h, data, name, &sp, mymessage, size); 9

10 if(res == -1) fprintf(stderr, "Can not sign content\n"); //free memory and return ccn_charbuf_destroy(&sp.template_ccnb); ccn_charbuf_destroy(&name); return res; enum ccn_upcall_res incoming_interest(struct ccn_closure *selfp, enum ccn_upcall_kind kind, struct ccn_upcall_info *info) //this is the callback function, all interest matching ccnx:/trace //will come here, handle them as appropriate int res = 0; //store the incoming interest name struct ccn_charbuf *data = ccn_charbuf_create(); //check for null, length of incoming interest name //size_t name_length = info->pi->offset[ccn_pi_e_name] - info->pi->offset[ccn_pi_b_name //define answer char *MYMESSAGE="Hello World"; //switch on type of event switch (kind) case CCN_UPCALL_FINAL: return CCN_UPCALL_RESULT_OK; break; case CCN_UPCALL_CONTENT: printf("received content\n"); break; case CCN_UPCALL_INTEREST: 10

11 default: break; return(0); //received matching interest //get the interest name from incoming packet construct_trace_response(info->h, data, info->interest_ccnb, info->pi, MYMESSAGE, s printf("sending binary content of length: %Zu \n", data->length); res = ccn_put(info->h, data->buf, data->length); break; int main(int argc, char **argv) // printf("path:main"); //no argument necessary if(argc!= 1) printf("usage:./server\n"); // for now, look in flags for local vs remote int res; //create ccn handle struct ccn *ccn = NULL; //connect to CCN ccn = ccn_create(); //NOTE:check for null if (ccn_connect(ccn, NULL) == -1) fprintf(stderr, "Could not connect to ccnd"); //create prefix we are interested in, register in FIB struct ccn_charbuf *prefix = ccn_charbuf_create(); //We are interested in anythin starting with ccnx:/ res = ccn_name_from_uri(prefix, "ccnx:/"); 11

12 if (res < 0) fprintf(stderr, "Can not convert name to URI\n"); //handle for upcalls, receive notifications of incoming interests and content. //specify where the reply will go struct ccn_closure in_interest =.p = &incoming_interest; in_interest.data = &prefix; //set the interest filter for prefix we created res = ccn_set_interest_filter(ccn, prefix, &in_interest); if (res < 0) fprintf(stderr, "Failed to register interest (res == %d)\n", res); //listen infinitely res = ccn_run(ccn, -1); //cleanup ccn_destroy(&ccn); ccn_charbuf_destroy(&prefix); exit(0); 12

Programs. Function main. C Refresher. CSCI 4061 Introduction to Operating Systems

Programs. Function main. C Refresher. CSCI 4061 Introduction to Operating Systems Programs CSCI 4061 Introduction to Operating Systems C Program Structure Libraries and header files Compiling and building programs Executing and debugging Instructor: Abhishek Chandra Assume familiarity

More information

ECE 264 Exam 2. 6:30-7:30PM, March 9, You must sign here. Otherwise you will receive a 1-point penalty.

ECE 264 Exam 2. 6:30-7:30PM, March 9, You must sign here. Otherwise you will receive a 1-point penalty. ECE 264 Exam 2 6:30-7:30PM, March 9, 2011 I certify that I will not receive nor provide aid to any other student for this exam. Signature: You must sign here. Otherwise you will receive a 1-point penalty.

More information

Midterm Exam Nov 8th, COMS W3157 Advanced Programming Columbia University Fall Instructor: Jae Woo Lee.

Midterm Exam Nov 8th, COMS W3157 Advanced Programming Columbia University Fall Instructor: Jae Woo Lee. Midterm Exam Nov 8th, 2012 COMS W3157 Advanced Programming Columbia University Fall 2012 Instructor: Jae Woo Lee About this exam: - There are 4 problems totaling 100 points: problem 1: 30 points problem

More information

Project-2 Continued. Subhojeet Mukherjee CSU Database and Security Research Group

Project-2 Continued. Subhojeet Mukherjee CSU Database and Security Research Group Project-2 Continued Subhojeet Mukherjee CSU Database and Security Research Group Storyboard IP: 129.82.34.24 IP: 129.62.14.90 IP: 219.65.74.90 IP: 219.62.21.91 I know what you did last summer from this

More information

CyberSoft Operating Corporation Simple Virus Scanning Protocol (SVSP)

CyberSoft Operating Corporation Simple Virus Scanning Protocol (SVSP) CyberSoft Operating Corporation Simple Virus Scanning Protocol (SVSP) Copyright CyberSoft Operating Corporation, December 28, 2011. This document is based upon the Manual pages delivered with the VSTK

More information

CS Operating Systems Lab 3: UNIX Processes

CS Operating Systems Lab 3: UNIX Processes CS 346 - Operating Systems Lab 3: UNIX Processes Due: February 15 Purpose: In this lab you will become familiar with UNIX processes. In particular you will examine processes with the ps command and terminate

More information

File Descriptors and Piping

File Descriptors and Piping File Descriptors and Piping CSC209: Software Tools and Systems Programming Furkan Alaca & Paul Vrbik University of Toronto Mississauga https://mcs.utm.utoronto.ca/~209/ Week 8 Today s topics File Descriptors

More information

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Information Sciences and Engineering

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Information Sciences and Engineering INTERNAL ASSESSMENT TEST 2 Solutions 1. Explain the working of the waitpid() API with the help of a program. The program needs to take 2 command line arguments: the first argument should be used as the

More information

Dynamic memory allocation

Dynamic memory allocation Dynamic memory allocation outline Memory allocation functions Array allocation Matrix allocation Examples Memory allocation functions (#include ) malloc() Allocates a specified number of bytes

More information

Deep C. Multifile projects Getting it running Data types Typecasting Memory management Pointers. CS-343 Operating Systems

Deep C. Multifile projects Getting it running Data types Typecasting Memory management Pointers. CS-343 Operating Systems Deep C Multifile projects Getting it running Data types Typecasting Memory management Pointers Fabián E. Bustamante, Fall 2004 Multifile Projects Give your project a structure Modularized design Reuse

More information

THE C STANDARD LIBRARY & MAKING YOUR OWN LIBRARY. ISA 563: Fundamentals of Systems Programming

THE C STANDARD LIBRARY & MAKING YOUR OWN LIBRARY. ISA 563: Fundamentals of Systems Programming THE C STANDARD LIBRARY & MAKING YOUR OWN LIBRARY ISA 563: Fundamentals of Systems Programming Announcements Homework 2 posted Homework 1 due in two weeks Typo on HW1 (definition of Fib. Sequence incorrect)

More information

are all acceptable. With the right compiler flags, Java/C++ style comments are also acceptable.

are all acceptable. With the right compiler flags, Java/C++ style comments are also acceptable. CMPS 12M Introduction to Data Structures Lab Lab Assignment 3 The purpose of this lab assignment is to introduce the C programming language, including standard input-output functions, command line arguments,

More information

Exception Namespaces C Interoperability Templates. More C++ David Chisnall. March 17, 2011

Exception Namespaces C Interoperability Templates. More C++ David Chisnall. March 17, 2011 More C++ David Chisnall March 17, 2011 Exceptions A more fashionable goto Provides a second way of sending an error condition up the stack until it can be handled Lets intervening stack frames ignore errors

More information

Armide Documentation. Release Kyle Mayes

Armide Documentation. Release Kyle Mayes Armide Documentation Release 0.3.1 Kyle Mayes December 19, 2014 Contents 1 Introduction 1 1.1 Features.................................................. 1 1.2 License..................................................

More information

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco CS 326 Operating Systems C Programming Greg Benson Department of Computer Science University of San Francisco Why C? Fast (good optimizing compilers) Not too high-level (Java, Python, Lisp) Not too low-level

More information

CSC209H Lecture 3. Dan Zingaro. January 21, 2015

CSC209H Lecture 3. Dan Zingaro. January 21, 2015 CSC209H Lecture 3 Dan Zingaro January 21, 2015 Streams (King 22.1) Stream: source of input or destination for output We access a stream through a file pointer (FILE *) Three streams are available without

More information

CSci 4061 Introduction to Operating Systems. Programs in C/Unix

CSci 4061 Introduction to Operating Systems. Programs in C/Unix CSci 4061 Introduction to Operating Systems Programs in C/Unix Today Basic C programming Follow on to recitation Structure of a C program A C program consists of a collection of C functions, structs, arrays,

More information

C BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ.

C BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ. C BOOTCAMP DAY 2 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh Pointers 2 Pointers Pointers are an address in memory Includes variable addresses,

More information

CS61, Fall 2012 Section 2 Notes

CS61, Fall 2012 Section 2 Notes CS61, Fall 2012 Section 2 Notes (Week of 9/24-9/28) 0. Get source code for section [optional] 1: Variable Duration 2: Memory Errors Common Errors with memory and pointers Valgrind + GDB Common Memory Errors

More information

United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017

United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017 United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017 1. Do a page check: you should have 8 pages including this cover sheet. 2. You have 50 minutes

More information

CpSc 1010, Fall 2014 Lab 10: Command-Line Parameters (Week of 10/27/2014)

CpSc 1010, Fall 2014 Lab 10: Command-Line Parameters (Week of 10/27/2014) CpSc 1010, Fall 2014 Lab 10: Command-Line Parameters (Week of 10/27/2014) Goals Demonstrate proficiency in the use of the switch construct and in processing parameter data passed to a program via the command

More information

When you add a number to a pointer, that number is added, but first it is multiplied by the sizeof the type the pointer points to.

When you add a number to a pointer, that number is added, but first it is multiplied by the sizeof the type the pointer points to. Refresher When you add a number to a pointer, that number is added, but first it is multiplied by the sizeof the type the pointer points to. i.e. char *ptr1 = malloc(1); ptr1 + 1; // adds 1 to pointer

More information

CSE 333 SECTION 3. POSIX I/O Functions

CSE 333 SECTION 3. POSIX I/O Functions CSE 333 SECTION 3 POSIX I/O Functions Administrivia Questions (?) HW1 Due Tonight Exercise 7 due Monday (out later today) POSIX Portable Operating System Interface Family of standards specified by the

More information

Preview. Process Control. What is process? Process identifier The fork() System Call File Sharing Race Condition. COSC350 System Software, Fall

Preview. Process Control. What is process? Process identifier The fork() System Call File Sharing Race Condition. COSC350 System Software, Fall Preview Process Control What is process? Process identifier The fork() System Call File Sharing Race Condition COSC350 System Software, Fall 2015 1 Von Neumann Computer Architecture: An integrated set

More information

CS 0449 Sample Midterm

CS 0449 Sample Midterm Name: CS 0449 Sample Midterm Multiple Choice 1.) Given char *a = Hello ; char *b = World;, which of the following would result in an error? A) strlen(a) B) strcpy(a, b) C) strcmp(a, b) D) strstr(a, b)

More information

Direct Memory Access. Lecture 2 Pointer Revision Command Line Arguments. What happens when we use pointers. Same again with pictures

Direct Memory Access. Lecture 2 Pointer Revision Command Line Arguments. What happens when we use pointers. Same again with pictures Lecture 2 Pointer Revision Command Line Arguments Direct Memory Access C/C++ allows the programmer to obtain the value of the memory address where a variable lives. To do this we need to use a special

More information

Tutorial 1: Introduction to C Computer Architecture and Systems Programming ( )

Tutorial 1: Introduction to C Computer Architecture and Systems Programming ( ) Systems Group Department of Computer Science ETH Zürich Tutorial 1: Introduction to C Computer Architecture and Systems Programming (252-0061-00) Herbstsemester 2012 Goal Quick introduction to C Enough

More information

CS1003: Intro to CS, Summer 2008

CS1003: Intro to CS, Summer 2008 CS1003: Intro to CS, Summer 2008 Lab #07 Instructor: Arezu Moghadam arezu@cs.columbia.edu 6/25/2008 Recap Pointers Structures 1 Pointer Arithmetic (exercise) What do the following return? given > char

More information

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary GATE- 2016-17 Postal Correspondence 1 C-Programming Computer Science & Information Technology (CS) 20 Rank under AIR 100 Postal Correspondence Examination Oriented Theory, Practice Set Key concepts, Analysis

More information

Recitation 2/18/2012

Recitation 2/18/2012 15-213 Recitation 2/18/2012 Announcements Buflab due tomorrow Cachelab out tomorrow Any questions? Outline Cachelab preview Useful C functions for cachelab Cachelab Part 1: you have to create a cache simulator

More information

CPSC 457 Principles of Operating Systems Daniel de Castro Tutorial 16: Program supervision with ptrace Expected Time: minutes March 20, 2012

CPSC 457 Principles of Operating Systems Daniel de Castro Tutorial 16: Program supervision with ptrace Expected Time: minutes March 20, 2012 CPSC 457 Principles of Operating Systems Daniel de Castro Tutorial 16: Program supervision with ptrace Expected Time: 30-40 minutes March 20, 2012 In this exercise, we are going to implement a strace-inspired

More information

Friday, February 10, Lab Notes

Friday, February 10, Lab Notes Friday, February 10, 2017 Lab Notes Topics for today Structures in C Redirection of input and output in a Unix-like environment Command line arguments More pre-processor options Programs: Finish Program

More information

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto Ricardo Rocha Department of Computer Science Faculty of Sciences University of Porto Adapted from the slides Revisões sobre Programação em C, Sérgio Crisóstomo Compilation #include int main()

More information

Figure 1 Ring Structures

Figure 1 Ring Structures CS 460 Lab 10 The Token Ring I Tong Lai Yu ( The materials here are adopted from Practical Unix Programming: A Guide to Concurrency, Communication and Multithreading by Kay Robbins and Steven Robbins.

More information

Introduction to C. Robert Escriva. Cornell CS 4411, August 30, Geared toward programmers

Introduction to C. Robert Escriva. Cornell CS 4411, August 30, Geared toward programmers Introduction to C Geared toward programmers Robert Escriva Slide heritage: Alin Dobra Niranjan Nagarajan Owen Arden Cornell CS 4411, August 30, 2010 1 Why C? 2 A Quick Example 3 Programmer s Responsibilities

More information

JTSK Programming in C II C-Lab II. Lecture 3 & 4

JTSK Programming in C II C-Lab II. Lecture 3 & 4 JTSK-320112 Programming in C II C-Lab II Lecture 3 & 4 Xu (Owen) He Spring 2018 Slides modified from Dr. Kinga Lipskoch Planned Syllabus The C Preprocessor Bit Operations Pointers and Arrays (Dynamically

More information

Functions in C C Programming and Software Tools. N.C. State Department of Computer Science

Functions in C C Programming and Software Tools. N.C. State Department of Computer Science Functions in C C Programming and Software Tools N.C. State Department of Computer Science Functions in C Functions are also called subroutines or procedures One part of a program calls (or invokes the

More information

518 Lecture Notes Week 3

518 Lecture Notes Week 3 518 Lecture Notes Week 3 (Sept. 15, 2014) 1/8 518 Lecture Notes Week 3 1 Topics Process management Process creation with fork() Overlaying an existing process with exec Notes on Lab 3 2 Process management

More information

EL2310 Scientific Programming LAB2: C lab session. Patric Jensfelt, Andrzej Pronobis

EL2310 Scientific Programming LAB2: C lab session. Patric Jensfelt, Andrzej Pronobis EL2310 Scientific Programming LAB2: C lab session Patric Jensfelt, Andrzej Pronobis Chapter 1 Introduction 1.1 Reporting errors As any document, this document is likely to include errors and typos. Please

More information

CSE 333 Midterm Exam July 24, Name UW ID#

CSE 333 Midterm Exam July 24, Name UW ID# Name UW ID# There are 6 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed book, closed notes,

More information

UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4500/8506 Operating Systems Fall Programming Assignment 1 (updated 9/16/2017)

UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4500/8506 Operating Systems Fall Programming Assignment 1 (updated 9/16/2017) UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4500/8506 Operating Systems Fall 2017 Programming Assignment 1 (updated 9/16/2017) Introduction The purpose of this programming assignment is to give you

More information

PRINCIPLES OF OPERATING SYSTEMS

PRINCIPLES OF OPERATING SYSTEMS PRINCIPLES OF OPERATING SYSTEMS Tutorial-1&2: C Review CPSC 457, Spring 2015 May 20-21, 2015 Department of Computer Science, University of Calgary Connecting to your VM Open a terminal (in your linux machine)

More information

CS Basics 14) C: Additional features

CS Basics 14) C: Additional features CS Basics 14) C: Additional features Emmanuel Benoist Fall Term 2016-17 Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 1 Additional Features of C Enumerations

More information

Crit-bit Trees. Adam Langley (Version )

Crit-bit Trees. Adam Langley (Version ) CRITBIT CWEB OUTPUT 1 Crit-bit Trees Adam Langley (agl@imperialviolet.org) (Version 20080926) 1. Introduction This code is taken from Dan Bernstein s qhasm and implements a binary crit-bit (alsa known

More information

Signal Example 1. Signal Example 2

Signal Example 1. Signal Example 2 Signal Example 1 #include #include void ctrl_c_handler(int tmp) { printf("you typed CTL-C, but I don't want to die!\n"); int main(int argc, char* argv[]) { long i; signal(sigint, ctrl_c_handler);

More information

unsigned char memory[] STACK ¼ 0x xC of address space globals function KERNEL code local variables

unsigned char memory[] STACK ¼ 0x xC of address space globals function KERNEL code local variables Graded assignment 0 will be handed out in section Assignment 1 Not that bad Check your work (run it through the compiler) Factorial Program Prints out ENTERING, LEAVING, and other pointers unsigned char

More information

NETWORK AND SYSTEM PROGRAMMING

NETWORK AND SYSTEM PROGRAMMING NETWORK AND SYSTEM PROGRAMMING LAB 09 Network Byte Ordering, inet_aton, inet_addr, inet_ntoa Functions Objectives: To learn byte order conversion To understand inet-aton, inet_addr, inet_ntoa Functions

More information

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University C Programming Notes Dr. Karne Towson University Reference for C http://www.cplusplus.com/reference/ Main Program #include main() printf( Hello ); Comments: /* comment */ //comment 1 Data Types

More information

Good Luck! Marking Guide. APRIL 2014 Final Exam CSC 209H5S

Good Luck! Marking Guide. APRIL 2014 Final Exam CSC 209H5S APRIL 2014 Final Exam CSC 209H5S Last Name: Student #: First Name: Signature: UNIVERSITY OF TORONTO MISSISSAUGA APRIL 2014 FINAL EXAMINATION CSC209H5S System Programming Daniel Zingaro Duration - 3 hours

More information

CSE 333 Autumn 2013 Midterm

CSE 333 Autumn 2013 Midterm CSE 333 Autumn 2013 Midterm Please do not read beyond this cover page until told to start. A question involving what could be either C or C++ is about C, unless it explicitly states that it is about C++.

More information

Software Development With Emacs: The Edit-Compile-Debug Cycle

Software Development With Emacs: The Edit-Compile-Debug Cycle Software Development With Emacs: The Edit-Compile-Debug Cycle Luis Fernandes Department of Electrical and Computer Engineering Ryerson Polytechnic University August 8, 2017 The Emacs editor permits the

More information

Recitation: Cache Lab & C

Recitation: Cache Lab & C 15-213 Recitation: Cache Lab & C Jack Biggs 16 Feb 2015 Agenda Buffer Lab! C Exercises! C Conventions! C Debugging! Version Control! Compilation! Buffer Lab... Is due soon. So maybe do it soon Agenda Buffer

More information

File I/O. Preprocessor Macros

File I/O. Preprocessor Macros Computer Programming File I/O. Preprocessor Macros Marius Minea marius@cs.upt.ro 4 December 2017 Files and streams A file is a data resource on persistent storage (e.g. disk). File contents are typically

More information

Unix-Linux 2. Unix is supposed to leave room in the process table for a superuser process that could be used to kill errant processes.

Unix-Linux 2. Unix is supposed to leave room in the process table for a superuser process that could be used to kill errant processes. Unix-Linux 2 fork( ) system call is successful parent suspended child created fork( ) returns child pid to parent fork( ) returns zero value to child; zero is the pid of the swapper/scheduler process both

More information

Programming Assignment Multi-Threading and Debugging 2

Programming Assignment Multi-Threading and Debugging 2 Programming Assignment Multi-Threading and Debugging 2 Due Date: Friday, June 1 @ 11:59 pm PAMT2 Assignment Overview The purpose of this mini-assignment is to continue your introduction to parallel programming

More information

Kurt Schmidt. October 30, 2018

Kurt Schmidt. October 30, 2018 to Structs Dept. of Computer Science, Drexel University October 30, 2018 Array Objectives to Structs Intended audience: Student who has working knowledge of Python To gain some experience with a statically-typed

More information

PROGRAMMING IN C++ CVIČENÍ

PROGRAMMING IN C++ CVIČENÍ PROGRAMMING IN C++ CVIČENÍ INFORMACE Michal Brabec http://www.ksi.mff.cuni.cz/ http://www.ksi.mff.cuni.cz/~brabec/ brabec@ksi.mff.cuni.cz gmichal.brabec@gmail.com REQUIREMENTS FOR COURSE CREDIT Basic requirements

More information

CSE 333 Midterm Exam Sample Solution 7/28/14

CSE 333 Midterm Exam Sample Solution 7/28/14 Question 1. (20 points) C programming. For this question implement a C function contains that returns 1 (true) if a given C string appears as a substring of another C string starting at a given position.

More information

File Access. FILE * fopen(const char *name, const char * mode);

File Access. FILE * fopen(const char *name, const char * mode); File Access, K&R 7.5 Dealing with named files is surprisingly similar to dealing with stdin and stdout. Start by declaring a "file pointer": FILE *fp; /* See Appendix B1.1, pg. 242 */ header

More information

POSIX Semaphores. Operations on semaphores (taken from the Linux man page)

POSIX Semaphores. Operations on semaphores (taken from the Linux man page) POSIX Semaphores A variable of type sem_t Example Declaration of a semaphore sem_t sem; Operations on semaphores (taken from the Linux man page) int sem_init(sem_t *sem, int pshared, unsigned int value);

More information

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community http://csc.cs.rit.edu History and Evolution of Programming Languages 1. Explain the relationship between machine

More information

Friday, September 16, Lab Notes. Command line arguments More pre-processor options Programs: Finish Program 1, begin Program 2 due next week

Friday, September 16, Lab Notes. Command line arguments More pre-processor options Programs: Finish Program 1, begin Program 2 due next week Friday, September 16, 2016 Lab Notes Topics for today Redirection of input and output Command line arguments More pre-processor options Programs: Finish Program 1, begin Program 2 due next week 1. Redirection

More information

Arrays and Strings. Antonio Carzaniga. February 23, Faculty of Informatics Università della Svizzera italiana Antonio Carzaniga

Arrays and Strings. Antonio Carzaniga. February 23, Faculty of Informatics Università della Svizzera italiana Antonio Carzaniga Arrays and Strings Antonio Carzaniga Faculty of Informatics Università della Svizzera italiana February 23, 2015 Outline General memory model Definition and use of pointers Invalid pointers and common

More information

CSE au Midterm Exam Nov. 2, 2018 Sample Solution

CSE au Midterm Exam Nov. 2, 2018 Sample Solution Question 1. (16 points) Build tools and make. We re building a C++ software back-end prototype for a new food web site. So far, we ve got the following source files with the code for two main programs

More information

Student Number: Instructor: Reid Section: L0101 (10:10-11:00am)

Student Number: Instructor: Reid Section: L0101 (10:10-11:00am) Midterm Test Duration 50 minutes Aids allowed: none Last Name: Student Number: First Name: Instructor: Reid Section: L0101 (10:10-11:00am) Do not turn this page until you have received the signal to start.

More information

1 /* client.c - adapted from code for example client program that uses TCP */ 2 /*Modified by Vincent Chu, Winter

1 /* client.c - adapted from code for example client program that uses TCP */ 2 /*Modified by Vincent Chu, Winter 1 /* client.c - adapted from code for example client program that uses TCP */ 2 /*Modified by Vincent Chu, Winter 2004. 3 http://www.sfu.ca/~vwchu 4 chuvincent (at) gmail (dot) com 5 */ 6 7 #define closesocket

More information

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Data Types Basic Types Enumerated types The type void Derived types

More information

C: Pointers, Arrays, and strings. Department of Computer Science College of Engineering Boise State University. August 25, /36

C: Pointers, Arrays, and strings. Department of Computer Science College of Engineering Boise State University. August 25, /36 Department of Computer Science College of Engineering Boise State University August 25, 2017 1/36 Pointers and Arrays A pointer is a variable that stores the address of another variable. Pointers are similar

More information

LibSysCTr(3) System Call Tracing Library LibSysCTr(3)

LibSysCTr(3) System Call Tracing Library LibSysCTr(3) NAME systr_init_library, systr_cleanup_library, systr_run, systr_stop, systr_trace_syscall, systr_untrace_syscall, systr_get_pid, systr_get_param, systr_set_params, systr_is_entry, systr_pmem_read, systr_pmem_write,

More information

Dynamic memory. EECS 211 Winter 2019

Dynamic memory. EECS 211 Winter 2019 Dynamic memory EECS 211 Winter 2019 2 Initial code setup $ cd eecs211 $ curl $URL211/lec/06dynamic.tgz tar zx $ cd 06dynamic 3 Oops! I made a mistake. In C, the declaration struct circle read_circle();

More information

Application Programming Interfaces

Application Programming Interfaces Application Programming Interfaces Stefan D. Bruda Winter 2018 SYSTEM CALLS Machine 1 Machine 2 Application 1 Application 3 Application 4 Application 5 Application 2 API (system functions) API (system

More information

CSE 333 SECTION 3. POSIX I/O Functions

CSE 333 SECTION 3. POSIX I/O Functions CSE 333 SECTION 3 POSIX I/O Functions Administrivia Questions (?) HW1 Due Tonight HW2 Due Thursday, July 19 th Midterm on Monday, July 23 th 10:50-11:50 in TBD (And regular exercises in between) POSIX

More information

ELEC 377 C Programming Tutorial. ELEC Operating Systems

ELEC 377 C Programming Tutorial. ELEC Operating Systems ELE 377 Programming Tutorial Outline! Short Introduction! History & Memory Model of! ommon Errors I have seen over the years! Work through a linked list example on the board! - uses everything I talk about

More information

TCSS 422: OPERATING SYSTEMS

TCSS 422: OPERATING SYSTEMS TCSS 422: OPERATING SYSTEMS fork() Process API, Limited Direct Execution Wes J. Lloyd Institute of Technology University of Washington - Tacoma Creates a new process - think of a fork in the road Parent

More information

Computer Systems Assignment 2: Fork and Threads Package

Computer Systems Assignment 2: Fork and Threads Package Autumn Term 2018 Distributed Computing Computer Systems Assignment 2: Fork and Threads Package Assigned on: October 5, 2018 Due by: October 12, 2018 1 Understanding fork() and exec() Creating new processes

More information

Section 3: File I/O, JSON, Generics. Meghan Cowan

Section 3: File I/O, JSON, Generics. Meghan Cowan Section 3: File I/O, JSON, Generics Meghan Cowan POSIX Family of standards specified by the IEEE Maintains compatibility across variants of Unix-like OS Defines API and standards for basic I/O: file, terminal

More information

Homework 5. Due Date: Friday, June 7, 2002, at 11:59PM; no late assignments accepted Points: 100

Homework 5. Due Date: Friday, June 7, 2002, at 11:59PM; no late assignments accepted Points: 100 Homework 5 Due Date: Friday, June 7, 2002, at 11:59PM; no late assignments accepted Points: 100 UNIX System 1. (10 points) I want to make the file libprog.a in my home directory available to everyone so

More information

Lab 8. Follow along with your TA as they demo GDB. Make sure you understand all of the commands, how and when to use them.

Lab 8. Follow along with your TA as they demo GDB. Make sure you understand all of the commands, how and when to use them. Lab 8 Each lab will begin with a recap of last lab and a brief demonstration by the TAs for the core concepts examined in this lab. As such, this document will not serve to tell you everything the TAs

More information

CS342 - Spring 2019 Project #3 Synchronization and Deadlocks

CS342 - Spring 2019 Project #3 Synchronization and Deadlocks CS342 - Spring 2019 Project #3 Synchronization and Deadlocks Assigned: April 2, 2019. Due date: April 21, 2019, 23:55. Objectives Practice multi-threaded programming. Practice synchronization: mutex and

More information

Compile and execute fifo1.cpp listed above. Try the Balady's anomaly examples discussed in class. Did you observe the Belady's anomaly?

Compile and execute fifo1.cpp listed above. Try the Balady's anomaly examples discussed in class. Did you observe the Belady's anomaly? Tyler Gaynair Lab9 Score out of 20 Compile and execute fifo1.cpp listed above. Try the Balady's anomaly examples discussed in class. Did you observe the Belady's anomaly? Fifo.cpp code // fifo1.cpp: First

More information

CS 378: Computer Game Technology

CS 378: Computer Game Technology CS 378: Computer Game Technology SDL_net Client-Server Example Spring 2012 University of Texas at Austin CS 378 Game Technology Don Fussell SDL_net TCP Chat Server if ( SDL_Init(0) < 0 ) { fprintf(stderr,

More information

Week 2 Intro to the Shell with Fork, Exec, Wait. Sarah Diesburg Operating Systems CS 3430

Week 2 Intro to the Shell with Fork, Exec, Wait. Sarah Diesburg Operating Systems CS 3430 Week 2 Intro to the Shell with Fork, Exec, Wait Sarah Diesburg Operating Systems CS 3430 1 Why is the Shell Important? Shells provide us with a way to interact with the core system Executes programs on

More information

Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program

Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program Syntax What the Compiler needs to understand your program 1 Pre-Processing Any line that starts with # is a pre-processor directive Pre-processor consumes that entire line Possibly replacing it with other

More information

Memory management. Johan Montelius KTH

Memory management. Johan Montelius KTH Memory management Johan Montelius KTH 2017 1 / 22 C program # include int global = 42; int main ( int argc, char * argv []) { if( argc < 2) return -1; int n = atoi ( argv [1]); int on_stack

More information

Shared Memory Memory mapped files

Shared Memory Memory mapped files Shared Memory Memory mapped files 1 Shared Memory Introduction Creating a Shared Memory Segment Shared Memory Control Shared Memory Operations Using a File as Shared Memory 2 Introduction Shared memory

More information

CS 33. Architecture and the OS. CS33 Intro to Computer Systems XIX 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.

CS 33. Architecture and the OS. CS33 Intro to Computer Systems XIX 1 Copyright 2018 Thomas W. Doeppner. All rights reserved. CS 33 Architecture and the OS CS33 Intro to Computer Systems XIX 1 Copyright 2018 Thomas W. Doeppner. All rights reserved. The Operating System My Program Mary s Program Bob s Program OS CS33 Intro to

More information

UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4500/8506 Operating Systems Summer 2016 Programming Assignment 1 Introduction The purpose of this

UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4500/8506 Operating Systems Summer 2016 Programming Assignment 1 Introduction The purpose of this UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4500/8506 Operating Systems Summer 2016 Programming Assignment 1 Introduction The purpose of this programming assignment is to give you some experience

More information

Introduction to C. Zhiyuan Teo. Cornell CS 4411, August 26, Geared toward programmers

Introduction to C. Zhiyuan Teo. Cornell CS 4411, August 26, Geared toward programmers Introduction to C Geared toward programmers Zhiyuan Teo Slide heritage: Alin Dobra Niranjan Nagarajan Owen Arden Robert Escriva Cornell CS 4411, August 26, 2011 1 Administrative Information 2 Why C? 3

More information

Approximately a Test II CPSC 206

Approximately a Test II CPSC 206 Approximately a Test II CPSC 206 Sometime in history based on Kelly and Pohl Last name, First Name Last 5 digits of ID Write your section number(s): All parts of this exam are required unless plainly and

More information

Lesson 6.1: Structs. This declares a collection of two integer variables to denote the two coordinates of a point in a plane.

Lesson 6.1: Structs. This declares a collection of two integer variables to denote the two coordinates of a point in a plane. Lesson 6.1: Structs Programming in C Prof. Dr. Eike Best Dr. Elke Wilkeit October 12, 2002 1 struct point { 2 int x; 3 int y; 4 }; This declares a collection of two integer variables to denote the two

More information

Crit-bit Trees. Adam Langley (Version )

Crit-bit Trees. Adam Langley (Version ) Crit-bit Trees Adam Langley (agl@imperialviolet.org) (Version 20080926) 1. Introduction This code is taken from Dan Bernstein s qhasm and implements a binary crit-bit (alsa known as PATRICA) tree for NUL

More information

Chapter 14 - Advanced C Topics

Chapter 14 - Advanced C Topics Chapter 14 - Advanced C Topics Outline 14.1 Introduction 14.2 Redirecting Input/Output on UNIX and DOS Systems 14.3 Variable-Length Argument Lists 14.4 Using Command-Line Arguments 14.5 Notes on Compiling

More information

A programmer can create Internet application software without understanding the underlying network technology or communication protocols.

A programmer can create Internet application software without understanding the underlying network technology or communication protocols. CS442 Comer Networking API Chapter 3 Chapter three of the textbook presents an API to perform network programming in the C language. While this chapter does not cover everything about network programming,

More information

Lab 09 - Virtual Memory

Lab 09 - Virtual Memory Lab 09 - Virtual Memory Due: November 19, 2017 at 4:00pm 1 mmapcopy 1 1.1 Introduction 1 1.1.1 A door predicament 1 1.1.2 Concepts and Functions 2 1.2 Assignment 3 1.2.1 mmap copy 3 1.2.2 Tips 3 1.2.3

More information

OPC UA Protocol Stack

OPC UA Protocol Stack Enhanced Universal Realtime Operating System OPC UA Protocol Stack Programming Guide and Reference Document version: 05/2018 EUROS Embedded Systems GmbH Campestraße 12 D-90419 Nuremberg Germany Phone:

More information

CSE 333 Midterm Exam July 24, 2017 Sample Solution

CSE 333 Midterm Exam July 24, 2017 Sample Solution Sample Solution Question 1. (14 points) Making things. Suppose we have the following C header and implementation files, showing the various #include and #if directives in each one: widget.h #ifndef _WIDGET_H_

More information

Lecture 7: Files. opening/closing files reading/writing strings reading/writing numbers (conversion to ASCII) command line arguments

Lecture 7: Files. opening/closing files reading/writing strings reading/writing numbers (conversion to ASCII) command line arguments Lecture 7: Files opening/closing files reading/writing strings reading/writing numbers (conversion to ASCII) command line arguments Lecture 5: Files, I/O 0IGXYVI*MPIW 0 opening/closing files reading/writing

More information

Each line will contain a string ("even" or "odd"), followed by one or more spaces, followed by a nonnegative integer.

Each line will contain a string (even or odd), followed by one or more spaces, followed by a nonnegative integer. Decision-making in C Squeezing Digits out of an Integer Assignment For part of this assignment, you will use very basic C techniques to implement a C function to remove from a given nonnegative integer

More information

Question 1. [15 marks]

Question 1. [15 marks] Note to Students: This file contains sample solutions to the term test together with the marking scheme and comments for each question. Please read the solutions and the marking schemes and comments carefully.

More information

nbtcpfrm: Non Blocking TCP/IP Network Control Program CML

nbtcpfrm: Non Blocking TCP/IP Network Control Program CML nbtcpfrm: Non Blocking TCP/IP Network Control Program CML00053-01 Code Magus Limited (England reg. no. 4024745) Number 6, 69 Woodstock Road Oxford, OX2 6EY, United Kingdom www.codemagus.com Copyright c

More information