Out: Sept 5, 2017
Due: Sept 12, 2017 (Start of Lab)
This assignment’s weight is 50% of a regular assignment.
5% penalty later the same day, 10% per day
CENG320 Lab 1
Part I: strace and ltrace (8 marks/2 each)
The Unix commands ltrace and strace trace, demonstrated in class on Sept 5, track regular library calls and system call respectively.
ltrace programName 2> /dev/pts/nnn #where nnn is the device # of a 2nd terminal window
strace programName 2>/dev/pts/nnn
The purpose of these exercises is to give you some practice in tracing and interpreting the trace of system and regular library calls. These questions are fairly easy – all you have to do is run The following cmd line option flags may prove useful:
-p pid / -p pid / Attach to a running process
-c / -c / Summarize/count the # of time each function is called
-h / -h / Print help
-o file / -o file / Send the trace output to a file
Note that the standard output goes to stderr. You could also redirect the trace output to another terminal
exec 2>/dev/pts/21
-T / -T / Lists in > estimated time spend in each function call
-t, -tt, -ttt / -t, -tt, -ttt / Lists when each function was called. -tt most useful
-e fn1,!f2 / Lists functions to trace. !function means exclude this function
-S / Add system calls
-n # / Indent nested calls # spaces per level
-e trace=option / Option could be: file, process, network, signal , ipc
Can combine: -e trace=!file,network,signal.ipc
Enables/disables tracing on a given class of function
For each of the following you may use short programs that you’ve previously written or one of the example programs from CENG251 (
1)Find a program uses fprintf and fscanf. Use the ltrace options -S and -n to determine which system functions are called by each. (2 marks)
2)Find a program that uses readdir. What system functions does readdir use? Use man and summarize in your own words its arguments and what it does. (2)
3)Find a program that uses signals. Use strace to filter out only signal related system calls. Send a signal to the program. Record the command used and list the function calls. (2)
4)Note the process id of the your bash shell. Open up a 2nd terminal window and use the -p option of both ltrace and strace to attach to the shell in the 1st window and type in a command. Record the commands you used. In a paragraph summarize what kinds of functions bash is using to read and interpret the command.
Part II: Smaller functions (12 marks)
1)In class on Sept 5th we looked at the functions htonl; and ntohl which transformed long integers from host to network byte order in the program endianDemo.c Add the following field to the overlay datastructure: short shortInts[4];
Use the function calls htons and ntohs to display the short ints and then transform them into network byte order. Hand in the code, the output and a short description of what happened. Is the result the same as when the long ints were manipulated? (2 marks)
2)The functions getservbyname, getservbyport along with getservent, setservent and endservent are designed to read the /etc/services file in the same style as getpwnam, getpwdid and getpwent, setpwent and endpwent process /etc/passwd. It’s also similar to how the file /etc/groups is handled.
Refer to the man pages on getservent and
a)Draw a full data structure diagram for the servent data structure including labelled boxes for each of the items that the pointers point to. (2 marks)
b)Using the sample programs from and groups.c as a basis, write a C program that uses getservent to print out the full contents of the /etc/services file in a similar format. You won’t be able to retrieve the comments.
Hand in a program listing and a 6-8 line sample of the output with a status report (3 marks)
3)Create a file consisting of a list domain names, some of which should have ip6 addresses. Most of the domain names listed here should have at least some ip6 addresses – please use a random sample from beyond the 1st page to create your list.
The program you are to write should work with an indefinitely long list of such names, but 8-12 names will do. (5 marks)
Modify the main loop of the program getaddrinfo to do the following:
a)Write a version of this loop that
i)verifies that each ip address name does have all 3 socket types
ii)Reports the number of different ip addresses
iii)counts and reports the number of ipv4 and the number of ipv6 addresses and reports whether the domain name is purely ipv4, purely ipv6 or mixed.
iv)Hand in:
(1)your list of domain names (your test data)
(2)program listing
(3)sample output listing
(4)status report of program