CIS 452 Program 1

CIS 452 Program 1

Overview

This assignment is a "warm-up" exercise.  Its purpose is to gain experience with interpreting man pages, with reading and understanding function prototypes, with using system calls and C library functions, and with using UNIX programming utilities and development tools.  To help with this process you will develop a small program that uses the termios library. 
Activities

Write a small program (specified below) that uses library calls to implement the specified functionality.

This programming project is an individual assignment (i.e. you must each write your own code).  

Submit your well-documented source code along with a sample run.  Please use professional documentation and presentation standards as learned in introductory programming courses.

Be prepared to demonstrate your program.

 

Programming Assignment (No Echo)

All UNIX systems contain a terminal interface for enabling interactive communication between a user (presumably using a terminal-type device such as the console or an xterm) and the kernel.  The POSIX standard defines such an interface, called termios (terminal input/output system).  Like many APIs (application programming interfaces), termios consists of internally maintained status data and a set of functions that access that data.  Note that in most APIs, functions that return information usually contain the word "get" in their name and those that modify data structures generally contain a "set".

By using the function calls associated with the termios API, a program can query a terminal to determine its present state and change the terminal's behavior by modifying the termios data structures.  As is often the case, the internal data structures maintain a notion of state in the form of flags; the flag bits are then queried for information return or manipulated to control the behavior of the terminal.  For example, a termios function can query the system to determine the terminal control mode.  Another function can be used to modify the system to map all input to lowercase.  This mechanism can be used to control many useful features of an input/output device.

Your assignment is to write a simple program that accepts user input without echoing it back to the terminal.  This would be advisable, for example, when asking a user to enter a password or passphrase.  In particular, your program should:

obtain and store the default (currrent) terminal parameters

modify the current terminal behavior to turn off terminal echo

input a word or phrase (i.e. the password/passphrase)

output the data the user entered

restore default terminal behavior

Here is what a sample run might look like:

[eos02:~/cs452]$ program_01

Disabling echo.
Enter secret word/phrase:
You entered: secret

Default behavior restored.
Enter visible word/phrase: visible

[eos02:~/cs452]$

To successfully complete this assignment, you will need to review or learn about:

basic terminal input/output (e.g. file descriptors, I/O functions)

using library functions (i.e. understanding function prototypes)

accessing system data structures

flags, masks, bit manipulations (e.g. |, &)
Powered by