|
5/24 |
2005/6/14-16 [Computer/SW/Unix] UID:38127 Activity:low |
6/14 Does anyone know the POSIX specified way to get the fully qualified domain name of the local machine in a C program? gethostname just returns the name of the box without the domain. \_ There probably isn't a POSIX-specified way, as there is no single way to map machine->FQDN. (What if a machine has two, or 1000 FQDNs?) -tom \_ So far all I've gotten is: gethostname, get IP address, do reverse DNS lookup. Apparently this is a common problem, and everyone hates this. \_ It may be difficult to handle programatically, but that's because it sounds like you're trying to do something which simply can't be done reliably. Maybe if you explain what you're trying to accomplish there might be some help. -tom \_ in otherwords, you want the result of `hostname` \_ Well, hostname -f, but yeah. Anyone have to hostname source code? :P \_ On Soda: /usr/src/bin/hostname/hostname.c If you want a much better example, get a copy of Stevens Unix Network Programming Vol 1 and look at Chapter 11. http://www.amazon.com/exec/obidos/tg/detail/-/013490012X http://www.unpbook.com The http://unpbook.com site has src code for the examples which might help. \_ Thanks, the source isn't very helpful (it turns out) it's non-standard. But I have the Stevens book, and if that's the way to do it, ok I guess. \_ Figured it out. gethostbyname returns the cononical name as part of the hostent structure. Not optimal, but better than the next alternitive. -op |
5/24 |
|
www.amazon.com/exec/obidos/tg/detail/-/013490012X Unix Network Programming has been update d by author W Richard Stevens to encompass three new volumes. There hav e been a few changes in the computing world since 1990 (the year the ori ginal was published), and Stevens has taken the opportunity to create a complete set of reference manuals for programmers of all skill levels. The first volume, Networking APIs: Sockets and XTI, covers everything you need to know to make your programs communicate over networks. Stevens c overs everything from writing your programs to be compatible with both I nternet Protocol version 4 (IPv4) and IPv6, to raw sockets, routing sock ets, User Datagram Protocol (UDP), broadcasting/multicasting, routing so ckets, server internals, and more, plus a section covering Posix threads . Stevens also notes compatibility issues with different operating systems so that readers can create code that is more portable, and he offers ple nty of advice on how to make code more robust. An introductory tutorial or class text and a reference for experienced pr ogrammers. Revised from the 1990 edition by using ANSI C for all example s, expanding and rearranging much of the material, dropping the explanat ion of UNIX, describing the Posix interface, some terminology change, an d covering several new topics. the second probably on IPC: interprocess communications and the third on applications. Those are the first, simplest, and most important things to understand about it. Before explaining what makes it so good, let's get the table of contents out of the way: Preface Part 1 Introduction and TCP/IP 1 Introduction 2 The Transport Layer: TCP and UDP Part 2 Elementary Sockets 3 Sockets Introduction 4 Elementary TCP Sockets 5 TCP Client-Server Example 6 I/O Multiplexing: The select() and poll() Functions 7 Socket Options 8 Elementary UDP Sockets 9 Elementary Name and Address Conventions Part 3 Advanced Sockets 10. Client-Server Design Alternatives Part 4 XTI: X/Open Transport Interface 28. XTI: Additional Functions Appendix A IPv4, IPv6, ICMPv4, ICMPv6 Appendix B Virtual Networks Appendix C Debugging Techniques Appendix D Miscellaneous Source Code Appendix E Solutions to Selected Exercises Bibliography Index Appendices A Function Prototypes B Miscellaneous Source Code (all source code is available for download) C Solutions to Selected Exercises Bibliography Index Understanding why the book is as good as it is requires an understanding of what it does: it serves as a tutorial for learning sockets progra mming, it serves as an API reference, and it serves as a guide t o alternative strategies for network programs. It is not an easy thing t o address these three disparate goals at the same time. The way Stevens does it is through his method of presentation. The lowest-level building block around which Stevens structures his book is the individual function call. For each call (or minor variations on a single call), he provides the C prototype, and then, in text, explains what the function does, what it's arguments are for, and then provides a small C program that demonstrates it in action (all of the sample progr ams can also be downloaded from the web). These function-level building blocks are arranged into related sets, each of which is a chapter in the book. Each chapter has a wrapper that explains the basic concepts behin d the functions in that chapter, and some review exercises at the end. T he chapters in turn build on each other, with the most basic ones at the beginning and the more difficult ones towards the end. The chapters do more, however, than just explain how the functions work, they also present different approaches to structuring socket programs. T he basic problem in structuring a socket program is how to handle multip le connections. Stevens, in the process of teaching the reader the individual function calls, provides the reader with examples of all of these types of programs, along with a discussion of their relative strengths and weaknesses. I don't know if I can say e nough in favor of Stevens' choice to include this material, or enough ab out the quality of his coverage of it. First, I have mixed feelings about the presentation of error handling. Stevens' coverage in the text is excellent, but the samp le programs have a tendency to exit on error rather than demonstrate rec overy. only about 120 pages of this 1,00 0 page book are about XTI. Finally, Stevens absolutely assumes that the reader knows how to program in C, knows general UNIX programming, and ho w to use Unix development tools (or at least has some other source from which to learn them). If you don't know C programming, you want to get K ernighan & Ritchie's "The C Programming Language". If you don't know abo ut general UNIX programming, get Stevens' "Advanced Programming in the U NIX Environment". If you don't know the tools, I know of many books, but unfortunately none that I would particularly recommend. In closing, whatever the caveats, this is clearly a five-star programming book. If you need to write socket programs, it can save you untold amou nts of grief. Writing network programs that are efficient, fast, and rob ust is far from trivial, and you can think of the thousand pages in this book as a thousand ways to avoid a thousand mistakes. While it expensiv e, it paid for itself for me in the first hour, and every hour since has been a dividend - if only all my investments had worked out this well.. The seco nd volume is a grab-bag of material on pipes, message queues, mutexes, l ocks, semaphores, shared memory, and remote procedure calls. For network programming proper, the first volume is all you need. After I had been using UNIX for a long time and was getting into more advanced UNIX programming about a decade ago, these two books were recommended. I bought both of them and use them a lot, even when doing Windows programming. As an example, I had to reference them again this weekend. I am using Vis ual Basic and C++ under Windows to connect some UDP/IP communications be tween applications. Once again, these books were indispensable (even aft er looking at online help, Google, Microsoft Knowledge Base and Experts- Exchange). Any Internet professional should have both of these books on their shelf. See all my reviews Though book is preety straight forward. It rarely talks about tricks,code is highly redundant in the sense that e verywhere error checking is being done. Which makes it highly boring is that if you are dealing with some kind of N/W installation or S/W trobuleshooting. Talks much more on code, Was this review helpful to you? See all my reviews In my work, Stevens' books are absolutely a must-have reference. Anytime I am confused, it is clarified somewhere in this two-volume book. Yes, Stevens used a lot of his own wrapper functions instead of the sta ndard library functions, but this doesn't compromise the excellence of h is works. The wrapper functions only added some error processing functio nalities compared to the standard ones. If you like, you can use the sta ndard library functions in the place of his wrappers, and add your own e rror processing methods. IMHO, this two-volume works is much more better than APUE, for the explan ations are much more detailed, and the examples are much more abundant. Yet I am not attacking APUE, it is a good book as well, but maybe not as good as this 2-volume. I love Stevens' books so much that I wonder why Prentice Hall or Addison- Wesley doesn't want to publish a CD version of his books, just as O'Reil ly does. I hope one day, I can see in the bookstore "The Complete W Richard Steve ns" in one CD. Then I will not hesitate a moment to buy it, and referenc e it from time time to time with my PC. Suggestion Box Your comments can help make our site better for everyone. If you've found something incorrect, broken, or frustrating on this page, let us know s o that we can improve it. Please note that we are unable to respond dire ctly to suggestions made via this form. |
www.unpbook.com This book is for people who want to write programs that communicate with each other using an application program interface (API) known as sockets. Some readers may be very familiar with sockets already, as that model has become synonymous with network programming. Others may need an introduction to sockets from the ground up. The goal of this book is to offer guidance on network programming for beginners as well as professionals, for those developing new network-aware applications as well as those maintaining existing code, and for people who simply want to understand how the networking components of their system function. All the examples in this text are actual, runnable code tested on Unix systems. However, many non-Unix systems support the sockets API and the examples are largely operating system-independent, as are the general concepts we present. Virtually every operating system (OS) provides numerous network-aware applications such as Web browsers, email clients, and file-sharing servers. We discuss the usual partitioning of these applications into client and server and write our own small examples of these many times throughout the text. Sockets have been around, more or less in their current form, since the 1980s, and it is a tribute to their initial design that they have continued to be the network API of choice. Therefore, it may come as a surprise to learn that quite a bit has changed since the second edition of this book was published in 1998. The changes we've made to the text are summarized as follows: This new edition contains updated information on IPv6, which was only in draft form at the time of publication of the second edition and has evolved somewhat. That API has fallen out of common use and even the most recent POSIX specification does not bother to cover it. The coverage of TCP for transactions (T/TCP) has been dropped. Three chapters have been added to describe a relatively new transport protocol, SCTP. This reliable, message-oriented protocol provides multiple streams between endpoints and transport-level support for multihoming. It was originally designed for transport of telephony signaling across the Internet, but provides some features that many applications could take advantage of. A chapter has been added on key management sockets, which may be used with Internet Protocol Security (IPsec) and other network security services. The machines used, as well as the versions of their variants of Unix, have all been updated, and the examples have been updated to reflect how these machines behave. In many cases, examples were updated because OS vendors fixed bugs or added features, but as one might expect, we've discovered the occasional new bug here and there. Bill Fenner is Principal Technical Staff Member at AT&T Labs in Menlo Park, CA, specializing in IP multicasting, network management, and measurement. He is one of the IETF's Routing Area Directors, responsible for approving all routing-related documents that get published as RFCs. Andy Rudoff is a Senior Software Engineer at Sun Microsystems, where he has worked for approximately a decade. Andy's experience includes Networking, Operating Systems internals, File Systems, and High Availability software architecture. Bill Fenner and Andy Rudoff welcome your questions, corrections, and feedback on the UNIX Network Programming book. |
unpbook.com This book is for people who want to write programs that communicate with each other using an application program interface (API) known as sockets. Some readers may be very familiar with sockets already, as that model has become synonymous with network programming. Others may need an introduction to sockets from the ground up. The goal of this book is to offer guidance on network programming for beginners as well as professionals, for those developing new network-aware applications as well as those maintaining existing code, and for people who simply want to understand how the networking components of their system function. All the examples in this text are actual, runnable code tested on Unix systems. However, many non-Unix systems support the sockets API and the examples are largely operating system-independent, as are the general concepts we present. Virtually every operating system (OS) provides numerous network-aware applications such as Web browsers, email clients, and file-sharing servers. We discuss the usual partitioning of these applications into client and server and write our own small examples of these many times throughout the text. Sockets have been around, more or less in their current form, since the 1980s, and it is a tribute to their initial design that they have continued to be the network API of choice. Therefore, it may come as a surprise to learn that quite a bit has changed since the second edition of this book was published in 1998. The changes we've made to the text are summarized as follows: This new edition contains updated information on IPv6, which was only in draft form at the time of publication of the second edition and has evolved somewhat. That API has fallen out of common use and even the most recent POSIX specification does not bother to cover it. The coverage of TCP for transactions (T/TCP) has been dropped. Three chapters have been added to describe a relatively new transport protocol, SCTP. This reliable, message-oriented protocol provides multiple streams between endpoints and transport-level support for multihoming. It was originally designed for transport of telephony signaling across the Internet, but provides some features that many applications could take advantage of. A chapter has been added on key management sockets, which may be used with Internet Protocol Security (IPsec) and other network security services. The machines used, as well as the versions of their variants of Unix, have all been updated, and the examples have been updated to reflect how these machines behave. In many cases, examples were updated because OS vendors fixed bugs or added features, but as one might expect, we've discovered the occasional new bug here and there. Bill Fenner is Principal Technical Staff Member at AT&T Labs in Menlo Park, CA, specializing in IP multicasting, network management, and measurement. He is one of the IETF's Routing Area Directors, responsible for approving all routing-related documents that get published as RFCs. Andy Rudoff is a Senior Software Engineer at Sun Microsystems, where he has worked for approximately a decade. Andy's experience includes Networking, Operating Systems internals, File Systems, and High Availability software architecture. Bill Fenner and Andy Rudoff welcome your questions, corrections, and feedback on the UNIX Network Programming book. |