1 /* -*- Mode: C; tab-width: 4 -*-
3 * Copyright (c) 2002-2004 Apple Computer, Inc. All rights reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
21 #include <sys/types.h>
22 #include <sys/socket.h>
24 #include <netinet/in.h>
27 #include <linux/socket.h>
28 #define IPV6_2292_PKTINFO IPV6_2292PKTINFO
29 #define IPV6_2292_HOPLIMIT IPV6_2292HOPLIMIT
31 // The following are the supported non-linux posix OSes -
32 // netbsd, freebsd and openbsd.
34 #define IPV6_2292_PKTINFO 19
35 #define IPV6_2292_HOPLIMIT 20
43 #ifdef NOT_HAVE_SOCKLEN_T
44 typedef unsigned int socklen_t
;
47 #if !defined(_SS_MAXSIZE)
49 #define sockaddr_storage sockaddr_in6
51 #define sockaddr_storage sockaddr
53 #endif // !defined(_SS_MAXSIZE)
55 #ifndef NOT_HAVE_SA_LEN
56 #define GET_SA_LEN(X) (sizeof(struct sockaddr) > ((struct sockaddr*)&(X))->sa_len ? \
57 sizeof(struct sockaddr) : ((struct sockaddr*)&(X))->sa_len )
59 #define GET_SA_LEN(X) (((struct sockaddr*)&(X))->sa_family == AF_INET ? sizeof(struct sockaddr_in) : \
60 ((struct sockaddr*)&(X))->sa_family == AF_INET6 ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr))
62 #define GET_SA_LEN(X) (((struct sockaddr*)&(X))->sa_family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr))
65 #define IFI_NAME 16 /* same as IFNAMSIZ in <net/if.h> */
66 #define IFI_HADDR 8 /* allow for 64-bit EUI-64 in future */
68 // Renamed from my_in_pktinfo because in_pktinfo is used by Linux.
70 struct my_in_pktinfo
{
71 struct sockaddr_storage ipi_addr
;
72 int ipi_ifindex
; /* received interface index */
73 char ipi_ifname
[IFI_NAME
]; /* received interface name */
76 /* From the text (Stevens, section 20.2): */
77 /* 'As an example of recvmsg we will write a function named recvfrom_flags that */
78 /* is similar to recvfrom but also returns: */
79 /* 1. the returned msg_flags value, */
80 /* 2. the destination addres of the received datagram (from the IP_RECVDSTADDR socket option, and */
81 /* 3. the index of the interface on which the datagram was received (the IP_RECVIF socket option).' */
82 extern ssize_t
recvfrom_flags(int fd
, void *ptr
, size_t nbytes
, int *flagsp
,
83 struct sockaddr
*sa
, socklen_t
*salenptr
, struct my_in_pktinfo
*pktp
, u_char
*ttl
);
86 char ifi_name
[IFI_NAME
]; /* interface name, null terminated */
87 u_char ifi_haddr
[IFI_HADDR
]; /* hardware address */
88 u_short ifi_hlen
; /* #bytes in hardware address: 0, 6, 8 */
89 short ifi_flags
; /* IFF_xxx constants from <net/if.h> */
90 short ifi_myflags
; /* our own IFI_xxx flags */
91 int ifi_index
; /* interface index */
92 struct sockaddr
*ifi_addr
; /* primary address */
93 struct sockaddr
*ifi_netmask
;
94 struct sockaddr
*ifi_brdaddr
; /* broadcast address */
95 struct sockaddr
*ifi_dstaddr
; /* destination address */
96 struct ifi_info
*ifi_next
; /* next of these structures */
99 #if defined(AF_INET6) && HAVE_IPV6 && HAVE_LINUX
100 #define PROC_IFINET6_PATH "/proc/net/if_inet6"
101 extern struct ifi_info
*get_ifi_info_linuxv6(int family
, int doaliases
);
104 #if defined(AF_INET6) && HAVE_IPV6
105 #define INET6_ADDRSTRLEN 46 /*Maximum length of IPv6 address */
110 #define IFI_ALIAS 1 /* ifi_addr is an alias */
112 /* From the text (Stevens, section 16.6): */
113 /* 'Since many programs need to know all the interfaces on a system, we will develop a */
114 /* function of our own named get_ifi_info that returns a linked list of structures, one */
115 /* for each interface that is currently "up."' */
116 extern struct ifi_info
*get_ifi_info(int family
, int doaliases
);
118 /* 'The free_ifi_info function, which takes a pointer that was */
119 /* returned by get_ifi_info and frees all the dynamic memory.' */
120 extern void free_ifi_info(struct ifi_info
*);
122 #ifdef NOT_HAVE_DAEMON
123 extern int daemon(int nochdir
, int noclose
);