ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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....
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.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.