syslog code changes fixed (I hope) and mingw port partially done.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@12765 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2002-02-25 18:10:58 +00:00
parent d9dcbd8181
commit 4a878054f9
2 changed files with 98 additions and 15 deletions

View file

@ -7,6 +7,9 @@ Mon Feb 25 15:26:38 2002 Nicola Pero <nicola@brainstorm.co.uk>
2002-02-25 Richard Frith-Macdonald <rfm@gnu.org> 2002-02-25 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GNUmakefile: Move xml and mime classes into an additional * Source/GNUmakefile: Move xml and mime classes into an additional
library, and make base library depend on it. EXPERIMENTAL.
* Tools/gdomap.c: Try to get output working again after last changes.
Add first attempt at MINGW support for getting network interface info.
library, and make base library depend on it. library, and make base library depend on it.
EXPERIMENTAL - activate using 'make add=yes' EXPERIMENTAL - activate using 'make add=yes'

View file

@ -1,5 +1,5 @@
/* This is a simple name server for GNUstep Distributed Objects /* This is a simple name server for GNUstep Distributed Objects
Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc. Copyright (C) 1996, 1997, 1998, 2002 Free Software Foundation, Inc.
Written by: Richard Frith-Macdonald <richard@brainstorm.co.uk> Written by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
Created: October 1996 Created: October 1996
@ -44,7 +44,8 @@
#include <ctype.h> /* for strchr() */ #include <ctype.h> /* for strchr() */
#include <fcntl.h> #include <fcntl.h>
#ifdef __MINGW__ #ifdef __MINGW__
#include <winsock.h> #include <winsock2.h>
#include <ws2tcpip.h>
#include <wininet.h> #include <wininet.h>
#include <process.h> #include <process.h>
#include <sys/time.h> #include <sys/time.h>
@ -125,6 +126,7 @@
#define MAX_EXTRA ((GDO_NAME_MAX_LEN - 2 * IASIZE)/IASIZE) #define MAX_EXTRA ((GDO_NAME_MAX_LEN - 2 * IASIZE)/IASIZE)
typedef unsigned char *uptr; typedef unsigned char *uptr;
int daemon = 0; /* Currently running as daemon. */
int debug = 0; /* Extra debug logging. */ int debug = 0; /* Extra debug logging. */
int nobcst = 0; /* turn off broadcast probing. */ int nobcst = 0; /* turn off broadcast probing. */
int nofork = 0; /* turn off fork() for debugging. */ int nofork = 0; /* turn off fork() for debugging. */
@ -271,16 +273,23 @@ static char ebuf[2048];
#ifdef HAVE_SYSLOG #ifdef HAVE_SYSLOG
int log_perror = 0; int is_daemon = 0;
int log_priority; int log_perror = 0;
int log_priority;
void void
log (int prio) log (int prio)
{ {
syslog (log_priority | prio, ebuf); if (daemon)
{
/* Also log it to stderr? */ syslog (log_priority | prio, ebuf);
if (log_perror || nofork) }
else if (prio == 0)
{
write (0, ebuf, strlen (ebuf));
write (0, "\n", 1);
}
else
{ {
write (2, ebuf, strlen (ebuf)); write (2, ebuf, strlen (ebuf));
write (2, "\n", 1); write (2, "\n", 1);
@ -288,8 +297,11 @@ log (int prio)
if (prio == LOG_CRIT) if (prio == LOG_CRIT)
{ {
syslog (LOG_CRIT, "exiting."); if (daemon)
if (log_perror || nofork) {
syslog (LOG_CRIT, "exiting.");
}
else
{ {
fprintf (stderr, "exiting.\n"); fprintf (stderr, "exiting.\n");
fflush (stderr); fflush (stderr);
@ -299,9 +311,9 @@ log (int prio)
} }
#else #else
#define LOG_CRIT 1 #define LOG_CRIT 2
#define LOG_DEBUG 0 #define LOG_DEBUG 0
#define LOG_ERR 0 #define LOG_ERR 1
#define LOG_INFO 0 #define LOG_INFO 0
#define LOG_WARNING 0 #define LOG_WARNING 0
void void
@ -1146,7 +1158,7 @@ dump_tables()
} }
else else
{ {
log(LOG_INFO); sprintf(ebuf, "Failed to open gdomap.dump file for output\n");
log(LOG_ERR); log(LOG_ERR);
} }
} }
@ -1159,6 +1171,72 @@ dump_tables()
static void static void
init_iface() init_iface()
{ {
#ifdef __MINGW__
INTERFACE_INFO InterfaceList[20];
unsigned long nBytesReturned;
int i, nNumInterfaces;
SOCKET desc = WSASocket(AF_INET, SOCK_DGRAM, 0, 0, 0, 0);
if (desc == SOCKET_ERROR)
{
sprintf(ebuf, "Failed to get a socket. Error %s\n", WSAGetLastError());
log(LOG_CRIT);
exit(1);
}
if (WSAIoctl(desc, SIO_GET_INTERFACE_LIST, 0, 0, &InterfaceList,
sizeof(InterfaceList), &nBytesReturned, 0, 0) == SOCKET_ERROR)
{
sprintf(ebuf, "Failed WSAIoctl. Error %s\n", WSAGetLastError());
log(LOG_CRIT);
exit(1);
}
nNumInterfaces = nBytesReturned / sizeof(INTERFACE_INFO);
/*
* Allocate enough space for all interfaces.
*/
if (addr != 0) free(addr);
addr = (struct in_addr*)malloc((nNumInterfaces+1)*IASIZE);
if (bcok != 0) free(bcok);
bcok = (char*)malloc((nNumInterfaces+1)*sizeof(char));
if (bcst != 0) free(bcst);
bcst = (struct in_addr*)malloc((nNumInterfaces+1)*IASIZE);
if (mask != 0) free(mask);
mask = (struct in_addr*)malloc((nNumInterfaces+1)*IASIZE);
for (i = 0; i < nNumInterfaces; i++)
{
u_long nFlags = InterfaceList[i].iiFlags;
if (nFlags & IFF_UP)
{ /* interface is up */
int broadcast = 0;
int pointopoint = 0;
int loopback = 0;
if (nFlags & IFF_BROADCAST)
{
broadcast = 1;
}
if (nFlags & IFF_POINTTOPOINT)
{
pointopoint = 1;
}
if (nFlags & IFF_LOOPBACK)
{
loopback = 1;
}
addr[interfaces] = ((struct sockaddr_in*)&(InterfaceList[i].iiAddress))->sin_addr;
mask[interfaces] = ((struct sockaddr_in*)&(InterfaceList[i].iiNetmask))->sin_addr;
bcst[interfaces] = ((struct sockaddr_in*)&(InterfaceList[i].iiBroadcastAddress))->sin_addr;
bcok[interfaces] = (broadcast | pointopoint);
interfaces++;
}
}
closesocket(desc);
#else
#ifdef SIOCGIFCONF #ifdef SIOCGIFCONF
struct ifconf ifc; struct ifconf ifc;
struct ifreq ifreq; struct ifreq ifreq;
@ -1357,9 +1435,9 @@ init_iface()
} }
} }
#ifdef __MINGW__ #ifdef __MINGW__
closesocket(desc); closesocket(desc);
#else #else
close(desc); close(desc);
#endif /* __MINGW__ */ #endif /* __MINGW__ */
#else #else
sprintf(ebuf, "I can't find the SIOCGIFCONF ioctl on this platform - " sprintf(ebuf, "I can't find the SIOCGIFCONF ioctl on this platform - "
@ -1367,6 +1445,7 @@ init_iface()
log(LOG_CRIT); log(LOG_CRIT);
exit(1); exit(1);
#endif #endif
#endif
} }
/* /*
@ -4336,6 +4415,7 @@ printf(
#ifndef __MINGW__ /* On Win32, we don't fork */ #ifndef __MINGW__ /* On Win32, we don't fork */
if (nofork == 0) if (nofork == 0)
{ {
daemon = 1;
/* /*
* Now fork off child process to run in background. * Now fork off child process to run in background.
*/ */