Sponsored Content
Full Discussion: Python, struct.pack
Top Forums Programming Python, struct.pack Post 302471541 by Dedalus on Saturday 13th of November 2010 01:32:07 PM
Old 11-13-2010
Python, struct.pack

Hello,

I found some code on line.
Is a python function that bring up an Internet interface, here the code:
Code:
        # Get existing device flags
        ifreq = struct.pack('16sh', 'wlan0', 0)
        flags = struct.unpack('16sh', fcntl.ioctl(sockfd, SIOCGIFFLAGS, ifreq))[1]

I'm starting reading something about it. I know that the struct.pack is needed for compatibility with C struct.
But why we pack the wlan0 exactly with 16 string and 1 short (and not 30s10h)?
In my case for example I get:
Quote:
ifreq = wlan0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
and
Quote:
fcntl.ioctl(sockfd, SIOCGIFFLAGS, ifreq) give me:
wlan0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00C\x10
the final result unpacking everything is 4163.
Is it because from the fcntl.ioctl (in this case) I will expect to fill it with string and short?

Thanks

D
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl help!! (pack()?)

Hello everyone. I wrote a perl script to get the two answers from a value: x. By this, I want to do sqrt($x) in different precision. #!/usr/bin/perl print "Input the initial value x:\n"; chomp($x=<STDIN>); $comp=sqrt($x); $float_value=pack("f", $comp); $double_value=pack("d", $comp);... (2 Replies)
Discussion started by: Euler04
2 Replies

2. AIX

Aix - Service Pack

I've recently installed ServicePack1 for Tecnology_Level 9 of AIX 5.2 . The result of installation is "OK" but with oslevel -s i dont see the service pack installed .... after many research i try (with many luck!!) instfix -i|grep SP and the result : All filesets for 5200-08-01_SP... (1 Reply)
Discussion started by: BabylonRocker
1 Replies

3. UNIX for Dummies Questions & Answers

Pack current folder

How do I pack (using tar zcvf ?) the current folder inluding all files and folders ?? I need to be sure to get all files and folders/subfolders... Later I will unpack into a new folder on a new server.. Appreciate any help.. (3 Replies)
Discussion started by: WebWatch
3 Replies

4. UNIX for Dummies Questions & Answers

How to access a struct within a struct?

Can someone tell me how to do this? Just a thought that entered my mind when learning about structs. First thought was: struct one { struct two; } struct two { three; } one->two->three would this be how you would access "three"? (1 Reply)
Discussion started by: unbelievable21
1 Replies

5. Solaris

weblogic Maintenance pack

Hi ALL, I am running weblogic portal(9.2.2) on solaris and i wanted to apply maintenance pack and upgrade it to 9.2.3. Without using x-windows system how can i apply maintenance pack.? (0 Replies)
Discussion started by: gaurav183
0 Replies

6. Programming

Storing C++-struct in file - problem when adding new item in struct

