Debian Codegraph @

lib/rose_ntop.c

raw
1 /* SPDX-License-Identifier: GPL-2.0+ */
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <unistd.h>
6 #include <fcntl.h>
7 #include <sys/ioctl.h>
8 #include <sys/socket.h>
9 #include <netinet/in.h>
10 #include <arpa/inet.h>
11 #include <string.h>
12 #include <errno.h>
13
14 #include <linux/netdevice.h>
15 #include <linux/if_arp.h>
16 #include <linux/sockios.h>
17 #include <linux/rose.h>
18
19 #include "rt_names.h"
20 #include "utils.h"
21
22 static const char *rose_ntop1(const rose_address *src, char *dst,
23 socklen_t size)
24 {
25 char *p = dst;
26 int i;
27
28 if (size < 10)
29 return NULL;
30
31 for (i = 0; i < 5; i++) {
32 *p++ = '0' + ((src->rose_addr[i] >> 4) & 0xf);
33 *p++ = '0' + ((src->rose_addr[i] ) & 0xf);
34 }
35
36 if (size == 10)
37 return dst;
38
39 *p = '\0';
40
41 return dst;
42 }
43
44 const char *rose_ntop(int af, const void *addr, char *buf, socklen_t buflen)
45 {
46 switch (af) {
47 case AF_ROSE:
48 errno = 0;
49 return rose_ntop1((rose_address *)addr, buf, buflen);
50
51 default:
52 errno = EAFNOSUPPORT;
53 }
54
55 return NULL;
56 }