Introduction
In this assignment, you will implement the packet encoding and decoding for a basic instant messaging pro- tocol. You will be using void pointers and pointer arithmetic, along with functions from string.h to accomplish this. You will learn about pointer arithmetic, raw memory access, and data serialization. This assignment only requires you to encode and decode the outgoing and incoming packets, the rest of the instant messaging application is already implemented for you.
Academic Integrity
As detailed in the course syllabus, academic integrity is important for the value and durability of your degree from the University at Buffalo. Here are a few reminders to help you maintain the integrity of this assignment.
• It is a violation of the course academic integrity policy to share this assignment document or details about this assignment with any student at UB not enrolled in CSE 220 during this academic semester, with any student at any other institution, or with anyone else without permission from your instructor. This includes homework- and note-sharing Internet sites such as Course Hero and Chegg.
• It is a violation of the course academic integrity policy to share any code from this assignment with any student at any time during or after this semester. You may discuss your code with course staff if necessary.
• It is a violation of the course academic integrity policy to seek assistance from other students or any online resource not specifically approved by your instructor. Forbidden resources include: Stack Overflow/Stack Exchange, GitHub/GitLab/BitBucket, students who have previously taken this course, etc.
• It is a violation of the course academic integrity policy to discuss implementation details with anyone except course staff.
Students found violating any of these policies, or any other academic integrity policy in the syllabus, will be sanctioned. Sanctions may include failure in the course or expulsion from the University. Make sure that you are familiar with the course academic integrity policies, as well as the policies of the department and University.
1 Getting Started
You should have received a GitHub Classroom invitation for this project. Follow it and check out the resulting repository.
As always, read over the entirety of this handout before starting the assignment. If you have not yet read Chapter 5 of The C Programming Language by Kernighan & Ritchie, you should also read that before starting. You will speciflcally flnd Sections 5.3, 5.4, and 5.5 to be very helpful.
You should read and understand all of the code in the src directory. You are not expected to read or under- stand any code in the client directory, although you may look at it if you wish.
Man page sections are noted as a number in square brackets after a keyword in this document. For example, memset [3] indicates that the manual page for the memset() function is found in section 3 of the Unix manual, and you can view it with the command man 3 memset.
2 Requirements
In this assignment, you must implement encoding and decoding of packets of data according to the formats specifled below. Each packet is stored internally as a void *, according to a standard format as specifled in Section 3.
Note that the formats in this assignment are very specific, and must be implemented precisely. This in- cludes details such as white space and the value of padding bytes. Be sure not to include any extra characters in quoted strings, insert extra newlines or other formatting, or deviate from this speciflcation in any way!
The standard deflnes several packet types:
• STATUS
This packet type sets your status on the server. It should be sent when the user input starts with “/me” followed by a space. Any input starting with “/me” followed by any other character is invalid.
• LABELED
This packet type tags another user. It is sent when the user input starts with “@” followed by at least one and no more than NAME_SIZE non-space characters. NAME_SIZE is deflned in src/serialize.h.
• STATISTICS
This packet type is used to request and receive a set of basic statistics from the server. It is sent when the user input starts with “/stats” followed by the end of the input. Any input beginning with “/stats” followed by any other character is invalid.
• MESSAGE
This packet type is the most basic, it is just a normal plaintext message. It should be sent if the user input does not fall into any of the above categories.
The standard also deflnes a special packet:
• REFRESH
This packet is sent to the server by the client to request new messages to decode. It is sent every second and has no relation to user input.
Through this assignment, you will implement four functions:
• int pack(void *packed, char *input):
Parse input to determine the packet type and flll packed with the encoded input.
• int pack_refresh(void *packed, int message_id):
Fill packed with an encoded refresh packet according to the speciflcation in Section 3.5.
• int unpack(char *message, void *packed):
Decode packed based on the packet type and flll message with the decoded string.
• int unpack_statistics(struct statistics *statistics, void *packed):
Decode packed according to the STATISTICS format specifled in Section 3.4, fllling statistics with the data.
Any input beginning with “/” that does not include one of the commands deflned above is invalid, but will never be tested. You may use this to implement commands starting with slash for debugging if it is useful to you.
For all functions, the return value should be the integer value of the packet type as deflned in serialize.h, or
-1 for invalid inputs. You should assume that any non-NULL pointer passed to a function is correctly allocated and of an adequate size. Other than that, you should not make any assumptions about the validity of inputs; you are responsible for validating them. This includes unreasonable or meaningless user input as well as malformed data to be unpacked. Some examples of invalid values will be described in Section 3.
3 Packet Formats
This section will describe the format of the different packets in memory. The packets are generally in the form described in the table below.
int char[NAME_SIZE] size_t[] size_t char[]
Packet Type UBIT Name Data Lengths 0 Data
The flrst half of the packet is constant among the different packet types. It starts with an integer storing a value associated with the packet type. This would be one of the packet types described above (REFRESH, MESSAGE, etc.), as deflned in serialize.h. Following this is a character array of exactly NAME_SIZE bytes, which is also deflned in serialize.h. This character array is valid if and only if it contains the sender’s UBIT Name followed by ASCII NUL bytes.
The second half of the packet describes the actual data of the message. The “Data Lengths” fleld is an array of size_t, which varies in length based on the packet type. This list will always have a 0 value terminating it. For each non-zero value in this list, there is an associated string of characters in the “Data” fleld. To give a simple example, if the Data Lengths fleld held the array {2, 5}, and the Data fleld held the string “hihello”, that would signify that there are two strings in the data of sizes two and flve respectively, “hi” and “hello”. The sum of all data lengths must not exceed MAX_MESSAGE_SIZE as deflned in src/serialize.h. Note also that, due to ambiguity with the 0 terminating length value, no valid packet can contain a field of length 0.
Each of the speciflc packet formats follows. All of the speciflc formats other than the STATISTICS and REFRESH
types are implementations of the general format described above.
3.1 Message
int char[NAME_SIZE] size_t size_t char[]
MESSAGE UBIT Name Message Length 0 Message
The message packet is the simplest data-carrying packet, holding only a single data fleld and its length. The data should be the entirety of the message input by the user including any leading or trailing whitespace. So if I were to input “My name is Peter” the encoded message should look like the following:
int char[NAME_SIZE] size_t size_t char[]
MESSAGE “pagottes” 16 0 “My name is Peter”
Note that every character after the “s” in the UBIT Name fleld should be a NUL character, which you should remember has a integer representation of zero.
A message containing only ASCII space characters should not be encoded, and the pack function should instead return invalid.
When decoding this packet, the resulting string should be of the form “UBIT Name: Message”, so the above packet would decode to “pagottes: My name is Peter”. Note that there is both a colon and a space between the UBIT Name and the Message.
3.2 Status
int char[NAME_SIZE] size_t size_t char[]
STATUS UBIT Name Status Length 0 Status
This packet type is very similar to that of the message type; however, the data it contains differs. As previ- ously mentioned, the status packet type is sent when the user input begins with “/me” followed by one or more space characters. When you encode this input you should only send the status itself, not the “/me” or any of the spaces between it and the next non-space character. If the user input was “/me says hi”, the data encoded should be simply “says hi”; this would be the same for a dozen spaces of separation as a single space. Like the message packet type, a status of only spaces should be considered invalid.
A status should be decoded nearly the same as a message, but it should not have a colon, so it would be “UBIT Name Status”. If I were to send a status resulting from the user input “/me says hi”, it would be decoded by a client as “pagottes says hi”.
DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma
Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t
Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th
1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of
1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of