MCPcopy Create free account
hub / github.com/OpenPrinting/cups / httpGetHostname

Function httpGetHostname

cups/http-addr.c:795–899  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

793 */
794
795const char * /* O - FQDN for connection or system */
796httpGetHostname(http_t *http, /* I - HTTP connection or NULL */
797 char *s, /* I - String buffer for name */
798 int slen) /* I - Size of buffer */
799{
800 if (http)
801 {
802 if (!s || slen <= 1)
803 {
804 if (http->hostname[0] == '/')
805 return ("localhost");
806 else
807 return (http->hostname);
808 }
809 else if (http->hostname[0] == '/')
810 strlcpy(s, "localhost", (size_t)slen);
811 else
812 strlcpy(s, http->hostname, (size_t)slen);
813 }
814 else
815 {
816 /*
817 * Get the hostname...
818 */
819
820 if (!s || slen <= 1)
821 return (NULL);
822
823 if (gethostname(s, (size_t)slen) < 0)
824 strlcpy(s, "localhost", (size_t)slen);
825
826 if (!strchr(s, '.'))
827 {
828#ifdef HAVE_SCDYNAMICSTORECOPYCOMPUTERNAME
829 /*
830 * The hostname is not a FQDN, so use the local hostname from the
831 * SystemConfiguration framework...
832 */
833
834 SCDynamicStoreRef sc = SCDynamicStoreCreate(kCFAllocatorDefault,
835 CFSTR("libcups"), NULL, NULL);
836 /* System configuration data */
837 CFStringRef local = sc ? SCDynamicStoreCopyLocalHostName(sc) : NULL;
838 /* Local host name */
839 char localStr[1024]; /* Local host name C string */
840
841 if (local && CFStringGetCString(local, localStr, sizeof(localStr),
842 kCFStringEncodingUTF8))
843 {
844 /*
845 * Append ".local." to the hostname we get...
846 */
847
848 snprintf(s, (size_t)slen, "%s.local.", localStr);
849 }
850
851 if (local)
852 CFRelease(local);

Callers 15

create_clientFunction · 0.85
create_printerFunction · 0.85
cupsdIsAuthorizedFunction · 0.85
cupsdAcceptClientFunction · 0.85
cupsdReadClientFunction · 0.85
cupsdSendErrorFunction · 0.85
pipe_commandFunction · 0.85
lpd_queueFunction · 0.85
mainFunction · 0.85
cgiRewriteURLFunction · 0.85
mainFunction · 0.85

Calls 1

_cups_tolowerFunction · 0.85

Tested by 1

mainFunction · 0.68