Packing of verilog_struct

Hi, I am facing the issue when i want to pack the ethernet packet fields by using verilog_struct.pack() method.

Error I am pasting below:
Traceback (most recent call last):
File “pcap_extract.py”, line 42, in
verilog_data = verilog_struct.pack(*ip_fields)
struct.error: pack expected 1 items for packing (got 2)

My code is:
from struct import *
fields =
verilog_struct = struct.Struct(“>6s6s”)

for pkt in ins:
print(pkt.fields)
ip_fields = (pkt.src,pkt.dst)
verilog_data = verilog_struct.pack(*ip_fields)
fields.append(verilog_data)

Please let me know, where is the issue in my code?

The Traceback is telling you what and where the error is:

verilog_data = verilog_struct.pack(*ip_fields)
struct.error: pack expected 1 items for packing (got 2)

Looking at your code, you have:

ip_fields = (pkt.src,pkt.dst)
verilog_data = verilog_struct.pack(*ip_fields)

So, ip_fields is a <class 'tuple'>, which is holding two values, hence the struct.error

All the * is doing, is to iterate over the ip_fields, returning the two values.

As a demonstration:

v_input = "this is the input"

print(*v_input)
output
t h i s   i s   t h e   i n p u t

Thanks Rob. Issue is fixed by the below code.

ip_fields = (pkt.src,pkt.dst)
fields.append(ip_fields)
with open(‘packet_fields.v’,‘w’) as f:
for data in fields:
f.write(str(data))

Now, the issue is generated packet_fields.v file data is dumping like this:
[(‘ca:03:0d:b4:00:1c’, ‘ff:ff:ff:ff:ff:ff’), (‘ca:03:0d:b4:00:1c’, ‘ff:ff:ff:ff:ff:ff’)]

I want this data to be printed like this
48’hca030db4001c
48’hffffffffff like this i want to print in the file
How can i do this in python?

You’re welcome.

The list of tuples can be unpacked with a nested loop, but I’m not sure what 48’hca030db4001c means. I can see (what looks like) a MAC Address ca:03:0d:b4:00:1c in there, but I don’t know enough about the topic to advise. There are others here that have a far better understanding of this than I, so maybe you’ll get an answer, given time.