473,586 Members | 2,555 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A starter needs help with struct.pack() and "".join()

7 New Member
Basically i'm trying to form a mac packet.

1. a simple mac header is generated using struct.pack('!H H', desti_mac, src_mac)

2. the packet is created using ''.join(header, .....)

Could anyone explain what pack and join really do, and suggest a way of retrieving header part(for retrieving desti_mac and src_mac purpose) from received packet(demodula ted, let's assume it's same as the string created by join)

Also, with a bit of luck, does anyone know where the ip interface/socket of GNU radio is? :)

Another one. I've tolde from all the place that list.delete_hea d() removes the first element. but no one would tell me what this function returns, does it return the removed first element?

Thanks a lot
May 23 '07 #1
9 4396
Motoma
3,237 Recognized Expert Specialist
Basically i'm trying to form a mac packet.

1. a simple mac header is generated using struct.pack('!H H', desti_mac, src_mac)

2. the packet is created using ''.join(header, .....)

Could anyone explain what pack and join really do, and suggest a way of retrieving header part(for retrieving desti_mac and src_mac purpose) from received packet(demodula ted, let's assume it's same as the string created by join)

Also, with a bit of luck, does anyone know where the ip interface/socket of GNU radio is? :)

Another one. I've tolde from all the place that list.delete_hea d() removes the first element. but no one would tell me what this function returns, does it return the removed first element?

Thanks a lot
There are a lot of very specific questions. Care to elaborate on what you are trying to do/accomplish?
May 23 '07 #2
zhangbo2050
7 New Member
There are a lot of very specific questions. Care to elaborate on what you are trying to do/accomplish?


I'm just wandering after several 'struct.pack'ed objects are 'join'ed together, how can i retrieve the first 'pack' from the string generated by 'join'

I'm currently working on modifying GNU radio. the default packet format doesn't have mac header, so i'm trying to add a simple mac header(just include desti and src mac addresses) to it, it's seems fine to add mac addresses when sending packet, but i can't find a way to retrieve those mac addresses on receiving a packet

Also, in order to involve ip address when assigning mac address, i need to find a ip interface in GNU radio so i can retrieve ip address(which is assigned by e.g. 'ifconfig gr0 192.168.200.1') . at least i should know where GNU radio stores this ip address
May 23 '07 #3
Motoma
3,237 Recognized Expert Specialist
A quick synopsis on pack and unpack.

Try using unpack("!HHs", packetstring)

Also, with a bit of luck, does anyone know where the ip interface/socket of GNU radio is? :)
I'm not quite sure what you are asking...Could you rephrase the question?

delete_head returns nothing.
May 23 '07 #4
Motoma
3,237 Recognized Expert Specialist
I'm just wandering after several 'struct.pack'ed objects are 'join'ed together, how can i retrieve the first 'pack' from the string generated by 'join'

I'm currently working on modifying GNU radio. the default packet format doesn't have mac header, so i'm trying to add a simple mac header(just include desti and src mac addresses) to it, it's seems fine to add mac addresses when sending packet, but i can't find a way to retrieve those mac addresses on receiving a packet

Also, in order to involve ip address when assigning mac address, i need to find a ip interface in GNU radio so i can retrieve ip address(which is assigned by e.g. 'ifconfig gr0 192.168.200.1') . at least i should know where GNU radio stores this ip address

What part of GNU Radio are you modifying? What part of it uses IP? I am almost entirely unfamiliar with GNU Radio, as you can see. Have you tried posting to the GNU Radio boards? I am sure they would love to help with your modification/port/addon/plugin/mess.
May 23 '07 #5
zhangbo2050
7 New Member
Thanks for your reply guys.

Let's not worry about the IP address for now.

There are two lines of code in GNU radio as below:

msg = self.rcvd_pktq. delete_head()
ok, payload = packet_utils.un make_packet(msg .to_string())

rcvd_pktq seems like a msg queue held by physical layer. I'm wandering what 'msg' could be. is it the first packet of the entire queue?
May 23 '07 #6
zhangbo2050
7 New Member
And for the pack problem. I constructed a mac header using the function below:

def make_mac_header (desti_mac, src_mac):
# Upper 12 bits is destination mac, lower 12 bits is source mac
val = ((desti_mac & 0xf) << 12) | (src_mac & 0x0fff)
#print "desti_mac =", desti_mac, " src_mac =", src_mac, " val=", val
return struct.pack('!H H', (desti_mac & 0xf) << 12, src_mac & 0xfff)

And later I generate a packet using:

