gethost.c revision 4809af1b585989830a14e97aa5095fdd2bfd11be
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson#include <isc/net.h>
499b34cea04a46823d003d4c0520c8b03e8513cbBrian Wellington#include <lwres/netdb.h>
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence#include <stdio.h>
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafssonstatic struct hostent *he = NULL;
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrencestruct hostent *
15a44745412679c30a6d022733925af70a38b715David Lawrencegethostbyname(const char *name) {
15a44745412679c30a6d022733925af70a38b715David Lawrence int error;
15a44745412679c30a6d022733925af70a38b715David Lawrence
15a44745412679c30a6d022733925af70a38b715David Lawrence if (he != NULL)
15a44745412679c30a6d022733925af70a38b715David Lawrence freehostent(he);
15a44745412679c30a6d022733925af70a38b715David Lawrence
15a44745412679c30a6d022733925af70a38b715David Lawrence he = getipnodebyname(name, AF_INET, 0, &error);
15a44745412679c30a6d022733925af70a38b715David Lawrence h_errno = error;
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson return (he);
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson}
900d7d9c9bc443110f9a2b93c94def44093d64b0David Lawrence
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrencestruct hostent *
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafssongethostbyaddr(const char *addr, int len, int type) {
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson int error;
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson if (he != NULL)
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson freehostent(he);
9cd6d409b78a6f833b681c13a68fbdc7c024fe66David Lawrence
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson he = getipnodebyaddr(addr, len, type, &error);
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson h_errno = error;
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson return (he);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence}
364a82f7c25b62967678027043425201a5e5171aBob Halley
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafssonstruct hostent *
b356893425f18a2399771faa875e91318f204fb5Andreas Gustafssongethostent(void) {
b356893425f18a2399771faa875e91318f204fb5Andreas Gustafsson
b356893425f18a2399771faa875e91318f204fb5Andreas Gustafsson if (he != NULL)
b356893425f18a2399771faa875e91318f204fb5Andreas Gustafsson freehostent(he);
b356893425f18a2399771faa875e91318f204fb5Andreas Gustafsson
b356893425f18a2399771faa875e91318f204fb5Andreas Gustafsson return (NULL);
b356893425f18a2399771faa875e91318f204fb5Andreas Gustafsson}
b356893425f18a2399771faa875e91318f204fb5Andreas Gustafsson
b356893425f18a2399771faa875e91318f204fb5Andreas Gustafssonvoid
b356893425f18a2399771faa875e91318f204fb5Andreas Gustafssonsethostent(int stayopen) {
b356893425f18a2399771faa875e91318f204fb5Andreas Gustafsson /* empty */
b356893425f18a2399771faa875e91318f204fb5Andreas Gustafsson}
b356893425f18a2399771faa875e91318f204fb5Andreas Gustafsson
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrencevoid
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrenceendhostent(void) {
b356893425f18a2399771faa875e91318f204fb5Andreas Gustafsson /* empty */
b356893425f18a2399771faa875e91318f204fb5Andreas Gustafsson}
b356893425f18a2399771faa875e91318f204fb5Andreas Gustafsson