LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-24-2007, 08:59 AM   #1
nc3b
Member
 
Registered: Aug 2005
Posts: 330

Rep: Reputation: 32
Send DNS query datagram


Hi. In am trying to write a simple program that send a udp datagram to a dns server and then gets the response. The problem is, I don't know how to create that datagram, and I don't know what message to send to the server. If it could only be as easy as with http (GET etc). Also, please note I am not simply trying to resolve names (I would have used gethostbyname() ), I must send a raw UDP datagram.
 
Old 05-24-2007, 10:02 AM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Places you should look:
1. For information on the mechanics of sending and receiving TCP/IP streams and datagrams, Beej's Guide.

2. For information regarding DNS, the internet RFCs related to DNS.

What I would do as part of the background research, set up a network sniffer to capture packets to and from a DNS server. Create a controlled DNS query using ordinary commands (like ping, for instance), capture the resulting exchange, and analyze that. Perhaps even set up something like netcat, configure a system to send DNS queries to it, and capture the results.

I sense that you are not telling us what your real intentions are. Perhaps with more information, someone can point out a simple and easy solution. Unless this is homework....

--- rod.

Last edited by theNbomr; 05-24-2007 at 10:03 AM.
 
Old 05-24-2007, 01:06 PM   #3
nc3b
Member
 
Registered: Aug 2005
Posts: 330

Original Poster
Rep: Reputation: 32
Thanks.

Actually I have read beej's guide a long time ago. Obviously, I know how to send datagrams (but this is not thanks to beej's guide but thanks to some books about sockets programming).

The problem is that constructing the dns header and the dns query by hand is quite unpleasant. I am not hiding anything, that's exactly what I want to do, send a raw udp packet and print back what the server sends.
 
Old 05-24-2007, 03:35 PM   #4
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
You may be interested in the way gethostbyname does it. Download libc sources, unpack it and look into it's net directory. The whole query generation and response parsing is present.
 
Old 05-24-2007, 07:05 PM   #5
95se
Member
 
Registered: Apr 2002
Location: Windsor, ON, CA
Distribution: Ubuntu
Posts: 740

Rep: Reputation: 32
DNS is actually a pretty straightforward protocol. RFC 1035 is what you really want to read. If your just looking to construct a single type of DNS request and handle the reply, you shouldn't have to spend too much time w/ it either.
 
Old 05-25-2007, 12:35 PM   #6
nc3b
Member
 
Registered: Aug 2005
Posts: 330

Original Poster
Rep: Reputation: 32
Thank you for your replies. Of course I have already read the rfc . I have, in the end, read some gethostbyname source and decided to write the damn thing by hand. And actually I have to be able to construct all kinds of dns queries.. Anyway, thank you for your help.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Query regarding DNS saini_mw Linux - Software 4 09-14-2009 12:29 PM
DNS query sanw2k Linux - Networking 1 03-11-2005 11:31 PM
DNS query chynna_v Linux - Newbie 1 09-15-2004 04:57 AM
Send query string via MIRC script cadj Programming 0 08-25-2004 06:25 AM
cron to run a an sql query and send Email ehsan Linux - General 2 03-14-2001 10:50 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration