Exchanging binary files by email is not quite straightforward because many mail servers were designed to handle text, not binary data. Attempts to send binary files through these servers can result in mangled files. For example, some mail servers might ignore the most significant bit of each byte, since standard ASCII encoding uses only 7 bits. Other mail servers truncate all data beyond the 80th character of each line. In fact, the whole concept of a line is meaningless when we work with binary files. To complicate matters, email is often routed through several servers, so the problem might not be with either the sender's mail server or the receiver's mail server.
The MIME (Multipurpose Internet Mail Exchange) standard defined in Internet RFC 1521 is a comprehensive mechanism for formatting Internet messages. For many people, MIME is synonymous to email attachments. We are interested in just one section of this standard the Base64 Content-Transfer-Encoding that specifies how binary files should be converted into a text file that can be sent intact through most mail servers. The complete specifications of the Base64 standard are (what else) attached at the end of this project description.
Remark: Unlike other organizations (e.g., ANSI, ISO) which publish standards with lofty-sounding titles, the Internet Engineering Task Force's (IETF's) standards are for historical reasons published as Request for Comments (RFCs). Although not all RFCs are standards, the specifications of just about every Internet protocol can be found in an RFC. For more information on RFCs and how they are published, check out http://www.rfc-editor.org.
As a reference standard, we will use the mimencode command on linux.gl.umbc.edu. Using mimencode with the -u option, we can convert the output of your program back to binary. If your program works correctly, the output of mimencode -u should be identical to the original input file. For 15% extra credit, write an assembly language program that reverses the process of your first program. I.e., the second program prompts the user for an input file and an output file. If the input file is a properly formatted text file that conforms to the Base64 standard, your program should store the corresponding binary file in the output file.
int open(const char *pathname, int flags);According to the Linux system call convention, the syscall number for open() should be stored in EAX, a pointer to a null-terminated string with the name of the file to be opened should be stored in EBX and the flag O_RDONLY should be stored in ECX. The return value, stored in EAX, is a file descriptor (a 4-byte integer) that can be used in subsequent syscalls to read(). Further information on open() can be obtained from the Linux man pages. Type 'man 2 open'.
%include "stddefs.mac"
int creat(const char *pathname, mode_t mode);Calling creat() is very similar to calling open(). The difference is that the file is opened for writing and the file is created if it does not already exist. If a file with the same name already exists, it is overwritten. As before, the return value stored in EAX is a file descriptor. The second argument to creat() is used to set the permissions of the newly created file (as in the chmod Unix command). You will most likely want to allow the user to read and write to the file, so store the expression S_IREAD|S_IWRITE in the ECX register. S_IREAD and S_IWRITE are defined in stddefs.mac.
int close(int fd);
Use the UNIX 'submit' command on the GL system to turn in your project. The class name for submit is 'cs313' and the project name is 'project'. Sample runs and a typescript file is not needed for this project. The grader will simply test your program using mimencode and some binary files. Include a README file if your submission needs any special attention.