Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Purpose Exercise the socket, bind, sendto and recvfrom system calls. Assignment

ID: 3568023 • Letter: P

Question

Purpose

Exercise the socket, bind, sendto and recvfrom system calls.

Assignment

Write a C++ program that validates credit card transaction information by querying a UDP server.

Program

Implement a C++ program that prompts the user for credit card transaction detail: name of the card holder, credit card number, expiration date
and the amount to be authorized. The card holder name is a string, the card number is a 15 or 16 digit number, the expiration date is of the form
mm/yyyy (e.g. 12/2014), and the amount is a number with 2 digits after the decimal point. Your program will send the information to a UDP
server in a single datagram. The server will respond with a single datagram. The response contains whether the credit card transaction is valid,
and an authorization code. Display the server's response to the user as is. Then the whole dialog will repeat. Execution will stop when "quit" is
entered as the card holder name.

The UDP datagram sent to the server must contain the card number, expiration date, amount and card holder name in a colon separated list of
words, ex.: "6011 1234 4321 1234:12/2016:543.21:John Doe".
UDP Server Detail
For this assignment 2 UDP servers are running to help you test your program: one on blitz.cs.niu.edu, and one on
hopper.cs.niu.edu. Both servers accept incoming datagrams on port 9045.
Note that the server on hopper is only reachable from progams running on turing or hopper.
The server on blitz is reachable from the Internet but not from turing or hopper.

Error Checking
Check whether the name, credit card, expiration date and amount are well formed: if not re-prompt the user.
Name can be any string less than 64 characters. Credit card number is 15 or 16 digits, spaces are allowed to group numbers. Expiration date is
of the form mm/yyyy. Amount is of the form digits followed by a decimal point and 2 more digits.

Example Run

% ./z123456.udp
Welcome to the Credit Card transaction verification utility:
Enter card holder name (or quit): John Doe
Enter CC number: 3724 531039 23000
Enter expiration: 10/2016
Enter amount: 12.00
Wed Nov 14 10:34:05 CST 2012: American Express: 3715 199624 21012 is valid: authorization code: 198806 for $12.00
Enter card holder name (or quit): Susan Maloney
Enter CC number: 6011 1234 4321 1234
Enter expiration: 12/16
... expiration date invalid, try again: 12/2014
Enter amount: 1234.56
Wed Nov 14 10:35:45 CST 2012: Discover: 6011 1234 4321 1234 is valid: authorization code: 386489 for $1234.56
Enter card holder name (or quit): Manny Diaz
Enter CC number: 6011432112344321
Enter expiration: 01/2018
Enter amount: forty
... amount invalid, try again: 44
... amount invalid, try again: 44.44
Wed Nov 14 10:36:33 CST 2012: Discover: 6011432112344321: checksum incorrect
Enter card holder name (or quit): quit
%

Hints

you can assume that user input is less than 64 characters long
if any of the UDP system calls fail, call perror and exit the program

Explanation / Answer

I think I am almost done but one of my perrors is going off when trying to send the info to the server.

The perror is

.

These are the functions I made to help get user input

how to solve the error :::

I tried to receive 64 bytes but checking the return value against echolen. The value in echolen is the length message which may not be exactly 64 bytes. I was not checking all possible conditions returned by recvfrom. If it returns 0 the connection was closed by the other side, if it returns -1 an error occurred and any other value is the number of bytes received.

Be aware datagram socket are message based. If you try to read 64 bytes and the length of the message is bigger all unread bytes in the datagram will be discarded

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote