array problems.. OverflowError

A

ashtonn

How do i fill 1 byte and 4 bytes in a single array? This array contains
packet information.

Python code...

from array import *

size = 526
pData = array("B", '\0'* 526)
# Destination MAC address
destAddress = FFFFFFFFFFFF
for i in range(0, len(destAddress), 2):
pData[i/2] = int(destAddress[i:i+2], 16)

pattern = 0xAAAAAAAA
for i in range( 512):
pData[i+6] = long(pattern, 16)
print pData

OverflowError: long int too large to covert to int

def test(pData.buffer_info()[0])
....
....
Any help appreciated.
-Ashton
 
C

Chris Lambacher

You probably want to look at using struct.pack. That will allow you
to back heterogenious groups of data into a string that can be saved
to disk or sent over the network. It also does a really good job of
taking care of byte order for you(if you tell it to).

-Chris

How do i fill 1 byte and 4 bytes in a single array? This array contains
packet information.

Python code...

from array import *

size = 526
pData = array("B", '\0'* 526)
# Destination MAC address
destAddress = FFFFFFFFFFFF
for i in range(0, len(destAddress), 2):
pData[i/2] = int(destAddress[i:i+2], 16)

pattern = 0xAAAAAAAA
for i in range( 512):
pData[i+6] = long(pattern, 16)
print pData

OverflowError: long int too large to covert to int

def test(pData.buffer_info()[0])
....
....
Any help appreciated.
-Ashton
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,240
Messages
2,571,205
Members
47,843
Latest member
eicamotu

Latest Threads

Top