473,383 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Stdout to UDP socket in inetd

I'm trying to write a daemon in C that runs under (x)inetd that
communicates over UDP. I'm trying to write a simple DNS server that
returns the same IP for every query it receives. Things work just
fine reading the request, but when I try to write(2) the response, it
returns -1 with errno 89: "Destination address required". This seems
to indicate the wrong setting on a socket. Here's my xinetd config
paragraph:

------------------------- Achilles tendon - cut here -------------------------
service domain
{
port = 53
protocol = udp
socket_type = dgram
wait = yes
only_from = 127.0.0.1
user = root
server = /usr/local/sbin/dns
log_on_failure += USERID
disable = no
}
------------------------- Achilles tendon - cut here -------------------------

The write that's failing is the first one I'm calling, and it takes
place less than a second after the request comes in. I verified this
with the following program:

------------------------- Achilles tendon - cut here -------------------------
main() {
int err;
char *buf = "hello";

openlog("dns", LOG_PID, LOG_DAEMON);
if ((err = write(1, buf, 1)) != 1)
syslog(LOG_ERR, "write returned %d: errno %d: %s",
err, errno, strerror(errno));
closelog();
return 0;
}
------------------------- Achilles tendon - cut here -------------------------

If I run that from the command line, it prints an "h". From xinetd,
it logs:
write returned -1: errno 89: Destination address required

What am I doing wrong?

I suppose I could rewrite this thing to act as a standalone daemon,
but that's more work & a lot of refresher reading on socket programming.

If it matters, this is CentOS (RedHat) linux with a 2.4 kernel.

--
Ben "Obi-Wan" Hollingsworth ob****@jedi.com
The stuff of earth competes for the allegiance I owe only to the
Giver of all good things, so if I stand, let me stand on the
promise that You will pull me through. -- Rich Mullins

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Mar 10 '06 #1
3 7581

Obi-Wan wrote:
I'm trying to write a daemon in C that runs under (x)inetd that
communicates over UDP. I'm trying to write a simple DNS server that
returns the same IP for every query it receives. Things work just
fine reading the request, but when I try to write(2) the response, it
returns -1 with errno 89: "Destination address required". This seems
to indicate the wrong setting on a socket.


To be able to call write() on a UDP socket you first need to set the
default destination address by calling connect() on the socket. I don't
know if xinetd can does that for you.

Mar 10 '06 #2
Obi-Wan <bv*@tatooine.jedi.com> writes:
I'm trying to write a daemon in C that runs under (x)inetd that
communicates over UDP. I'm trying to write a simple DNS server that
returns the same IP for every query it receives. Things work just
fine reading the request, but when I try to write(2) the response, it
returns -1 with errno 89: "Destination address required". This seems
to indicate the wrong setting on a socket. Here's my xinetd config
paragraph:


That's not going to work. As a UDP wait-type service, you're given
the actual socket that the inetd process has.

In other words, you should be doing something like this:

char buffer[1024];
struct sockaddr_in from;
int fromlen, retv;

for (;;) {
/* Kill myself if I've been idle for a while */
alarm(10);
fromlen = sizeof (from);
retv = recvfrom(0, buffer, sizeof (buffer), 0, &from,
&fromlen);
... do something ...
sendto(1, replymsg, replylen, 0, &from, fromlen);
}

I think there are some useful examples of this in the Stevens
networking books.

--
James Carlson, KISS Network <ja*************@sun.com>
Sun Microsystems / 1 Network Drive 71.232W Vox +1 781 442 2084
MS UBUR02-212 / Burlington MA 01803-2757 42.496N Fax +1 781 442 1677
Mar 10 '06 #3
Obi-Wan <bv*@tatooine.jedi.com> writes:
I'm trying to write a daemon in C that runs under (x)inetd that
communicates over UDP.

[...]

Standard C does not provide any form of networking. Please drop
comp.lang.c from the newsgroups line if you post a followup. Thanks.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 11 '06 #4

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

Similar topics

5
by: Jean-Pierre Bergamin | last post by:
Dear python-Community We are forced to use a quite old simulation software that's based on Modula-2. The idea is now to let this software "talk" to the outside world over a TCP/IP network. ...
5
by: Moosebumps | last post by:
I have a large set of Python scripts that interface with command line utilities (primarily Perforce). I am currently capturing ALL the text output in order to get results and such. I am using the...
2
by: Jody Burgess | last post by:
Hi; I am writing my first python program and would like to know how to change stdout to refer to my default printer or any other printer on my network. The other question is, Is there an API set...
1
by: Harry George | last post by:
Normally the SOAP Servers are designed to take control of a port and run their own sockets via inheritance from SocktServer. But under inetd and xinetd, the port is controlled elsewhere and the...
3
by: David Douard | last post by:
Hi everybody, let me explain by problem: I am working on an application which consists in a C++ dll (numeric computations) and a Python IHM (Python/Tk), which must run under Linux and win32. My...
1
by: Pravin Prabhu | last post by:
Hi, Can the 'stdin' and 'stdout' streams point to a Network socket? I have a socket connection from Windows to UNIX, can I set the two streams to point to the socket connection to send/receive...
1
by: Samuel | last post by:
Hi, I am trying to automate a telnet session (currently using Python's telnetlib) and would like to echo any response of the remote host to stdout, as soon as it arrives on telnetlib's open TCP...
0
by: carl.dhalluin | last post by:
Hi I want a simple way to interactively remote debug a running python script which has no tty terminal attached to it. The scripts are running standalone (i.e. they are automatically started and...
1
Banfa
by: Banfa | last post by:
Looking at man swat It has the line swat is run from inetd What is inetd?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.