Hi, I have received an application that stores some properties in a file. The existing struct looks like this: struct TData { UINT uSizeIncludingStrings; // copy of Telnet data struct UINT uSize; // basic properties: TCHAR szHost; //defined in Sshconfig UINT iPortNr; TCHAR... (2 Replies)
Discussion started by: Powerponken
2 Replies

7. Shell Programming and Scripting

**python** unable to read the background color in python

I am working on requirement on spreadsheet in python scripting. I have a spreadsheet containing cell values and with background color. I am able to read the value value but unable to get the background color of that particular cell. Actually my requirement is to read the cell value along... (1 Reply)
Discussion started by: giridhar276
1 Replies

8. Programming

Python Results Converted To C Struct Header File

I created python code that produce output in the form of: moses-red-sea=1.00.03 genesis-snake=2.03 deliverance=5.0.010 I need to take this output and create a "C" header file and have it look like this: struct { char *name; char *fixed_version; } filename_versions... (7 Replies)
Discussion started by: metallica1973
7 Replies

9. Programming

Create a C source and compile inside Python 1.4.0 to 3.7.0 in Python for ALL? platforms...

Hi all... As you know I like making code backwards compatible for as many platforms as possible. This Python script was in fact dedicated for the AMIGA A1200 using Pythons 1.4.0, 1.5.2, 1.6.0, 2.0.1, and 2.4.6 as that is all we have for varying levels of upgrades from a HDD and 4MB FastRam... (1 Reply)
Discussion started by: wisecracker
1 Replies
xna(7)							 Miscellaneous Information Manual						    xna(7)

NAME
xna - The DEMNA Ethernet interfaces SYNOPSIS
config_driver xna DESCRIPTION
The xna driver provides access to a 10-MB Ethernet network through the DEMNA adapter. The DEMNA is an Ethernet-to-XMI adapter. The host's Internet address is specified at boot time with an SIOCSIFADDR ioctl. The xna driver employs the Address Resolution Protocol, as described in arp(7), to map dynamically between Internet and Ethernet addresses on the local network. The SIOCSPHYSADDR ioctl can be used to change the physical address of the adapter and SIOCRPHYSADDR can be used to read its physical address. SIOCADDMULTI and SIOCDELMULTI can be used to add or delete multicast addresses. The xna driver supports a maximum of 12 multi- cast addresses. The argument to the latter ioctls is a pointer to an ``ifreq'' structure found in <net/if.h>. SIOCRDCTRS and SIOCRDZCTRS ioctls can be used to read or read and clear network counters. The argument to the latter two ioctls is a pointer to a counter structure ``ctrreq'' found in <net/if.h>. The ioctls SIOCENABLBACK and SIOCDISABLBACK can be used to enable and disable the interface loopback mode. RESTRICTIONS
The PUP protocol family is not supported. EXAMPLES
To obtain the physical address of the adapter, use the SIOCRPHYSADDR ioctl as in the following program example: #include <stdio.h> /* standard I/O */ #include <errno.h> /* error numbers */ #include <sys/socket.h> /* socket definitions */ #include <sys/ioctl.h> /* ioctls */ #include <net/if.h> /* generic interface structures */ main() { int s,i; static struct ifdevea devea; /* Get a socket */ s = socket(AF_INET,SOCK_DGRAM,0); if (s < 0) { perror("socket"); exit(1); } strcpy(devea.ifr_name,"xna0"); if (ioctl(s,SIOCRPHYSADDR,&devea) < 0) { perror(&devea.ifr_name[0]); exit(1); } printf("Address is "); for (i = 0; i < 6; i++) printf("%X ", devea.default_pa[i] & 0xff); printf(" "); close(s); } To enable external loopback, use the SIOCENABLEBACK ioctl as in the following program example: #include <stdio.h> /* standard I/O */ #include <errno.h> /* error numbers */ #include <sys/socket.h> /* socket definitions */ #include <sys/ioctl.h> /* ioctls */ #include <net/if.h> /* generic interface structures */ main() { int s; struct ifreq data; /* Get a socket */ s = socket(AF_INET,SOCK_DGRAM,0); if (s < 0) { perror("socket"); exit(1); } strcpy(data.ifr_name,"xna0"); if (ioctl(s,SIOCENABLEBACK,&data) < 0) { perror("SIOCENABLEBACK:"); exit(1); } close(s); } ERRORS
The DEMNA errors are coded as follows: Adapter did not pass the power-up self-test during autoconfiguration time. The port attachment fails. The xna driver was unable to allocate memory for adapter data structures. The port attachment fails. The xna driver was unable to map memory for adapter data structures. The port attachment fails. The xna driver was unable to bring the adapter into the initialized state. The port attachment fails. The xna driver failed to prepare the adapter for run-time use. The xna driver was unable to bring the adapter into the initialized state during a port reset. The adapter port command failed. The error code gives reason for failure. Too many multicast requests have been made. RELATED INFORMATION
Files: arp(7), inet(7), intro(4), netstat(1) delim off xna(7)
All times are GMT -4. The time now is 03:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy