473,396 Members | 1,995 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,396 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 7582

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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...

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.