473,786 Members | 2,608 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

socket.makefile & AF_UNIX

I think I'm overlooking something assumed in socket's makefile method.
Googling several hours and digging thru the python reference didn't help - I
think I'm overlooking an assumption between Python and UNIX socket objects
neither is explicitely discussing. I think my mknod

In the makefile operation on socket (pydoc socket.socket.m akefile... using
AF_UNIX, allowing you to create a file object to correspond to a socket) I've
got an sample program (goal: open up unix file socket object for snort's
alert_unixsock output mode to dump to. later, take data written into file
object and process) as follows:

############### ############### #########3
#!/usr/bin/python
## socketfile.py
## for socket file object to collect snort data via alert_unixsock output
"""makes file interface to socket. demo application takes data written to file
and prints it."""

from socket import *
import os

FILE = 'snort_alert'
#FILE = '/dev/log'

if not os.path.exists( FILE):
print "Creating file..."
os.mknod(FILE)

s = socket(AF_UNIX, SOCK_DGRAM)
# SOCK_DGRAM for UDP compatibility with /dev/log - errors
# on SOCK_STREAM reference for /dev/log

s.connect(FILE)

f = s.makefile('rw' )

while 1:
print "Data: %s" % f.readline(1024 )
f.flush()
############### ############### #########3

If I guess correctly, socket.makefile might be wanting to use a block or
character file, which I may not be setting up properly. pydoc on os.mknod
refers to os.makedev which is even sparser on explanation. Part of the reason
for my guess is that:

- permissions on my snort_alert file don't look right:
-rw------- 1 sysadmin users 0 Dec 10 02:58 snort_alert

compared to:
srw-rw-rw- 1 root root 0 Dec 10 01:14 /dev/log=

And when I use /dev/log instead (which exists), it connects to the file object
and runs (though snort does not want to dump to /dev/log and the limitations
of the alert_unixsock output method limit it to /var/log/snort/snort_alert
only). Any thoughts from the socket savvy would be *greatly* appreciated!

Jamie

Jul 18 '05 #1
1 4655
Jamie Saker <w0***@firepole .com> writes:
In the makefile operation on socket (pydoc socket.socket.m akefile... using
AF_UNIX, allowing you to create a file object to correspond to a socket) I've
got an sample program (goal: open up unix file socket object for snort's
alert_unixsock output mode to dump to. later, take data written into file
object and process) as follows:


If you're trying to create a Unix socket then mknod() isn't what
you need. You probably want to create a socket and bind() it to
the log file:

filename = 'snort_alert'
s = socket(AF_UNIX, SOCK_DGRAM)
s.bind(filename )

The call to bind() will probably fail if the socket file already
exists, so you might want to unlink it first (or make sure you clean
up by unlinking it whenever you exit).

Whether it's appropriate to call makefile() and use methods like
readline() depends on the format of the data that the other end
will send. If it's binary then you might need to use s.recv().

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1470
by: Rajarshi Guha | last post by:
Hi, I'm writing some code using PyGTK2 that uses inpu_add_full() to watch a socket. I've included the code below. I have two questions: 1) What does a condition == 16 mean? It does match any of the gtk.gdk.INPUT_* values. What is the use of the condition variable in the callback? 2) The source variable in the call back is an fd. I have some trivial code that is able to read from a socket:
4
11774
by: Bryan Olson | last post by:
Here's the problem: Suppose we use: import socket f = some_socket.makefile() Then: f.read() is efficient, but verbose, and incorrect (or at least does not play will with others);
8
3194
by: Paulo da Silva | last post by:
How are those "files" of type "socket", whose name begins with "=", created? How can I create them with python? Thanks.
6
9801
by: J Rice | last post by:
Hi, I feel like I should apologize in advance because I must be missing something fairly basic and fundamental here. I don't have a book on Python network programming (yet) and I haven't been able to find an answer on the net so far. I am trying to create a pair of programs, one (the client) will be short-lived (fairly) and the second (server) will act as a cache for the client. Both will run on the same machine, so I think a simple...
15
4921
by: nephish | last post by:
hey there, i have a script that waits for message packets from a data server over a socket. it goes a little like this: while 1: x+=1 databack = sockobj.recv(158) if databack:
6
3676
by: ahlongxp | last post by:
socket.makefile() may lose data when "connection reset by peer". and socket.recv() will never lose the data. change the "1" to "0" in the client code to see the difference. confirmed on both windows and linux. so I guess there is a problem with makefile(). # Echo server program
3
1791
by: Clement | last post by:
Please help me....... I am getting blocked in bind() system call....... i don't know why can you please any one tell me why........ #include<stdio.h> #include<sys/un.h>
1
14751
by: wsguglielmetti | last post by:
Hi, How are you? I'm completly new in python but I know a little of C. I developed a small application in python which generate and receive some data from times in times (question of seconds) and I need to send this data to a unix domain socket (/var/run/sfp) and read the response and print on the screen.
1
1345
by: Clement | last post by:
Please tell me why the follwing program is not working............ client.c #include<stdio.h> #include<sys/socket.h> #include<sys/un.h> int main() {
0
9650
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10363
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9962
tracyyun
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6748
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4067
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
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.