I'm trying to read packets from a tun device in Python, the code I used
for this is the following:
f = file( '/dev/tun0', 'r+' )
pkt = f.read( 1500 )
The problem is that the f.read() call doesn't return. When I used a small
value in the f.read() call instead of the 1500, like 1 or 5, it did
return the first bytes of the packet.
I then went to the manuals and found that file() uses stdio's fopen, so I
changed my code to make file() not do any buffering, like this:
f = file( '/dev/tun0', 'r+', 0 )
pkt = f.read( 1500 )
But the behavior of the program is the same as the one above.
What I'm looking for is a way to open a file in Python without using
stdio, or a way to read from a tun device using it.
I also tried google'ing for another Python program that uses a tun device,
but couldn't find any yet, so if you know of a Python program that uses a
tun device, that'd be enough for me to figure out what I'm doing wrong.
Thank you for reading all this! 1 3460
Andre <an***@netvisio n.com.br> wrote in message news:<ma******* *************** ************@py thon.org>... I'm trying to read packets from a tun device in Python, the code I used for this is the following: f = file( '/dev/tun0', 'r+' ) pkt = f.read( 1500 )
The problem is that the f.read() call doesn't return. When I used a small value in the f.read() call instead of the 1500, like 1 or 5, it did return the first bytes of the packet. I then went to the manuals and found that file() uses stdio's fopen, so I changed my code to make file() not do any buffering, like this:
f = file( '/dev/tun0', 'r+', 0 ) pkt = f.read( 1500 ) But the behavior of the program is the same as the one above. What I'm looking for is a way to open a file in Python without using stdio, or a way to read from a tun device using it.
I'm not sure if this problem is due to buffering on your client side, but
you can open plain file descriptors in Python. The buffering could also
be on the server side of the tun device. What is connected to the other
side of the tun? Is that code that you wrote too? If so then send a copy
of that and I can understand better what is going on.
The 'os' package supports raw file descriptor file IO which is below stdio.
import os
fd_tun = os.open ('/dev/tun0', os.O_RDWR)
data = os.read (fd_tun, 1500)
os.close (fd_tun)
Let me know how this goes.
Yours,
Noah This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Eric Lilja |
last post by:
Hello, I have a text file that contains a number of entries describing a
recipe. Each entry consists of a number of strings. Here's an example file
with only one entry (recipe):
Name=Maple Quill
Process=Interim
Level=10
Technique=Fletching
Knowledge=Woodworking
Device=Sawhorse
Primary components=Refined Maple
|
by: Ldaled |
last post by:
Okay, I had a previous post called reading an XML document. Since this post I
have revised my code and got it to work. Now, Like Derek had mentioned in
answer to my previous post, I am getting an XmlException. The error message
is invalid date SEMICOLON expected at Line 1 Position 380. Derek you had said
something about the UTF encoding...
|
by: rs |
last post by:
Hi guys,
I am trying to read from a USB keyboard using vb.net and HID classes. the
USB keyboard is not my primary keyboard. I have a ps2 keyboard connected and
is detected in device manager as my keyboard. the USB keyboard is detected
as HID keyboard device. the program finds the keyboard if it is attached.
and I am getting valid handles....
|
by: rs |
last post by:
Hi guys,
I am trying to read from a USB keyboard using vb.net and HID classes. the
USB keyboard is not my primary keyboard. I have a ps2 keyboard connected and
is detected in device manager as my keyboard. the USB keyboard is detected
as HID keyboard device. the program finds the keyboard if it is attached.
and I am getting valid handles....
|
by: Macca |
last post by:
Hi,
I have a synchronous socket server which my app uses to read data from
clients.
To test this I have a simulated client that sends 100 byte packets.
I have set up the socket server so that its buffer is bigger than this.
I did this expecting the data to be read in one pass.
| |
by: Pashlipops |
last post by:
Hi there
I am looking for some guidance.
I am new to C++ and whilst I am reading up about the language, my
actual goal is to create a program that reads a UDP packet sent by a
data logger and displays the reults real-time on screen.
The UDP packet is sent every 200ms. I know the port. I have Windows
Vicual C++ Express Edition running...
|
by: sreehari |
last post by:
Hi All,
I have this problem,
I have developed a Master - Slave kinda appliacation , were the slave
is generally a device.when i broadcast a message from my application,
the Device seems to recieve the message and responds correctly, and
replies with a broadcast frame. Here is where i face the problem, what
happens is that my application...
|
by: Plater |
last post by:
Useing a packet sniffer I have been watching some tcpip traffic between my computer and my embedded device I am developing on (the embeded device runs wince 5.0) and I have been noticing that a LOT (like %40) of the packets leaving the embeded device are showing up as having a bad checksum and having to be re-sent.
I was just wondering if that is...
|
by: makTSPL |
last post by:
Dear All,
I am developing an application in C#. This application communicates with Garmin Forerunner device. I have developed a demo for it, which shows Device software version. but I am not able to get Device history Data. What should I pass for getting history data.
Below is the code sample which I am using for fetching device information:
...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
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. ...
| |
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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...
| |