source: rtems/cpukit/libnetworking/libc/getnameinfo.c @ 0e16fa45

5
Last change on this file since 0e16fa45 was cb68253, checked in by Sebastian Huber <sebastian.huber@…>, on 09/07/18 at 04:19:02

network: Use kernel/user space header files

Add and use <machine/rtems-bsd-kernel-space.h> and
<machine/rtems-bsd-user-space.h> similar to the libbsd to avoid command
line defines and defines scattered throught the code base.

Simplify cpukit/libnetworking/Makefile.am.

Update #3375.

  • Property mode set to 100644
File size: 1.3 KB
Line 
1#include <machine/rtems-bsd-user-space.h>
2
3/*
4 * Copyright (c) 2016 embedded brains GmbH.  All rights reserved.
5 *
6 *  embedded brains GmbH
7 *  Dornierstr. 4
8 *  82178 Puchheim
9 *  Germany
10 *  <rtems@embedded-brains.de>
11 *
12 * The license and distribution terms for this file may be
13 * found in the file LICENSE in this distribution or at
14 * http://www.rtems.org/license/LICENSE.
15 */
16
17#include <netdb.h>
18#include <sys/socket.h>
19#include <netinet/in.h>
20#include <arpa/inet.h>
21#include <stdio.h>
22
23int
24getnameinfo(const struct sockaddr *sa, socklen_t salen, char *node,
25    size_t nodelen, char *service, size_t servicelen, int flags)
26{
27        int af;
28        const struct sockaddr_in *sa_in = (const struct sockaddr_in *)sa;
29
30        (void) salen;
31
32        af = sa->sa_family;
33        if (af != AF_INET) {
34                return EAI_FAMILY;
35        }
36
37        if ((flags & NI_NAMEREQD) != 0) {
38                return EAI_NONAME;
39        }
40
41        /* FIXME: This return just the address value. Try resolving instead. */
42        if (node != NULL && nodelen > 0) {
43                if (inet_ntop(af, &sa_in->sin_addr, node, nodelen) == NULL) {
44                        return EAI_FAIL;
45                }
46        }
47
48        if (service != NULL && servicelen > 0) {
49                in_port_t port = ntohs(sa_in->sin_port);
50                int rv;
51
52                rv = snprintf(service, servicelen, "%u", port);
53                if (rv <= 0) {
54                        return EAI_FAIL;
55                } else if ((unsigned)rv >= servicelen) {
56                        return EAI_OVERFLOW;
57                }
58        }
59
60        return 0;
61}
Note: See TracBrowser for help on using the repository browser.