pkt = ''.join((make_m ac_header(desti _mac, src_mac), packed_preamble , packed_access_c ode, make_header(L, whitener_offset ), (payload_with_c rc), '\x55'))

As I understand, join will produce a string using whatever char in front of '.join()' as delimiter. Now suppose we received a pkt in string, it's sure that first part is gona be "make_mac_heade r()", but how can i split it out from the packet and retrieve desti_mac and src_mac?
May 23 '07 #7
Motoma
3,237 Recognized Expert Specialist
Is rcvd_pktq a list, or is it another class? This is critical, as there may be a redefinition of the delete_head function. When in doubt RTFM.

It seems from this last question you did not look at my first response at all. Did my unpack solution not work?
May 24 '07 #8
zhangbo2050
7 New Member
Is rcvd_pktq a list, or is it another class? This is critical, as there may be a redefinition of the delete_head function. When in doubt RTFM.

It seems from this last question you did not look at my first response at all. Did my unpack solution not work?
Sorry that i haven't say, unpack did work well if i do struct.pack('!H H', desti_mac, src_mac) in before.

I guess my problem is that i need to find the place where rcvd_pktq is defined, and where delete_head is defined. lots of code to look through :)

'case closed'

Thanks you guys, for ur patience
May 24 '07 #9
Motoma
3,237 Recognized Expert Specialist
Sorry that i haven't say, unpack did work well if i do struct.pack('!H H', desti_mac, src_mac) in before.

I guess my problem is that i need to find the place where rcvd_pktq is defined, and where delete_head is defined. lots of code to look through :)

'case closed'

Thanks you guys, for ur patience
No problem. Perhaps you could post back the information that you find so we know how things turn out.

Come back anytime you have a question.
May 24 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
4206
by: Steve | last post by:
I have a SQL query I'm invoking via VB6 & ADO 2.8, that requires three "Left Outer Joins" in order to return every transaction for a specific set of criteria. Using three "Left Outer Joins" slows the system down considerably. I've tried creating a temp db, but I can't figure out how to execute two select commands. (It throws the exception...
2
66166
by: beena | last post by:
Apologize for posting this question.... Yes there were postings on update with join.... My question involves 4 table join... (hopefully qualifies as a new question) Need to convert the following sql from SYbase to UDB 8.2 FP8 on AIX. UPDATE TABLE A SET A.FLD_SUPV = B.FLD_SUPV FROM TABLEA A, TABLEB B, TABLEC C,TABLED D
1
4165
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a couple of tables in my database using INNER JOINS and the WHERE clause to specify the required constraints. However, I also want to read two...
5
3899
by: Hendrik Schober | last post by:
Hi, we just run into the problem, that "default" alignment in the project properies dialog seem to be different. We have a project that's a DLL, which is linked with a couple of LIBs. All are with the same solution. All had "Default" set in the "Struct Member Alignment" entry. After some assembler debugging we found out that a struct...
5
15494
by: Sphenix | last post by:
------------------------ UPDATE A SET A.ID = '?' + A.ID FROM TABLEA A LEFT OUTER JOIN TABLEB B ON A.INDEX = B.INDEX WHERE B.DUP_ID IS NULL ------------------------ seems like update with join statement not working in DB2 version 5
4
4404
by: Daniel Mark | last post by:
Hello all: I have found a useful module in IPython, named 'from IPython.ipstruct import Struct". So I can use it as follows: #################################### from IPython.ipstruct import Struct
15
2661
by: arnuld | last post by:
-------- PROGRAMME ----------- /* Stroustrup, 5.6 Structures STATEMENT: this programmes *tries* to do do this in 3 parts: 1.) it creates a "struct", named "jd", of type "address". 2. it then adds values to "jd" 3.) in the end it prints values of "jd".
4
41859
by: news.onet.pl | last post by:
Hi!! Is it possible to delete (or update) with join ?? For example DELETE a FROM TableA a INNER JOIN TableB b ON b.id = a.bId
0
2070
by: kartikmpatel | last post by:
I have set "AutoEllipsis" property on for my checkbox(winform). My application is working with multiple languages. Particular with Chinese language, I have some issues. Here are some observation on XP 32bit : 1) AutoEllipsis property set + Chinese Language Pack installed & Set = working well ( it displays, text of checkbox) 2)...
0
2182
by: raylopez99 | last post by:
I ran afoul of this Compiler error CS1612 recently, when trying to modify a Point, which I had made have a property. It's pointless to do this (initially it will compile, but you'll run into problems later). Apparently Point is a struct, a value type, and it does not behave like a classic structure (in my mind's eye, and see below)....
0
7912
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8202
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.