mirror of
https://sourceware.org/git/glibc.git
synced 2024-12-21 10:20:06 +00:00
4bca4c1748
1998-04-07 08:51 Ulrich Drepper <drepper@cygnus.com> * iconv/gconv.c: Take care for NULL arguments. * iconv/gconv_dl.c: Make find_func function global. * iconv/gconv_int.h: Add prototype for __gconv_find_func. Add prototypes for ASCII conversion functions. * iconv/gconv_simple.c: Add ASCII conversion functions. * locale/C-ctype.c: Correct charset name. * wcsmbs/Makefile (distribute): Add wcsmbsload.h. (routines): Remove wmemrtowcs and wmemrtombs, add wcsnlen and wcsmbsload. * wcsmbs/btowc.c: Rewrite to use iconv functionality. * wcsmbs/mbrtowc.c: Likewise. * wcsmbs/mbsnrtowcs.c: Likewise. * wcsmbs/mbsrtowcs.c: Likewise. * wcsmbs/wcrtomb.c: Likewise. * wcsmbs/wcsnrtombs.c: Likewise. * wcsmbs/wcsrtombs.c: Likewise. * wcsmbs/wctob.c: Likewise. * wcsmbs/wchar.h: Add prototype for __wcslen, wcsnlen. Remove prototypes for wmemr*. * wcsmbs/wcslen.c: Rename to __wcslen and make wcslen weak alias. * wcsmbs/wcsnlen.c: New file. * wcsmbs/wcsmbsload.c: New file. * wcsmbs/wcsmbsload.h: New file. * manual/filesys.texi: Mention risks of tmpnam and mktemp. * manual/install.texi: Describe some more critical points. * string/string.h: Add prototype for __strnlen. * string/strnlen.c: Rename to __strnlen and make strnlen weak alias. * sysdeps/posix/mktemp.c: Rewrite to allow many more files and much less predictable names. * sysdeps/posix/mkstemp.c: Likewise. 1998-04-05 Andreas Jaeger <aj@arthur.rhein-neckar.de> * manual/libc.texinfo (Top): Change "file namespace" to "local namespace". * manual/socket.texi: Change file namespace to local namespace. (Out-of-Band Data): Remove unneeded variable link. (Host Address Functions): Use uint32_t consequently and add a number of clarifications for IPv4/IPv6, classless addresses. (Internet Namespace): Added some paragraphs about IPv6. Based on suggestions by Francesco Potorti` <F.Potorti@cnuce.cnr.it>. 1998-04-05 Philip Blundell <Philip.Blundell@pobox.com> Update for draft-ietf-ipngwg-bsd-api-new-01.txt: * resolv/netdb.h (getnameinfo): Use `socklen_t' not `size_t'. (NI_NUMERICHOST, et al.): Tidy up and add comments. (AI_NUMERICHOST): Define. (getnodebyname): New prototype. (AI_V4MAPPED, et al.): New constants. * sysdeps/unix/bsd/bsd4.4/bits/sockaddr.h (SA_LEN): New macro.< * sysdeps/generic/bits/sockaddr.h (SA_LEN): Likewise. * sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Add sa_len for socket. * sysdeps/unix/sysv/linux/sa_len.c: New file. * sysdeps/unix/sysv/linux/Dist: Add sa_len.c. * sysdeps/unix/sysv/linux/bits/socket.h: Make multiple #inclusion safe. * sysdeps/generic/bits/sockunion.h: New file, defining sockaddr_union. * sysdeps/unix/sysv/linux/bits/sockunion.h: Likewise. * socket/Makefile (headers): Add bits/sockunion.h. * socket/sys/socket.h: Include <bits/sockunion.h> * inet/netinet/in.h: Include <bits/sockaddr.h> rather than <sys/socket.h>, to avoid getting sockaddr_union defined. * sysdeps/generic/bits/socket.h: Allow inclusion from netinet.in.h. * sysdeps/unix/sysv/linux/bits/socket.h: Likewise. * sysdeps/unix/sysv/linux/mips/bits/socket.h: Likewise. * sysdeps/unix/sysv/linux/if_index.c: Remove use of SIOCGIFCOUNT (2.2.x kernels won't have it). 1998-04-06 21:21 Ulrich Drepper <drepper@cygnus.com> * sysdeps/mach/hurd/bits/ioctls.h: Allow inclusion from hurd/ioctl.h. * sysdeps/mach/hurd/dl-sysdep.c: Use __ptr_t not caddr_t. * iconv/gconv_conf.c: Define MAXPATHLEN if not available before. Patches by UCHIYAMA Yasushi <uch@nop.or.jp>. 1998-04-05 Philip Blundell <Philip.Blundell@pobox.com> * manual/socket.texi (Socket Addresses): Fix a typo. (Interface Naming): New section. 1998-04-05 23:29 Zack Weinberg <zack@rabi.phys.columbia.edu> * configure.in: Check for CC using $ac_tool_prefix, to handle cross-compilation. Use AC_CHECK_TOOL to find MiG. * config.make.in: Add MIG to be substituted. * mach/Machrules: Don't define MIG variable. Patch by Gordon Matzigkeit <gord@profitpress.com>. 1998-04-05 Mark Kettenis <kettenis@phys.uva.nl> * elf/dl-load.c (decompose_rpath): Use local_strdup instead of strdupa to copy rpath. 1998-04-05 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de> * configure.in: Fix gcc version check. * aclocal.m4 (AC_PROG_CHECK_VER): Rewritten to make less confusing. 1998-04-05 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de> * configure.in: Fix gcc version check. * aclocal.m4 (AC_PROG_CHECK_VER): Rewritten to make less confusing. 1998-04-05 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de> * configure.in: Fix gcc version check. * aclocal.m4 (AC_PROG_CHECK_VER): Rewritten to make less confusing. 1998-03-31 Mark Kettenis <kettenis@phys.uva.nl> * sysdeps/unix/bsd/unlockpt.c (unlockpt): Call __ptsname_r instead of ptsname_r. * stdlib/stdlib.h: Change prototype of ptsname_r to make it more like ttyname_r. * sysdeps/unix/sysv/linux/ptsname.c (__ptsname_r): Likewise. * sysdeps/generic/ptsname.c (__ptsname_r): Likewise. * sysdeps/unix/grantpt.c (grantpt): Change check of return value of __ptsname_r accordingly. * login/openpty.c (openpty): Likewise. 1998-06-04 18:47 H.J. Lu <hjl@gnu.org> * libio/fileops.c (_IO_file_xsgetn): Adjust pointers. 1998-04-06 13:58 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de> * Makeconfig (libtypes): Redo H.J. Lu's change of 1998-03-27. * Makerules: Readd missing rule for $(objpfx)stamp.oS. 1998-04-06 Thorsten Kukuk <kukuk@vt.uni-paderborn.de> * nis/ypclnt.c: Don't give YPERR_RPC back, use the do_ypcall return value for better error checking.
260 lines
5.5 KiB
C
260 lines
5.5 KiB
C
/* Copyright (C) 1997, 1998 Free Software Foundation, Inc.
|
|
This file is part of the GNU C Library.
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Library General Public License as
|
|
published by the Free Software Foundation; either version 2 of the
|
|
License, or (at your option) any later version.
|
|
|
|
The GNU C Library 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
|
|
Library General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
|
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
Boston, MA 02111-1307, USA. */
|
|
|
|
#include <errno.h>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <net/if.h>
|
|
#include <sys/socket.h>
|
|
#include <sys/ioctl.h>
|
|
#include <bits/libc-lock.h>
|
|
|
|
/* Try to get a socket to talk to the kernel. */
|
|
#if defined SIOGIFINDEX || defined SIOGIFNAME
|
|
static int
|
|
internal_function
|
|
opensock (void)
|
|
{
|
|
/* Cache the last AF that worked, to avoid many redundant calls to
|
|
socket(). */
|
|
static int sock_af = -1;
|
|
int fd = -1;
|
|
__libc_lock_define_initialized (static, lock);
|
|
|
|
if (sock_af != -1)
|
|
{
|
|
fd = socket (sock_af, SOCK_DGRAM, 0);
|
|
if (fd != -1)
|
|
return fd;
|
|
}
|
|
|
|
__libc_lock_lock (lock);
|
|
|
|
if (sock_af != -1)
|
|
fd = socket (sock_af, SOCK_DGRAM, 0);
|
|
|
|
if (fd == -1)
|
|
{
|
|
fd = socket (sock_af = AF_INET6, SOCK_DGRAM, 0);
|
|
if (fd < 0)
|
|
fd = socket (sock_af = AF_INET, SOCK_DGRAM, 0);
|
|
if (fd < 0)
|
|
fd = socket (sock_af = AF_IPX, SOCK_DGRAM, 0);
|
|
if (fd < 0)
|
|
fd = socket (sock_af = AF_AX25, SOCK_DGRAM, 0);
|
|
if (fd < 0)
|
|
fd = socket (sock_af = AF_APPLETALK, SOCK_DGRAM, 0);
|
|
}
|
|
|
|
__libc_lock_unlock (lock);
|
|
return fd;
|
|
}
|
|
#endif
|
|
|
|
unsigned int
|
|
if_nametoindex (const char *ifname)
|
|
{
|
|
#ifndef SIOGIFINDEX
|
|
__set_errno (ENOSYS);
|
|
return 0;
|
|
#else
|
|
struct ifreq ifr;
|
|
int fd = opensock ();
|
|
|
|
if (fd < 0)
|
|
return 0;
|
|
|
|
strncpy (ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
|
|
if (ioctl (fd, SIOGIFINDEX, &ifr) < 0)
|
|
{
|
|
int saved_errno = errno;
|
|
close (fd);
|
|
if (saved_errno == EINVAL)
|
|
__set_errno (ENOSYS);
|
|
return 0;
|
|
}
|
|
close (fd);
|
|
return ifr.ifr_ifindex;
|
|
#endif
|
|
}
|
|
|
|
void
|
|
if_freenameindex (struct if_nameindex *ifn)
|
|
{
|
|
struct if_nameindex *ptr = ifn;
|
|
while (ptr->if_name || ptr->if_index)
|
|
{
|
|
if (ptr->if_name)
|
|
free (ptr->if_name);
|
|
++ptr;
|
|
}
|
|
free (ifn);
|
|
}
|
|
|
|
struct if_nameindex *
|
|
if_nameindex (void)
|
|
{
|
|
#ifndef SIOGIFINDEX
|
|
__set_errno (ENOSYS);
|
|
return NULL;
|
|
#else
|
|
int fd = opensock ();
|
|
struct ifconf ifc;
|
|
unsigned int nifs, i;
|
|
int rq_len;
|
|
struct if_nameindex *idx = NULL;
|
|
static int new_siocgifconf = 1;
|
|
#define RQ_IFS 4
|
|
|
|
if (fd < 0)
|
|
return NULL;
|
|
|
|
ifc.ifc_buf = NULL;
|
|
|
|
/* We may be able to get the needed buffer size directly, rather than
|
|
guessing. */
|
|
if (new_siocgifconf)
|
|
{
|
|
ifc.ifc_buf = NULL;
|
|
ifc.ifc_len = 0;
|
|
if (ioctl (fd, SIOCGIFCONF, &ifc) < 0 || ifc.ifc_len == 0)
|
|
{
|
|
new_siocgifconf = 0;
|
|
rq_len = RQ_IFS * sizeof (struct ifreq);
|
|
}
|
|
else
|
|
rq_len = ifc.ifc_len;
|
|
}
|
|
else
|
|
rq_len = RQ_IFS * sizeof (struct ifreq);
|
|
|
|
/* Read all the interfaces out of the kernel. */
|
|
do
|
|
{
|
|
ifc.ifc_buf = alloca (ifc.ifc_len = rq_len);
|
|
if ((ifc.ifc_buf == NULL) || (ioctl (fd, SIOCGIFCONF, &ifc) < 0))
|
|
{
|
|
close (fd);
|
|
return NULL;
|
|
}
|
|
rq_len *= 2;
|
|
}
|
|
while (ifc.ifc_len == rq_len && new_siocgifconf == 0);
|
|
|
|
nifs = ifc.ifc_len / sizeof (struct ifreq);
|
|
|
|
idx = malloc ((nifs + 1) * sizeof (struct if_nameindex));
|
|
if (idx == NULL)
|
|
{
|
|
close (fd);
|
|
return NULL;
|
|
}
|
|
|
|
for (i = 0; i < nifs; ++i)
|
|
{
|
|
struct ifreq *ifr = &ifc.ifc_req[i];
|
|
idx[i].if_name = __strdup (ifr->ifr_name);
|
|
if (idx[i].if_name == NULL
|
|
|| ioctl (fd, SIOGIFINDEX, ifr) < 0)
|
|
{
|
|
int saved_errno = errno;
|
|
unsigned int j;
|
|
|
|
for (j = 0; j < i; ++j)
|
|
free (idx[j].if_name);
|
|
free (idx);
|
|
close (fd);
|
|
if (saved_errno == EINVAL)
|
|
__set_errno (ENOSYS);
|
|
return NULL;
|
|
}
|
|
idx[i].if_index = ifr->ifr_ifindex;
|
|
}
|
|
|
|
idx[i].if_index = 0;
|
|
idx[i].if_name = NULL;
|
|
|
|
close (fd);
|
|
return idx;
|
|
#endif
|
|
}
|
|
|
|
char *
|
|
if_indextoname (unsigned int ifindex, char *ifname)
|
|
{
|
|
#ifndef SIOGIFINDEX
|
|
__set_errno (ENOSYS);
|
|
return NULL;
|
|
#else
|
|
struct if_nameindex *idx;
|
|
struct if_nameindex *p;
|
|
char *result = NULL;
|
|
|
|
#ifdef SIOGIFNAME
|
|
/* We may be able to do the conversion directly, rather than searching a
|
|
list. This ioctl is not present in kernels before version 2.1.50. */
|
|
struct ifreq ifr;
|
|
int fd;
|
|
static int siogifname_works = 1;
|
|
|
|
if (siogifname_works)
|
|
{
|
|
int serrno = errno;
|
|
|
|
fd = opensock ();
|
|
|
|
if (fd < 0)
|
|
return NULL;
|
|
|
|
ifr.ifr_ifindex = ifindex;
|
|
if (ioctl (fd, SIOGIFNAME, &ifr) < 0)
|
|
{
|
|
if (errno == EINVAL)
|
|
siogifname_works = 0; /* Don't make the same mistake twice. */
|
|
}
|
|
else
|
|
{
|
|
close (fd);
|
|
return strncpy (ifname, ifr.ifr_name, IFNAMSIZ);
|
|
}
|
|
|
|
close (fd);
|
|
|
|
__set_errno (serrno);
|
|
}
|
|
#endif
|
|
|
|
idx = if_nameindex ();
|
|
|
|
if (idx != NULL)
|
|
{
|
|
for (p = idx; p->if_index || p->if_name; ++p)
|
|
if (p->if_index == ifindex)
|
|
{
|
|
result = strncpy (ifname, p->if_name, IFNAMSIZ);
|
|
break;
|
|
}
|
|
|
|
if_freenameindex (idx);
|
|
}
|
|
return result;
|
|
#endif
|
|
}
|