Fixed ZDE build - missing header file
[ZeXOS.git] / libc / socket / inet_ntop.c
blob20e6e442f10bdcdf60305b4d697d31b9311c14a7
1 /*
2 * ZeX/OS
3 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
4 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include <stdio.h>
22 #include <string.h>
23 #include <arpa/inet.h>
24 #include <sys/socket.h>
25 #include <netinet/in.h>
27 const char *inet_ntop (int af, const void *src, char *dst, size_t cnt)
29 if (!src || !dst || !cnt)
30 return (char *) 0;
32 if (af == AF_INET && cnt > 15) {
33 unsigned *ip = (unsigned *) src;
35 unsigned char a = (unsigned char) *ip;
36 unsigned char b = (unsigned char) (*ip >> 8);
37 unsigned char c = (unsigned char) (*ip >> 16);
38 unsigned char d = (unsigned char) (*ip >> 24);
40 sprintf (dst, "%d.%d.%d.%d", a, b, c, d);
42 return dst;
45 if (af == AF_INET6 && cnt > 39) {
46 unsigned short ip[8];
47 memcpy (ip, src, 16);
49 sprintf (dst, "%x:%x:%x:%x:%x:%x:%x:%x", htons (ip[0]), htons (ip[1]), htons (ip[2]), htons (ip[3]),
50 htons (ip[4]), htons (ip[5]), htons (ip[6]), htons (ip[7]));
52 return dst;
55 return (char *) 0;