File: inet_aton.c

package info (click to toggle)
nut 0.45.5-rel-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,984 kB
  • ctags: 2,146
  • sloc: ansic: 22,216; sh: 1,138; makefile: 405
file content (34 lines) | stat: -rw-r--r-- 760 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* inet_aton.c Ben Collver <collver@softhome.net> */
/* This works if inet_addr exists like it does in CYGWIN */
#include <stddef.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#ifndef INADDR_NONE
#define INADDR_NONE ((unsigned long)-1)
#endif

/* Solaris 5.x defines extern inet_aton() in /usr/include/arpa/inet.h
   However, inet_aton is not in the C library!?  Solaris has inet_addr()
   but does not define INADDR_NONE
 */

#ifndef INADDR_NONE
#define INADDR_NONE -1
#endif

int inet_aton(const char *cp, struct in_addr *addr)
{
	unsigned long	retval;

	if (addr == NULL || cp == NULL)
		return 0;
	retval = inet_addr(cp);
	if (retval == INADDR_NONE) {
		return 0;
	}
	addr->s_addr = retval;
	return 1;
}