A Simple TCP & UDP Socket Library
Dependents: SimpleSocketExamples 1.0
Resolver.cpp@0:3eb1ce25eac4, 2012-06-05 (annotated)
- Committer:
- yamaguch
- Date:
- Tue Jun 05 05:56:49 2012 +0000
- Revision:
- 0:3eb1ce25eac4
1.1.3; fixed 0x00 reception bug
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yamaguch | 0:3eb1ce25eac4 | 1 | /* |
yamaguch | 0:3eb1ce25eac4 | 2 | Copyright (c) 2011, Senio Networks, Inc. |
yamaguch | 0:3eb1ce25eac4 | 3 | |
yamaguch | 0:3eb1ce25eac4 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
yamaguch | 0:3eb1ce25eac4 | 5 | of this software and associated documentation files (the "Software"), to deal |
yamaguch | 0:3eb1ce25eac4 | 6 | in the Software without restriction, including without limitation the rights |
yamaguch | 0:3eb1ce25eac4 | 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
yamaguch | 0:3eb1ce25eac4 | 8 | copies of the Software, and to permit persons to whom the Software is |
yamaguch | 0:3eb1ce25eac4 | 9 | furnished to do so, subject to the following conditions: |
yamaguch | 0:3eb1ce25eac4 | 10 | |
yamaguch | 0:3eb1ce25eac4 | 11 | The above copyright notice and this permission notice shall be included in |
yamaguch | 0:3eb1ce25eac4 | 12 | all copies or substantial portions of the Software. |
yamaguch | 0:3eb1ce25eac4 | 13 | |
yamaguch | 0:3eb1ce25eac4 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
yamaguch | 0:3eb1ce25eac4 | 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
yamaguch | 0:3eb1ce25eac4 | 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
yamaguch | 0:3eb1ce25eac4 | 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
yamaguch | 0:3eb1ce25eac4 | 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
yamaguch | 0:3eb1ce25eac4 | 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
yamaguch | 0:3eb1ce25eac4 | 20 | THE SOFTWARE. |
yamaguch | 0:3eb1ce25eac4 | 21 | */ |
yamaguch | 0:3eb1ce25eac4 | 22 | |
yamaguch | 0:3eb1ce25eac4 | 23 | #include "SimpleSocket.h" |
yamaguch | 0:3eb1ce25eac4 | 24 | |
yamaguch | 0:3eb1ce25eac4 | 25 | Resolver::Resolver() {} |
yamaguch | 0:3eb1ce25eac4 | 26 | |
yamaguch | 0:3eb1ce25eac4 | 27 | IpAddr Resolver::resolve(char *name, bool debug) { |
yamaguch | 0:3eb1ce25eac4 | 28 | IpAddr ip; |
yamaguch | 0:3eb1ce25eac4 | 29 | DNSRequest request; |
yamaguch | 0:3eb1ce25eac4 | 30 | |
yamaguch | 0:3eb1ce25eac4 | 31 | if (request.resolve(name) == DNS_OK) { |
yamaguch | 0:3eb1ce25eac4 | 32 | replied = false; |
yamaguch | 0:3eb1ce25eac4 | 33 | request.setOnReply(this, &Resolver::onReply); |
yamaguch | 0:3eb1ce25eac4 | 34 | while (!replied) |
yamaguch | 0:3eb1ce25eac4 | 35 | Net::poll(); |
yamaguch | 0:3eb1ce25eac4 | 36 | if (reply == DNS_FOUND) |
yamaguch | 0:3eb1ce25eac4 | 37 | request.getResult(&ip); |
yamaguch | 0:3eb1ce25eac4 | 38 | } |
yamaguch | 0:3eb1ce25eac4 | 39 | |
yamaguch | 0:3eb1ce25eac4 | 40 | DBG("%s -> %d.%d.%d.%d\n", name, ip[0], ip[1], ip[2], ip[3]); |
yamaguch | 0:3eb1ce25eac4 | 41 | |
yamaguch | 0:3eb1ce25eac4 | 42 | return ip; |
yamaguch | 0:3eb1ce25eac4 | 43 | } |
yamaguch | 0:3eb1ce25eac4 | 44 | |
yamaguch | 0:3eb1ce25eac4 | 45 | |
yamaguch | 0:3eb1ce25eac4 | 46 | void Resolver::onReply(DNSReply reply) { |
yamaguch | 0:3eb1ce25eac4 | 47 | replied = true; |
yamaguch | 0:3eb1ce25eac4 | 48 | this->reply = reply; |
yamaguch | 0:3eb1ce25eac4 | 49 | } |