1 /* PIPServer - A deamon for finger protocol v2
2 *
3 * Copyright (C) 1999-2001 Michael Baumer
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
19 *
20 * $Id: compat.c,v 1.5 2001/07/04 08:01:45 baumi Exp $
21 */
22
23 /* Compatibility library for systems with missing functions */
24
25
26 #include <config.h> /* for HAVE_* defines */
27 #include "compat.h"
28
29 #ifndef HAVE_STRDUP
30
31 #include <stdlib.h>
32 #include <string.h>
33
strdup(const char * s)34 char *strdup(const char *s)
35 {
36 char *dest;
37
38 dest = (char *)malloc(strlen(s));
39
40 if (dest)
41 strcpy(dest, s);
42
43 return(dest);
44 }
45
46 #endif /* HAVE_STRDUP */
47
48 #if !defined(HAVE_INET_NTOA) || defined(BROKEN_INET_NTOA)
49
50 #include <sys/types.h>
51 #include <netinet/in.h>
52 #include <arpa/inet.h>
53 #include <stdio.h>
54
55 /*
56 * Convert network-format internet address
57 * to base 256 d.d.d.d representation.
58 */
59
inet_ntoa(struct in_addr in)60 char *inet_ntoa(struct in_addr in)
61 {
62 static char b[18];
63 register char *p;
64
65 p = (char *)∈
66 #define UC(b) (((int)b)&0xff)
67
68 #ifdef HAVE_SNPRINTF
69 (void)snprintf(b, sizeof(b),
70 #else
71 (void)sprintf(b,
72 #endif
73 "%d.%d.%d.%d", UC(p[0]), UC(p[1]), UC(p[2]), UC(p[3]));
74 return (b);
75 }
76
77 #endif /* HAVE_INET_NTOA */
78