xref: /titanic_50/usr/src/cmd/cmd-inet/usr.lib/mdnsd/mDNSUNP.h (revision 5ffb0c9b03b5149ff4f5821a62be4a52408ada2a)
14b22b933Srs200217 /* -*- Mode: C; tab-width: 4 -*-
24b22b933Srs200217  *
34b22b933Srs200217  * Copyright (c) 2002-2004 Apple Computer, Inc. All rights reserved.
44b22b933Srs200217  *
54b22b933Srs200217  * Licensed under the Apache License, Version 2.0 (the "License");
64b22b933Srs200217  * you may not use this file except in compliance with the License.
74b22b933Srs200217  * You may obtain a copy of the License at
84b22b933Srs200217  *
94b22b933Srs200217  *     http://www.apache.org/licenses/LICENSE-2.0
104b22b933Srs200217  *
114b22b933Srs200217  * Unless required by applicable law or agreed to in writing, software
124b22b933Srs200217  * distributed under the License is distributed on an "AS IS" BASIS,
134b22b933Srs200217  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
144b22b933Srs200217  * See the License for the specific language governing permissions and
154b22b933Srs200217  * limitations under the License.
164b22b933Srs200217  */
174b22b933Srs200217 
184b22b933Srs200217 #ifndef __mDNSUNP_h
194b22b933Srs200217 #define __mDNSUNP_h
204b22b933Srs200217 
214b22b933Srs200217 #include <sys/types.h>
224b22b933Srs200217 #include <sys/socket.h>
234b22b933Srs200217 #include <net/if.h>
244b22b933Srs200217 #include <netinet/in.h>
254b22b933Srs200217 
264b22b933Srs200217 #ifdef HAVE_LINUX
274b22b933Srs200217 #include <linux/socket.h>
28*5ffb0c9bSToomas Soome #define IPV6_2292_PKTINFO  IPV6_2292PKTINFO
29*5ffb0c9bSToomas Soome #define IPV6_2292_HOPLIMIT IPV6_2292HOPLIMIT
30*5ffb0c9bSToomas Soome #else
31*5ffb0c9bSToomas Soome // The following are the supported non-linux posix OSes -
32*5ffb0c9bSToomas Soome // netbsd, freebsd and openbsd.
33*5ffb0c9bSToomas Soome #if HAVE_IPV6
34*5ffb0c9bSToomas Soome #define IPV6_2292_PKTINFO  19
35*5ffb0c9bSToomas Soome #define IPV6_2292_HOPLIMIT 20
36*5ffb0c9bSToomas Soome #endif
374b22b933Srs200217 #endif
384b22b933Srs200217 
394b22b933Srs200217 #ifdef  __cplusplus
404b22b933Srs200217 extern "C" {
414b22b933Srs200217 #endif
424b22b933Srs200217 
434b22b933Srs200217 #ifdef NOT_HAVE_SOCKLEN_T
444b22b933Srs200217 typedef unsigned int socklen_t;
454b22b933Srs200217 #endif
464b22b933Srs200217 
474b22b933Srs200217 #if !defined(_SS_MAXSIZE)
484b22b933Srs200217 #if HAVE_IPV6
494b22b933Srs200217 #define sockaddr_storage sockaddr_in6
504b22b933Srs200217 #else
514b22b933Srs200217 #define sockaddr_storage sockaddr
524b22b933Srs200217 #endif // HAVE_IPV6
534b22b933Srs200217 #endif // !defined(_SS_MAXSIZE)
544b22b933Srs200217 
554b22b933Srs200217 #ifndef NOT_HAVE_SA_LEN
564b22b933Srs200217 #define GET_SA_LEN(X) (sizeof(struct sockaddr) > ((struct sockaddr*)&(X))->sa_len ? \
574b22b933Srs200217                        sizeof(struct sockaddr) : ((struct sockaddr*)&(X))->sa_len   )
584b22b933Srs200217 #elif HAVE_IPV6
594b22b933Srs200217 #define GET_SA_LEN(X) (((struct sockaddr*)&(X))->sa_family == AF_INET  ? sizeof(struct sockaddr_in) : \
604b22b933Srs200217                        ((struct sockaddr*)&(X))->sa_family == AF_INET6 ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr))
614b22b933Srs200217 #else
624b22b933Srs200217 #define GET_SA_LEN(X) (((struct sockaddr*)&(X))->sa_family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr))
634b22b933Srs200217 #endif
644b22b933Srs200217 
654b22b933Srs200217 #define IFI_NAME    16          /* same as IFNAMSIZ in <net/if.h> */
664b22b933Srs200217 #define IFI_HADDR    8          /* allow for 64-bit EUI-64 in future */
674b22b933Srs200217 
684b22b933Srs200217 // Renamed from my_in_pktinfo because in_pktinfo is used by Linux.
694b22b933Srs200217 
704b22b933Srs200217 struct my_in_pktinfo {
714b22b933Srs200217     struct sockaddr_storage ipi_addr;
724b22b933Srs200217     int ipi_ifindex;                                /* received interface index */
734b22b933Srs200217     char ipi_ifname[IFI_NAME];                      /* received interface name  */
744b22b933Srs200217 };
754b22b933Srs200217 
764b22b933Srs200217 /* From the text (Stevens, section 20.2): */
774b22b933Srs200217 /* 'As an example of recvmsg we will write a function named recvfrom_flags that */
784b22b933Srs200217 /* is similar to recvfrom but also returns: */
794b22b933Srs200217 /*	1. the returned msg_flags value, */
804b22b933Srs200217 /*	2. the destination addres of the received datagram (from the IP_RECVDSTADDR socket option, and */
814b22b933Srs200217 /*	3. the index of the interface on which the datagram was received (the IP_RECVIF socket option).' */
824b22b933Srs200217 extern ssize_t recvfrom_flags(int fd, void *ptr, size_t nbytes, int *flagsp,
834b22b933Srs200217                               struct sockaddr *sa, socklen_t *salenptr, struct my_in_pktinfo *pktp, u_char *ttl);
844b22b933Srs200217 
854b22b933Srs200217 struct ifi_info {
864b22b933Srs200217     char ifi_name[IFI_NAME];    /* interface name, null terminated */
874b22b933Srs200217     u_char ifi_haddr[IFI_HADDR]; /* hardware address */
884b22b933Srs200217     u_short ifi_hlen;           /* #bytes in hardware address: 0, 6, 8 */
894b22b933Srs200217     short ifi_flags;            /* IFF_xxx constants from <net/if.h> */
904b22b933Srs200217     short ifi_myflags;          /* our own IFI_xxx flags */
914b22b933Srs200217     int ifi_index;              /* interface index */
924b22b933Srs200217     struct sockaddr  *ifi_addr; /* primary address */
934b22b933Srs200217     struct sockaddr  *ifi_netmask;
944b22b933Srs200217     struct sockaddr  *ifi_brdaddr; /* broadcast address */
954b22b933Srs200217     struct sockaddr  *ifi_dstaddr; /* destination address */
964b22b933Srs200217     struct ifi_info  *ifi_next; /* next of these structures */
974b22b933Srs200217 };
984b22b933Srs200217 
994b22b933Srs200217 #if defined(AF_INET6) && HAVE_IPV6 && HAVE_LINUX
1004b22b933Srs200217 #define PROC_IFINET6_PATH "/proc/net/if_inet6"
1014b22b933Srs200217 extern struct ifi_info  *get_ifi_info_linuxv6(int family, int doaliases);
1024b22b933Srs200217 #endif
1034b22b933Srs200217 
1044b22b933Srs200217 #if defined(AF_INET6) && HAVE_IPV6
1054b22b933Srs200217 #define INET6_ADDRSTRLEN 46 /*Maximum length of IPv6 address */
1064b22b933Srs200217 #endif
1074b22b933Srs200217 
1084b22b933Srs200217 
1094b22b933Srs200217 
1104b22b933Srs200217 #define IFI_ALIAS   1           /* ifi_addr is an alias */
1114b22b933Srs200217 
1124b22b933Srs200217 /* From the text (Stevens, section 16.6): */
1134b22b933Srs200217 /* 'Since many programs need to know all the interfaces on a system, we will develop a */
1144b22b933Srs200217 /* function of our own named get_ifi_info that returns a linked list of structures, one */
1154b22b933Srs200217 /* for each interface that is currently "up."' */
1164b22b933Srs200217 extern struct ifi_info  *get_ifi_info(int family, int doaliases);
1174b22b933Srs200217 
1184b22b933Srs200217 /* 'The free_ifi_info function, which takes a pointer that was */
1194b22b933Srs200217 /* returned by get_ifi_info and frees all the dynamic memory.' */
1204b22b933Srs200217 extern void             free_ifi_info(struct ifi_info *);
1214b22b933Srs200217 
1224b22b933Srs200217 #ifdef NOT_HAVE_DAEMON
1234b22b933Srs200217 extern int daemon(int nochdir, int noclose);
1244b22b933Srs200217 #endif
1254b22b933Srs200217 
1264b22b933Srs200217 #ifdef  __cplusplus
1274b22b933Srs200217 }
1284b22b933Srs200217 #endif
1294b22b933Srs200217 
1304b22b933Srs200217 #endif
131