[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
CVS gsasl/gl
From: |
gsasl-commit |
Subject: |
CVS gsasl/gl |
Date: |
Sun, 05 Sep 2004 22:37:46 +0200 |
Update of /home/cvs/gsasl/gl
In directory dopio:/tmp/cvs-serv9711/gl
Modified Files:
Makefile.am
Added Files:
getaddrinfo.c getaddrinfo.h
Log Message:
Assume getaddrinfo.
Add getaddrinfo gnulib module, for system that lack it.
--- /home/cvs/gsasl/gl/Makefile.am 2004/08/16 16:31:49 1.32
+++ /home/cvs/gsasl/gl/Makefile.am 2004/09/05 20:37:46 1.33
@@ -10,7 +10,7 @@
# Generated by gnulib-tool.
#
# Invoked as: gnulib-tool --import
-# Reproduce by: gnulib-tool --import --dir=. --lib=libgl --source-base=gl
--m4-base=gl/m4 --libtool dummy error exit extensions getline getopt
getpass-gnu gettext progname stdbool strdup unlocked-io
+# Reproduce by: gnulib-tool --import --dir=. --lib=libgl --source-base=gl
--m4-base=gl/m4 --libtool dummy error exit extensions getaddrinfo getline
getopt getpass-gnu gettext progname restrict stdbool strdup unlocked-io
AUTOMAKE_OPTIONS = 1.8 gnits
@@ -31,6 +31,8 @@
libgl_la_SOURCES += exit.h
+libgl_la_SOURCES += getaddrinfo.h
+
libgl_la_SOURCES += getline.h
EXTRA_DIST += getndelim2.h getndelim2.c
@@ -51,6 +53,7 @@
libgl_la_SOURCES += progname.h progname.c
+
BUILT_SOURCES += $(STDBOOL_H)
EXTRA_DIST += stdbool_.h
--- /home/cvs/gsasl/gl/getaddrinfo.c 2004/09/05 20:37:46 NONE
+++ /home/cvs/gsasl/gl/getaddrinfo.c 2004/09/05 20:37:46 1.1
/* Get address information (partial implementation).
Copyright (C) 2004 Free Software Foundation, Inc.
Written by Simon Josefsson <address@hidden>.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#if HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <gettext.h>
#define _(String) gettext (String)
#define N_(String) String
#include "getaddrinfo.h"
/* Translate name of a service location and/or a service name to set of
socket addresses. */
int
getaddrinfo (const char *restrict nodename,
const char *restrict servname,
const struct addrinfo *restrict hints,
struct addrinfo **restrict res)
{
struct addrinfo *tmp;
struct sockaddr sock;
struct sockaddr *sockp = &sock;
struct servent *se;
struct hostent *he;
if (hints && hints->ai_flags)
/* FIXME: Support more flags. */
return EAI_BADFLAGS;
if (hints &&
hints->ai_family != PF_UNSPEC &&
hints->ai_family != PF_INET &&
hints->ai_family != PF_INET6)
/* FIXME: Support more families. */
return EAI_FAMILY;
if (hints && hints->ai_socktype)
/* FIXME: Support more socket types. */
return EAI_SOCKTYPE;
if (hints &&
hints->ai_protocol != SOCK_STREAM &&
hints->ai_protocol != SOCK_DGRAM)
/* FIXME: Support other protocols. */
return EAI_SERVICE; /* FIXME: Better return code? */
if (!nodename)
/* FIXME: Support server bind mode. */
return EAI_NONAME;
if (servname)
{
/* FIXME: Use getservbyname_r if available. */
se = getservbyname (servname,
hints->ai_protocol == SOCK_DGRAM ? "udp" : "tcp");
if (!se)
return EAI_SERVICE;
}
/* FIXME: Use gethostbyname_r if available. */
he = gethostbyname (connect_hostname);
if (!he || he->h_addr_list[0] == NULL)
return EAI_NONAME;
tmp = calloc (1, sizeof (*tmp));
if (!tmp)
return EAI_MEMORY;
tmp->ai_addr->sa_family = he->he_addrtype;
switch (tmp->ai_addr->sa_family)
{
case PF_INET6:
{
struct sockaddr_in6 *sinp;
sinp = calloc (1, sizeof (*sinp));
if (!sinp)
{
free (tmp);
return EAI_MEMORY;
}
sinp->sin_port = se->s_port;
memcpy (&sinp->sin_addr, he->h_addr_list[0], he->h_length);
tmp->ai_addr = sinp;
tmp->ai_addrlen = sizeof (sin);
}
break;
case PF_INET:
{
struct sockaddr_in *sinp;
sinp = calloc (1, sizeof (*sinp));
if (!sinp)
{
free (tmp);
return EAI_MEMORY;
}
sinp->sin_port = se->s_port;
memcpy (&sinp->sin_addr, he->h_addr_list[0], he->h_length);
tmp->ai_addr = sinp;
tmp->ai_addrlen = sizeof (sin);
}
break;
default:
free (tmp);
return EAI_NODATA;
}
/* FIXME: If more than one address, create linked list of addrinfo's. */
*res = tmp;
return 0;
}
/* Free `addrinfo' structure AI including associated storage. */
void
freeaddrinfo (struct addrinfo *ai)
{
struct addrinfo *p;
while (ai != NULL)
{
p = ai;
ai = ai->ai_next;
free (p);
}
}
static struct
{
int code;
const char *msg;
}
values[] =
{
{ EAI_ADDRFAMILY, N_("Address family for hostname not supported") },
{ EAI_AGAIN, N_("Temporary failure in name resolution") },
{ EAI_BADFLAGS, N_("Bad value for ai_flags") },
{ EAI_FAIL, N_("Non-recoverable failure in name resolution") },
{ EAI_FAMILY, N_("ai_family not supported") },
{ EAI_MEMORY, N_("Memory allocation failure") },
{ EAI_NODATA, N_("No address associated with hostname") },
{ EAI_NONAME, N_("Name or service not known") },
{ EAI_SERVICE, N_("Servname not supported for ai_socktype") },
{ EAI_SOCKTYPE, N_("ai_socktype not supported") },
{ EAI_SYSTEM, N_("System error") },
};
/* Convert error return from getaddrinfo() to a string. */
const char *
gai_strerror (int code)
{
size_t i;
for (i = 0; i < sizeof (values) / sizeof (values[0]); ++i)
if (values[i].code == code)
return _(values[i].msg);
return _("Unknown error");
}
--- /home/cvs/gsasl/gl/getaddrinfo.h 2004/09/05 20:37:46 NONE
+++ /home/cvs/gsasl/gl/getaddrinfo.h 2004/09/05 20:37:46 1.1
/* Get address information.
Copyright (C) 2004 Free Software Foundation, Inc.
Written by Simon Josefsson <address@hidden>.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#ifndef GETADDRINFO_H
# define GETADDRINFO_H
/* Get getaddrinfo declarations, if available. */
# include <sys/socket.h>
# include <netdb.h>
# if defined HAVE_GETADDRINFO && !HAVE_GETADDRINFO
/* Get socklen_t, struct sockaddr. */
# include <sys/types.h>
/* Structure to contain information about address of a service provider. */
struct addrinfo
{
int ai_flags; /* Input flags. */
int ai_family; /* Protocol family for socket. */
int ai_socktype; /* Socket type. */
int ai_protocol; /* Protocol for socket. */
socklen_t ai_addrlen; /* Length of socket address. */
struct sockaddr *ai_addr; /* Socket address for socket. */
char *ai_canonname; /* Canonical name for service location. */
struct addrinfo *ai_next; /* Pointer to next in list. */
};
/* Possible values for `ai_flags' field in `addrinfo' structure. */
# define AI_PASSIVE 0x0001 /* Socket address is intended for `bind'. */
# define AI_CANONNAME 0x0002 /* Request for canonical name. */
# define AI_NUMERICHOST 0x0004 /* Don't use name resolution. */
# define AI_V4MAPPED 0x0008 /* IPv4 mapped addresses are acceptable. */
# define AI_ALL 0x0010 /* Return IPv4 mapped and IPv6 addresses. */
# define AI_ADDRCONFIG 0x0020 /* Use configuration of this host to choose
returned address type.. */
/* Error values for `getaddrinfo' function. */
# define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */
# define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
# define EAI_AGAIN -3 /* Temporary failure in name resolution. */
# define EAI_FAIL -4 /* Non-recoverable failure in name res. */
# define EAI_NODATA -5 /* No address associated with NAME. */
# define EAI_FAMILY -6 /* `ai_family' not supported. */
# define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */
# define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */
# define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
# define EAI_MEMORY -10 /* Memory allocation failure. */
# define EAI_SYSTEM -11 /* System error returned in `errno'. */
# define EAI_OVERFLOW -12 /* Argument buffer overflow. */
/* Translate name of a service location and/or a service name to set of
socket addresses. */
extern int getaddrinfo (const char *restrict nodename,
const char *restrict servname,
const struct addrinfo *restrict hints,
struct addrinfo **restrict res);
/* Free `addrinfo' structure AI including associated storage. */
extern void freeaddrinfo (struct addrinfo *ai);
/* Convert error return from getaddrinfo() to a string. */
extern const char *gai_strerror (int ecode);
# endif
#endif /* GETADDRINFO_H */
- CVS gsasl/gl,
gsasl-commit <=