This code tests the ability to add up 4 unsigned 32-bit integers. Hint: Keep in mind that it wraps. (link)
Source Code:
This ones a bit more complicated than net0 and net1, but overall very similar.
Your job is to read 4 32-bit little-endian integers, add them up, and send them back.
I wrote a quick python script that does it:
#!/usr/bin/env python
#
import socket
import struct
HOST = "127.0.0.1"
PORT = 2997
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
total = 0
for i in range(4):
val = int(struct.unpack("I", s.recv(4))[0])
total += val
print val
total &= 0xffffffff
to_send = struct.pack("I", total) + "\n"
print to_send
s.sendall(to_send)
print "sending:", to_send
print "response:", s.recv(1024)
Running it gives the following output:
user@protostar:/opt/protostar/bin$ python /tmp/net2.py
1642506226
1314001069
1294629977
29888033
C+?
sending: C+?
response: you added them correctly
No comments:
Post a Comment