xref: /titanic_50/usr/src/lib/libdns_sd/common/dnssd_clientlib.c (revision 5ffb0c9b03b5149ff4f5821a62be4a52408ada2a)
14b22b933Srs200217 /* -*- Mode: C; tab-width: 4 -*-
24b22b933Srs200217  *
34b22b933Srs200217  * Copyright (c) 2004, Apple Computer, Inc. All rights reserved.
44b22b933Srs200217  *
54b22b933Srs200217  * Redistribution and use in source and binary forms, with or without
64b22b933Srs200217  * modification, are permitted provided that the following conditions are met:
74b22b933Srs200217  *
84b22b933Srs200217  * 1.  Redistributions of source code must retain the above copyright notice,
94b22b933Srs200217  *     this list of conditions and the following disclaimer.
104b22b933Srs200217  * 2.  Redistributions in binary form must reproduce the above copyright notice,
114b22b933Srs200217  *     this list of conditions and the following disclaimer in the documentation
124b22b933Srs200217  *     and/or other materials provided with the distribution.
134b22b933Srs200217  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of its
144b22b933Srs200217  *     contributors may be used to endorse or promote products derived from this
154b22b933Srs200217  *     software without specific prior written permission.
164b22b933Srs200217  *
174b22b933Srs200217  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
184b22b933Srs200217  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
194b22b933Srs200217  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
204b22b933Srs200217  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
214b22b933Srs200217  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
224b22b933Srs200217  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
234b22b933Srs200217  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
244b22b933Srs200217  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
254b22b933Srs200217  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
264b22b933Srs200217  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
274b22b933Srs200217  */
284b22b933Srs200217 
294b22b933Srs200217 #include <stdlib.h>
304b22b933Srs200217 #include <string.h>
314b22b933Srs200217 
324b22b933Srs200217 #include "dns_sd.h"
334b22b933Srs200217 
344b22b933Srs200217 #if MDNS_BUILDINGSHAREDLIBRARY || MDNS_BUILDINGSTUBLIBRARY
354b22b933Srs200217 #pragma export on
364b22b933Srs200217 #endif
374b22b933Srs200217 
384b22b933Srs200217 #if defined(_WIN32)
394b22b933Srs200217 // disable warning "conversion from <data> to uint16_t"
404b22b933Srs200217 #pragma warning(disable:4244)
41*5ffb0c9bSToomas Soome #define strncasecmp _strnicmp
42*5ffb0c9bSToomas Soome #define strcasecmp _stricmp
434b22b933Srs200217 #endif
444b22b933Srs200217 
454b22b933Srs200217 /*********************************************************************************************
464b22b933Srs200217 *
474b22b933Srs200217 *  Supporting Functions
484b22b933Srs200217 *
494b22b933Srs200217 *********************************************************************************************/
504b22b933Srs200217 
51*5ffb0c9bSToomas Soome #define mDNSIsDigit(X)     ((X) >= '0' && (X) <= '9')
52*5ffb0c9bSToomas Soome 
53*5ffb0c9bSToomas Soome // DomainEndsInDot returns 1 if name ends with a dot, 0 otherwise
54*5ffb0c9bSToomas Soome // (DNSServiceConstructFullName depends this returning 1 for true, rather than any non-zero value meaning true)
554b22b933Srs200217 
DomainEndsInDot(const char * dom)564b22b933Srs200217 static int DomainEndsInDot(const char *dom)
574b22b933Srs200217 {
584b22b933Srs200217     while (dom[0] && dom[1])
594b22b933Srs200217     {
604b22b933Srs200217         if (dom[0] == '\\') // advance past escaped byte sequence
614b22b933Srs200217         {
62*5ffb0c9bSToomas Soome             if (mDNSIsDigit(dom[1]) && mDNSIsDigit(dom[2]) && mDNSIsDigit(dom[3]))
634b22b933Srs200217                 dom += 4;           // If "\ddd"    then skip four
644b22b933Srs200217             else dom += 2;          // else if "\x" then skip two
654b22b933Srs200217         }
664b22b933Srs200217         else dom++;                 // else goto next character
674b22b933Srs200217     }
684b22b933Srs200217     return (dom[0] == '.');
694b22b933Srs200217 }
704b22b933Srs200217 
InternalTXTRecordSearch(uint16_t txtLen,const void * txtRecord,const char * key,unsigned long * keylen)714b22b933Srs200217 static uint8_t *InternalTXTRecordSearch
724b22b933Srs200217 (
734b22b933Srs200217     uint16_t txtLen,
744b22b933Srs200217     const void       *txtRecord,
754b22b933Srs200217     const char       *key,
764b22b933Srs200217     unsigned long    *keylen
774b22b933Srs200217 )
784b22b933Srs200217 {
794b22b933Srs200217     uint8_t *p = (uint8_t*)txtRecord;
804b22b933Srs200217     uint8_t *e = p + txtLen;
814b22b933Srs200217     *keylen = (unsigned long) strlen(key);
824b22b933Srs200217     while (p<e)
834b22b933Srs200217     {
844b22b933Srs200217         uint8_t *x = p;
854b22b933Srs200217         p += 1 + p[0];
86*5ffb0c9bSToomas Soome         if (p <= e && *keylen <= x[0] && !strncasecmp(key, (char*)x+1, *keylen))
874b22b933Srs200217             if (*keylen == x[0] || x[1+*keylen] == '=') return(x);
884b22b933Srs200217     }
894b22b933Srs200217     return(NULL);
904b22b933Srs200217 }
914b22b933Srs200217 
924b22b933Srs200217 /*********************************************************************************************
934b22b933Srs200217 *
944b22b933Srs200217 *  General Utility Functions
954b22b933Srs200217 *
964b22b933Srs200217 *********************************************************************************************/
974b22b933Srs200217 
98*5ffb0c9bSToomas Soome // Note: Need to make sure we don't write more than kDNSServiceMaxDomainName (1009) bytes to fullName
99*5ffb0c9bSToomas Soome // In earlier builds this constant was defined to be 1005, so to avoid buffer overruns on clients
100*5ffb0c9bSToomas Soome // compiled with that constant we'll actually limit the output to 1005 bytes.
101*5ffb0c9bSToomas Soome 
DNSServiceConstructFullName(char * const fullName,const char * const service,const char * const regtype,const char * const domain)102*5ffb0c9bSToomas Soome DNSServiceErrorType DNSSD_API DNSServiceConstructFullName
1034b22b933Srs200217 (
104*5ffb0c9bSToomas Soome     char       *const fullName,
105*5ffb0c9bSToomas Soome     const char *const service,      // May be NULL
106*5ffb0c9bSToomas Soome     const char *const regtype,
107*5ffb0c9bSToomas Soome     const char *const domain
1084b22b933Srs200217 )
1094b22b933Srs200217 {
110*5ffb0c9bSToomas Soome     const size_t len = !regtype ? 0 : strlen(regtype) - DomainEndsInDot(regtype);
1114b22b933Srs200217     char       *fn   = fullName;
112*5ffb0c9bSToomas Soome     char *const lim  = fullName + 1005;
1134b22b933Srs200217     const char *s    = service;
1144b22b933Srs200217     const char *r    = regtype;
1154b22b933Srs200217     const char *d    = domain;
1164b22b933Srs200217 
117*5ffb0c9bSToomas Soome     // regtype must be at least "x._udp" or "x._tcp"
118*5ffb0c9bSToomas Soome     if (len < 6 || !domain || !domain[0]) return kDNSServiceErr_BadParam;
119*5ffb0c9bSToomas Soome     if (strncasecmp((regtype + len - 4), "_tcp", 4) && strncasecmp((regtype + len - 4), "_udp", 4)) return kDNSServiceErr_BadParam;
120*5ffb0c9bSToomas Soome 
121*5ffb0c9bSToomas Soome     if (service && *service)
1224b22b933Srs200217     {
1234b22b933Srs200217         while (*s)
1244b22b933Srs200217         {
125*5ffb0c9bSToomas Soome             unsigned char c = *s++;             // Needs to be unsigned, or values like 0xFF will be interpreted as < 32
126*5ffb0c9bSToomas Soome             if (c <= ' ')                       // Escape non-printable characters
1274b22b933Srs200217             {
128*5ffb0c9bSToomas Soome                 if (fn+4 >= lim) goto fail;
1294b22b933Srs200217                 *fn++ = '\\';
130*5ffb0c9bSToomas Soome                 *fn++ = '0' + (c / 100);
131*5ffb0c9bSToomas Soome                 *fn++ = '0' + (c /  10) % 10;
132*5ffb0c9bSToomas Soome                 c     = '0' + (c      ) % 10;
1334b22b933Srs200217             }
134*5ffb0c9bSToomas Soome             else if (c == '.' || (c == '\\'))   // Escape dot and backslash literals
135*5ffb0c9bSToomas Soome             {
136*5ffb0c9bSToomas Soome                 if (fn+2 >= lim) goto fail;
137*5ffb0c9bSToomas Soome                 *fn++ = '\\';
138*5ffb0c9bSToomas Soome             }
139*5ffb0c9bSToomas Soome             else
140*5ffb0c9bSToomas Soome             if (fn+1 >= lim) goto fail;
1414b22b933Srs200217             *fn++ = (char)c;
1424b22b933Srs200217         }
1434b22b933Srs200217         *fn++ = '.';
1444b22b933Srs200217     }
1454b22b933Srs200217 
146*5ffb0c9bSToomas Soome     while (*r) if (fn+1 >= lim) goto fail;else *fn++ = *r++;
147*5ffb0c9bSToomas Soome     if (!DomainEndsInDot(regtype)) { if (fn+1 >= lim) goto fail;else *fn++ = '.';}
1484b22b933Srs200217 
149*5ffb0c9bSToomas Soome     while (*d) if (fn+1 >= lim) goto fail;else *fn++ = *d++;
150*5ffb0c9bSToomas Soome     if (!DomainEndsInDot(domain)) { if (fn+1 >= lim) goto fail;else *fn++ = '.';}
151*5ffb0c9bSToomas Soome 
1524b22b933Srs200217     *fn = '\0';
153*5ffb0c9bSToomas Soome     return kDNSServiceErr_NoError;
154*5ffb0c9bSToomas Soome 
155*5ffb0c9bSToomas Soome fail:
156*5ffb0c9bSToomas Soome     *fn = '\0';
157*5ffb0c9bSToomas Soome     return kDNSServiceErr_BadParam;
1584b22b933Srs200217 }
1594b22b933Srs200217 
1604b22b933Srs200217 /*********************************************************************************************
1614b22b933Srs200217 *
1624b22b933Srs200217 *   TXT Record Construction Functions
1634b22b933Srs200217 *
1644b22b933Srs200217 *********************************************************************************************/
1654b22b933Srs200217 
1664b22b933Srs200217 typedef struct _TXTRecordRefRealType
1674b22b933Srs200217 {
1684b22b933Srs200217     uint8_t  *buffer;       // Pointer to data
1694b22b933Srs200217     uint16_t buflen;        // Length of buffer
1704b22b933Srs200217     uint16_t datalen;       // Length currently in use
1714b22b933Srs200217     uint16_t malloced;  // Non-zero if buffer was allocated via malloc()
1724b22b933Srs200217 } TXTRecordRefRealType;
1734b22b933Srs200217 
1744b22b933Srs200217 #define txtRec ((TXTRecordRefRealType*)txtRecord)
1754b22b933Srs200217 
1764b22b933Srs200217 // The opaque storage defined in the public dns_sd.h header is 16 bytes;
1774b22b933Srs200217 // make sure we don't exceed that.
178*5ffb0c9bSToomas Soome struct CompileTimeAssertionCheck_dnssd_clientlib
1794b22b933Srs200217 {
1804b22b933Srs200217     char assert0[(sizeof(TXTRecordRefRealType) <= 16) ? 1 : -1];
1814b22b933Srs200217 };
1824b22b933Srs200217 
TXTRecordCreate(TXTRecordRef * txtRecord,uint16_t bufferLen,void * buffer)1834b22b933Srs200217 void DNSSD_API TXTRecordCreate
1844b22b933Srs200217 (
1854b22b933Srs200217     TXTRecordRef     *txtRecord,
1864b22b933Srs200217     uint16_t bufferLen,
1874b22b933Srs200217     void             *buffer
1884b22b933Srs200217 )
1894b22b933Srs200217 {
1904b22b933Srs200217     txtRec->buffer   = buffer;
1914b22b933Srs200217     txtRec->buflen   = buffer ? bufferLen : (uint16_t)0;
1924b22b933Srs200217     txtRec->datalen  = 0;
1934b22b933Srs200217     txtRec->malloced = 0;
1944b22b933Srs200217 }
1954b22b933Srs200217 
TXTRecordDeallocate(TXTRecordRef * txtRecord)1964b22b933Srs200217 void DNSSD_API TXTRecordDeallocate(TXTRecordRef *txtRecord)
1974b22b933Srs200217 {
1984b22b933Srs200217     if (txtRec->malloced) free(txtRec->buffer);
1994b22b933Srs200217 }
2004b22b933Srs200217 
TXTRecordSetValue(TXTRecordRef * txtRecord,const char * key,uint8_t valueSize,const void * value)2014b22b933Srs200217 DNSServiceErrorType DNSSD_API TXTRecordSetValue
2024b22b933Srs200217 (
2034b22b933Srs200217     TXTRecordRef     *txtRecord,
2044b22b933Srs200217     const char       *key,
2054b22b933Srs200217     uint8_t valueSize,
2064b22b933Srs200217     const void       *value
2074b22b933Srs200217 )
2084b22b933Srs200217 {
2094b22b933Srs200217     uint8_t *start, *p;
2104b22b933Srs200217     const char *k;
2114b22b933Srs200217     unsigned long keysize, keyvalsize;
2124b22b933Srs200217 
2134b22b933Srs200217     for (k = key; *k; k++) if (*k < 0x20 || *k > 0x7E || *k == '=') return(kDNSServiceErr_Invalid);
2144b22b933Srs200217     keysize = (unsigned long)(k - key);
2154b22b933Srs200217     keyvalsize = 1 + keysize + (value ? (1 + valueSize) : 0);
2164b22b933Srs200217     if (keysize < 1 || keyvalsize > 255) return(kDNSServiceErr_Invalid);
2174b22b933Srs200217     (void)TXTRecordRemoveValue(txtRecord, key);
2184b22b933Srs200217     if (txtRec->datalen + keyvalsize > txtRec->buflen)
2194b22b933Srs200217     {
2204b22b933Srs200217         unsigned char *newbuf;
2214b22b933Srs200217         unsigned long newlen = txtRec->datalen + keyvalsize;
2224b22b933Srs200217         if (newlen > 0xFFFF) return(kDNSServiceErr_Invalid);
2234b22b933Srs200217         newbuf = malloc((size_t)newlen);
2244b22b933Srs200217         if (!newbuf) return(kDNSServiceErr_NoMemory);
2254b22b933Srs200217         memcpy(newbuf, txtRec->buffer, txtRec->datalen);
2264b22b933Srs200217         if (txtRec->malloced) free(txtRec->buffer);
2274b22b933Srs200217         txtRec->buffer = newbuf;
2284b22b933Srs200217         txtRec->buflen = (uint16_t)(newlen);
2294b22b933Srs200217         txtRec->malloced = 1;
2304b22b933Srs200217     }
2314b22b933Srs200217     start = txtRec->buffer + txtRec->datalen;
2324b22b933Srs200217     p = start + 1;
2334b22b933Srs200217     memcpy(p, key, keysize);
2344b22b933Srs200217     p += keysize;
2354b22b933Srs200217     if (value)
2364b22b933Srs200217     {
2374b22b933Srs200217         *p++ = '=';
2384b22b933Srs200217         memcpy(p, value, valueSize);
2394b22b933Srs200217         p += valueSize;
2404b22b933Srs200217     }
2414b22b933Srs200217     *start = (uint8_t)(p - start - 1);
2424b22b933Srs200217     txtRec->datalen += p - start;
2434b22b933Srs200217     return(kDNSServiceErr_NoError);
2444b22b933Srs200217 }
2454b22b933Srs200217 
TXTRecordRemoveValue(TXTRecordRef * txtRecord,const char * key)2464b22b933Srs200217 DNSServiceErrorType DNSSD_API TXTRecordRemoveValue
2474b22b933Srs200217 (
2484b22b933Srs200217     TXTRecordRef     *txtRecord,
2494b22b933Srs200217     const char       *key
2504b22b933Srs200217 )
2514b22b933Srs200217 {
2524b22b933Srs200217     unsigned long keylen, itemlen, remainder;
2534b22b933Srs200217     uint8_t *item = InternalTXTRecordSearch(txtRec->datalen, txtRec->buffer, key, &keylen);
2544b22b933Srs200217     if (!item) return(kDNSServiceErr_NoSuchKey);
2554b22b933Srs200217     itemlen   = (unsigned long)(1 + item[0]);
2564b22b933Srs200217     remainder = (unsigned long)((txtRec->buffer + txtRec->datalen) - (item + itemlen));
2574b22b933Srs200217     // Use memmove because memcpy behaviour is undefined for overlapping regions
2584b22b933Srs200217     memmove(item, item + itemlen, remainder);
2594b22b933Srs200217     txtRec->datalen -= itemlen;
2604b22b933Srs200217     return(kDNSServiceErr_NoError);
2614b22b933Srs200217 }
2624b22b933Srs200217 
TXTRecordGetLength(const TXTRecordRef * txtRecord)2634b22b933Srs200217 uint16_t DNSSD_API TXTRecordGetLength  (const TXTRecordRef *txtRecord) { return(txtRec->datalen); }
TXTRecordGetBytesPtr(const TXTRecordRef * txtRecord)2644b22b933Srs200217 const void * DNSSD_API TXTRecordGetBytesPtr(const TXTRecordRef *txtRecord) { return(txtRec->buffer); }
2654b22b933Srs200217 
2664b22b933Srs200217 /*********************************************************************************************
2674b22b933Srs200217 *
2684b22b933Srs200217 *   TXT Record Parsing Functions
2694b22b933Srs200217 *
2704b22b933Srs200217 *********************************************************************************************/
2714b22b933Srs200217 
TXTRecordContainsKey(uint16_t txtLen,const void * txtRecord,const char * key)2724b22b933Srs200217 int DNSSD_API TXTRecordContainsKey
2734b22b933Srs200217 (
2744b22b933Srs200217     uint16_t txtLen,
2754b22b933Srs200217     const void       *txtRecord,
2764b22b933Srs200217     const char       *key
2774b22b933Srs200217 )
2784b22b933Srs200217 {
2794b22b933Srs200217     unsigned long keylen;
2804b22b933Srs200217     return (InternalTXTRecordSearch(txtLen, txtRecord, key, &keylen) ? 1 : 0);
2814b22b933Srs200217 }
2824b22b933Srs200217 
TXTRecordGetValuePtr(uint16_t txtLen,const void * txtRecord,const char * key,uint8_t * valueLen)2834b22b933Srs200217 const void * DNSSD_API TXTRecordGetValuePtr
2844b22b933Srs200217 (
2854b22b933Srs200217     uint16_t txtLen,
2864b22b933Srs200217     const void       *txtRecord,
2874b22b933Srs200217     const char       *key,
2884b22b933Srs200217     uint8_t          *valueLen
2894b22b933Srs200217 )
2904b22b933Srs200217 {
2914b22b933Srs200217     unsigned long keylen;
2924b22b933Srs200217     uint8_t *item = InternalTXTRecordSearch(txtLen, txtRecord, key, &keylen);
2934b22b933Srs200217     if (!item || item[0] <= keylen) return(NULL);   // If key not found, or found with no value, return NULL
2944b22b933Srs200217     *valueLen = (uint8_t)(item[0] - (keylen + 1));
2954b22b933Srs200217     return (item + 1 + keylen + 1);
2964b22b933Srs200217 }
2974b22b933Srs200217 
TXTRecordGetCount(uint16_t txtLen,const void * txtRecord)2984b22b933Srs200217 uint16_t DNSSD_API TXTRecordGetCount
2994b22b933Srs200217 (
3004b22b933Srs200217     uint16_t txtLen,
3014b22b933Srs200217     const void       *txtRecord
3024b22b933Srs200217 )
3034b22b933Srs200217 {
3044b22b933Srs200217     uint16_t count = 0;
3054b22b933Srs200217     uint8_t *p = (uint8_t*)txtRecord;
3064b22b933Srs200217     uint8_t *e = p + txtLen;
3074b22b933Srs200217     while (p<e) { p += 1 + p[0]; count++; }
3084b22b933Srs200217     return((p>e) ? (uint16_t)0 : count);
3094b22b933Srs200217 }
3104b22b933Srs200217 
TXTRecordGetItemAtIndex(uint16_t txtLen,const void * txtRecord,uint16_t itemIndex,uint16_t keyBufLen,char * key,uint8_t * valueLen,const void ** value)3114b22b933Srs200217 DNSServiceErrorType DNSSD_API TXTRecordGetItemAtIndex
3124b22b933Srs200217 (
3134b22b933Srs200217     uint16_t txtLen,
3144b22b933Srs200217     const void       *txtRecord,
315*5ffb0c9bSToomas Soome     uint16_t itemIndex,
3164b22b933Srs200217     uint16_t keyBufLen,
3174b22b933Srs200217     char             *key,
3184b22b933Srs200217     uint8_t          *valueLen,
3194b22b933Srs200217     const void       **value
3204b22b933Srs200217 )
3214b22b933Srs200217 {
3224b22b933Srs200217     uint16_t count = 0;
3234b22b933Srs200217     uint8_t *p = (uint8_t*)txtRecord;
3244b22b933Srs200217     uint8_t *e = p + txtLen;
325*5ffb0c9bSToomas Soome     while (p<e && count<itemIndex) { p += 1 + p[0]; count++; }  // Find requested item
3264b22b933Srs200217     if (p<e && p + 1 + p[0] <= e)   // If valid
3274b22b933Srs200217     {
3284b22b933Srs200217         uint8_t *x = p+1;
3294b22b933Srs200217         unsigned long len = 0;
3304b22b933Srs200217         e = p + 1 + p[0];
3314b22b933Srs200217         while (x+len<e && x[len] != '=') len++;
3324b22b933Srs200217         if (len >= keyBufLen) return(kDNSServiceErr_NoMemory);
3334b22b933Srs200217         memcpy(key, x, len);
3344b22b933Srs200217         key[len] = 0;
3354b22b933Srs200217         if (x+len<e)        // If we found '='
3364b22b933Srs200217         {
3374b22b933Srs200217             *value = x + len + 1;
3384b22b933Srs200217             *valueLen = (uint8_t)(p[0] - (len + 1));
3394b22b933Srs200217         }
3404b22b933Srs200217         else
3414b22b933Srs200217         {
3424b22b933Srs200217             *value = NULL;
3434b22b933Srs200217             *valueLen = 0;
3444b22b933Srs200217         }
3454b22b933Srs200217         return(kDNSServiceErr_NoError);
3464b22b933Srs200217     }
3474b22b933Srs200217     return(kDNSServiceErr_Invalid);
3484b22b933Srs200217 }
349*5ffb0c9bSToomas Soome 
350*5ffb0c9bSToomas Soome /*********************************************************************************************
351*5ffb0c9bSToomas Soome *
352*5ffb0c9bSToomas Soome *   SCCS-compatible version string
353*5ffb0c9bSToomas Soome *
354*5ffb0c9bSToomas Soome *********************************************************************************************/
355*5ffb0c9bSToomas Soome 
356*5ffb0c9bSToomas Soome // For convenience when using the "strings" command, this is the last thing in the file
357*5ffb0c9bSToomas Soome 
358*5ffb0c9bSToomas Soome // Note: The C preprocessor stringify operator ('#') makes a string from its argument, without macro expansion
359*5ffb0c9bSToomas Soome // e.g. If "version" is #define'd to be "4", then STRINGIFY_AWE(version) will return the string "version", not "4"
360*5ffb0c9bSToomas Soome // To expand "version" to its value before making the string, use STRINGIFY(version) instead
361*5ffb0c9bSToomas Soome #define STRINGIFY_ARGUMENT_WITHOUT_EXPANSION(s) # s
362*5ffb0c9bSToomas Soome #define STRINGIFY(s) STRINGIFY_ARGUMENT_WITHOUT_EXPANSION(s)
363*5ffb0c9bSToomas Soome 
364*5ffb0c9bSToomas Soome // NOT static -- otherwise the compiler may optimize it out
365*5ffb0c9bSToomas Soome // The "@(#) " pattern is a special prefix the "what" command looks for
366*5ffb0c9bSToomas Soome const char VersionString_SCCS_libdnssd[] = "@(#) libdns_sd " STRINGIFY(mDNSResponderVersion) " (" __DATE__ " " __TIME__ ")";
367