CFNetwork Error Codes Reference

Framework
CoreServices
Companion guide
Declared in
CFNetworkErrors.h

Overview

Many functions in the CFNetwork API return error codes to indicate the cause of a failure. This document explains these error codes.

Constants

CFNetworkErrors Constants

This enumeration contains error codes returned under the error domain kCFErrorDomainCFNetwork.

enum CFNetworkErrors {
   kCFHostErrorHostNotFound      = 1,
   kCFHostErrorUnknown           = 2,
   
/* SOCKS errors */
   kCFSOCKSErrorUnknownClientVersion = 100,
   kCFSOCKSErrorUnsupportedServerVersion = 101,
   
/* SOCKS4-specific errors*/
   kCFSOCKS4ErrorRequestFailed   = 110,
   kCFSOCKS4ErrorIdentdFailed    = 111,
   kCFSOCKS4ErrorIdConflict      = 112,
   kCFSOCKS4ErrorUnknownStatusCode = 113,
   
/* SOCKS5-specific errors*/
   kCFSOCKS5ErrorBadState        = 120,
   kCFSOCKS5ErrorBadResponseAddr = 121,
   kCFSOCKS5ErrorBadCredentials  = 122,
   kCFSOCKS5ErrorUnsupportedNegotiationMethod = 123,
   kCFSOCKS5ErrorNoAcceptableMethod = 124,
   
   
/* FTP errors */
   kCFFTPErrorUnexpectedStatusCode = 200,
   
/* HTTP errors*/
   kCFErrorHTTPAuthenticationTypeUnsupported = 300,
   kCFErrorHTTPBadCredentials    = 301,
   kCFErrorHTTPConnectionLost    = 302,
   kCFErrorHTTPParseFailure      = 303,
   kCFErrorHTTPRedirectionLoopDetected = 304,
   kCFErrorHTTPBadURL            = 305,
   kCFErrorHTTPProxyConnectionFailure  = 306,
   kCFErrorHTTPBadProxyCredentials     = 307,
   kCFErrorPACFileError          = 308,
   kCFErrorPACFileAuth           = 309,
   kCFErrorHTTPSProxyConnectionFailure = 310,
   kCFStreamErrorHTTPSProxyFailureUnexpectedResponseToCONNECTMethod = 311,
   
/* CFURL and CFURLConnection Errors */
   kCFURLErrorUnknown   = -998,
   kCFURLErrorCancelled = -999,
   kCFURLErrorBadURL    = -1000,
   kCFURLErrorTimedOut  = -1001,
   kCFURLErrorUnsupportedURL = -1002,
   kCFURLErrorCannotFindHost = -1003,
   kCFURLErrorCannotConnectToHost    = -1004,
   kCFURLErrorNetworkConnectionLost  = -1005,
   kCFURLErrorDNSLookupFailed        = -1006,
   kCFURLErrorHTTPTooManyRedirects   = -1007,
   kCFURLErrorResourceUnavailable    = -1008,
   kCFURLErrorNotConnectedToInternet = -1009,
   kCFURLErrorRedirectToNonExistentLocation = -1010,
   kCFURLErrorBadServerResponse             = -1011,
   kCFURLErrorUserCancelledAuthentication   = -1012,
   kCFURLErrorUserAuthenticationRequired    = -1013,
   kCFURLErrorZeroByteResource        = -1014,
   kCFURLErrorCannotDecodeRawData     = -1015,
   kCFURLErrorCannotDecodeContentData = -1016,
   kCFURLErrorCannotParseResponse     = -1017,
   kCFURLErrorInternationalRoamingOff = -1018,
   kCFURLErrorCallIsActive               = -1019,
   kCFURLErrorDataNotAllowed             = -1020,
   kCFURLErrorRequestBodyStreamExhausted = -1021,
   kCFURLErrorFileDoesNotExist           = -1100,
   kCFURLErrorFileIsDirectory            = -1101,
   kCFURLErrorNoPermissionsToReadFile    = -1102,
   kCFURLErrorDataLengthExceedsMaximum   = -1103,
   
/* SSL errors */
   kCFURLErrorSecureConnectionFailed          = -1200,
   kCFURLErrorServerCertificateHasBadDate     = -1201,
   kCFURLErrorServerCertificateUntrusted      = -1202,
   kCFURLErrorServerCertificateHasUnknownRoot = -1203,
   kCFURLErrorServerCertificateNotYetValid    = -1204,
   kCFURLErrorClientCertificateRejected       = -1205,
   kCFURLErrorClientCertificateRequired       = -1206,
   
   kCFURLErrorCannotLoadFromNetwork           = -2000,
   
/* Download and file I/O errors */
   kCFURLErrorCannotCreateFile = -3000,
   kCFURLErrorCannotOpenFile = -3001,
   kCFURLErrorCannotCloseFile = -3002,
   kCFURLErrorCannotWriteToFile = -3003,
   kCFURLErrorCannotRemoveFile = -3004,
   kCFURLErrorCannotMoveFile = -3005,
   kCFURLErrorDownloadDecodingFailedMidStream = -3006,
   kCFURLErrorDownloadDecodingFailedToComplete = -3007,
   
/* Cookie errors */
   kCFHTTPCookieCannotParseCookieFile = -4000,
   
/* Errors originating from CFNetServices*/
   kCFNetServiceErrorUnknown     = -72000L,
   kCFNetServiceErrorCollision   = -72001L,
   kCFNetServiceErrorNotFound    = -72002L,
   kCFNetServiceErrorInProgress  = -72003L,
   kCFNetServiceErrorBadArgument = -72004L,
   kCFNetServiceErrorCancel      = -72005L,
   kCFNetServiceErrorInvalid     = -72006L,
   kCFNetServiceErrorTimeout     = -72007L,
   kCFNetServiceErrorDNSServiceFailure = -73000L,
};
typedef enum CFNetworkErrors CFNetworkErrors;
Constants
kCFHostErrorHostNotFound

Indicates that the DNS lookup failed.

Available in OS X v10.5 and later.

Declared in CFNetworkErrors.h.

kCFHostErrorUnknown

An unknown error occurred (a name server failure, for example). For additional information, you can query the kCFGetAddrInfoFailureKey key to obtain the value returned by getaddrinfo and look up the value in /usr/include/netdb.h.

Available in OS X v10.5 and later.

Declared in CFNetworkErrors.h.

kCFSOCKSErrorUnknownClientVersion

The SOCKS server rejected access because it does not support connections with the requested SOCKS version. SOCKS client version. You can query the kCFSOCKSVersionKey key to find out what version the server requested.

Available in OS X v10.5 and later.

Declared in CFNetworkErrors.h.

kCFSOCKSErrorUnsupportedServerVersion

The version of SOCKS requested by the server is not supported. You can query the kCFSOCKSVersionKey key to find out what version the server requested.

Available in OS X v10.5 and later.

Declared in CFNetworkErrors.h.

kCFSOCKS4ErrorRequestFailed

Request rejected by the server or request failed. This error is specific to SOCKS4.

Available in OS X v10.5 and later.

Declared in CFNetworkErrors.h.

kCFSOCKS4ErrorIdentdFailed

Request rejected by the server because it could not connect to the identd daemon on the client. This error is specific to SOCKS4.

Available in OS X v10.5 and later.

Declared in CFNetworkErrors.h.

kCFSOCKS4ErrorIdConflict

Request rejected by the server because the client program and the identd daemon reported different user IDs. This error is specific to SOCKS4.

Available in OS X v10.5 and later.

Declared in CFNetworkErrors.h.

kCFSOCKS4ErrorUnknownStatusCode

The status code returned by the server is unknown. This error is specific to SOCKS4.

Available in OS X v10.5 and later.

Declared in CFNetworkErrors.h.

kCFSOCKS5ErrorBadState

The stream is not in a state that allows the requested operation.

Available in OS X v10.5 and later.

Declared in CFNetworkErrors.h.

kCFSOCKS5ErrorBadResponseAddr

The address type returned is not supported

Available in OS X v10.5 and later.

Declared in CFNetworkErrors.h.

kCFSOCKS5ErrorBadCredentials

The SOCKS server refused the client connection because of bad login credentials.

Available in OS X v10.5 and later.

Declared in CFNetworkErrors.h.

kCFSOCKS5ErrorUnsupportedNegotiationMethod

The requested method is not supported. You can query the kCFSOCKSNegotiationMethodKey key to find out which method the server requested.

Available in OS X v10.5 and later.

Declared in CFNetworkErrors.h.

kCFSOCKS5ErrorNoAcceptableMethod

The client and server could not find a mutually agreeable authentication method.

Available in OS X v10.5 and later.

Declared in CFNetworkErrors.h.

kCFFTPErrorUnexpectedStatusCode

The server returned an unexpected status code.

Available in OS X v10.5 and later.

Declared in CFNetworkErrors.h.

kCFErrorHTTPAuthenticationTypeUnsupported

The client and server could not agree on a supported authentication type.

Available in OS X v10.5 and later.

Declared in CFNetworkErrors.h.

kCFErrorHTTPBadCredentials

The credentials provided for an authenticated connection were rejected by the server.

Available in OS X v10.5 and later.

Declared in CFNetworkErrors.h.

kCFErrorHTTPConnectionLost

The connection to the server was dropped. This usually indicates a highly overloaded server.

Available in OS X v10.5 and later.

Declared in CFNetworkErrors.h.

kCFErrorHTTPParseFailure

The HTTP server response could not be parsed.

Available in OS X v10.5 and later.

Declared in CFNetworkErrors.h.

kCFErrorHTTPRedirectionLoopDetected

Too many HTTP redirects occurred before reaching a page that did not redirect the client to another page. This usually indicates a redirect loop.

Available in OS X v10.5 and later.

Declared in CFNetworkErrors.h.

kCFErrorHTTPBadURL

The requested URL could not be retrieved.

Available in OS X v10.5 and later.

Declared in CFNetworkErrors.h.

kCFErrorHTTPProxyConnectionFailure

A connection could not be established to the HTTP proxy.

Available in OS X v10.5 and later.

Declared in CFNetworkErrors.h.

kCFErrorHTTPBadProxyCredentials

The authentication credentials provided for logging into the proxy were rejected.

Available in OS X v10.5 and later.

Declared in CFNetworkErrors.h.

kCFErrorPACFileError

An error occurred with the proxy autoconfiguration file.

Available in OS X v10.5 and later.

Declared in CFNetworkErrors.h.

kCFErrorPACFileAuth

The authentication credentials provided by the proxy autoconfiguration file were rejected.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFErrorHTTPSProxyConnectionFailure

A connection could not be established to the HTTPS proxy.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFStreamErrorHTTPSProxyFailureUnexpectedResponseToCONNECTMethod

The HTTPS proxy returned an unexpected status code, such as a 3xx redirect.

Available in OS X v10.7 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorUnknown

An unknown error occurred.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorCancelled

The connection was cancelled.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorBadURL

The connection failed due to a malformed URL.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorTimedOut

The connection timed out.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorUnsupportedURL

The connection failed due to an unsupported URL scheme.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorCannotFindHost

The connection failed because the host could not be found.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorCannotConnectToHost

The connection failed because a connection cannot be made to the host.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorNetworkConnectionLost

The connection failed because the network connection was lost.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorDNSLookupFailed

The connection failed because the DNS lookup failed.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorHTTPTooManyRedirects

The HTTP connection failed due to too many redirects.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorResourceUnavailable

The connection’s resource is unavailable.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorNotConnectedToInternet

The connection failed because the device is not connected to the internet.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorRedirectToNonExistentLocation

The connection was redirected to a nonexistent location.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorBadServerResponse

The connection received an invalid server response.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorUserCancelledAuthentication

The connection failed because the user cancelled required authentication.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorUserAuthenticationRequired

The connection failed because authentication is required.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorZeroByteResource

The resource retrieved by the connection is zero bytes.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorCannotDecodeRawData

The connection cannot decode data encoded with a known content encoding.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorCannotDecodeContentData

The connection cannot decode data encoded with an unknown content encoding.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorCannotParseResponse

The connection cannot parse the server’s response.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorInternationalRoamingOff

The connection failed because international roaming is disabled on the device.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorCallIsActive

The connection failed because a call is active.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorDataNotAllowed

The connection failed because data use is currently not allowed on the device.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorRequestBodyStreamExhausted

The connection failed because its request’s body stream was exhausted.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorFileDoesNotExist

The file operation failed because the file does not exist.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorFileIsDirectory

The file operation failed because the file is a directory.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorNoPermissionsToReadFile

The file operation failed because it does not have permission to read the file.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorDataLengthExceedsMaximum

The file operation failed because the file is too large.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorSecureConnectionFailed

The secure connection failed for an unknown reason.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorServerCertificateHasBadDate

The secure connection failed because the server’s certificate has an invalid date.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorServerCertificateUntrusted

The secure connection failed because the server’s certificate is not trusted.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorServerCertificateHasUnknownRoot

The secure connection failed because the server’s certificate has an unknown root.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorServerCertificateNotYetValid

The secure connection failed because the server’s certificate is not yet valid.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorClientCertificateRejected

The secure connection failed because the client’s certificate was rejected.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorClientCertificateRequired

The secure connection failed because the server requires a client certificate.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorCannotLoadFromNetwork

The connection failed because it is being required to return a cached resource, but one is not available.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorCannotCreateFile

The file cannot be created.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorCannotOpenFile

The file cannot be opened.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorCannotCloseFile

The file cannot be closed.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorCannotWriteToFile

The file cannot be written.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorCannotRemoveFile

The file cannot be removed.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorCannotMoveFile

The file cannot be moved.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorDownloadDecodingFailedMidStream

The download failed because decoding of the downloaded data failed mid-stream.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorDownloadDecodingFailedToComplete

The download failed because decoding of the downloaded data failed to complete.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFHTTPCookieCannotParseCookieFile

The cookie file cannot be parsed.

Available in OS X v10.6 and later.

Declared in CFNetworkErrors.h.

kCFNetServiceErrorUnknown

An unknown error occurred.

Declared in CFNetworkErrors.h.

Available in OS X v10.2 and later.

kCFNetServiceErrorCollision

An attempt was made to use a name that is already in use.

Declared in CFNetworkErrors.h.

Available in OS X v10.2 and later.

kCFNetServiceErrorNotFound

Not used.

Declared in CFNetworkErrors.h.

Available in OS X v10.2 and later.

kCFNetServiceErrorInProgress

A new search could not be started because a search is already in progress.

Declared in CFNetworkErrors.h.

Available in OS X v10.2 and later.

kCFNetServiceErrorBadArgument

A required argument was not provided or was not valid.

Declared in CFNetworkErrors.h.

Available in OS X v10.2 and later.

kCFNetServiceErrorCancel

The search or service was cancelled.

Declared in CFNetworkErrors.h.

Available in OS X v10.2 and later.

kCFNetServiceErrorInvalid

Invalid data was passed to a CFNetServices function.

Declared in CFNetworkErrors.h.

Available in OS X v10.2 and later.

kCFNetServiceErrorTimeout

A search failed because it timed out.

Declared in CFNetworkErrors.h.

Available in OS X v10.2 and later.

kCFNetServiceErrorDNSServiceFailure

DNS service discovery returned an error. You can query the kCFDNSServiceFailureKey key to find out the error returned by DNS service discovery and look up the code in /usr/include/dns_sd.h or DNS Service Discovery C Reference.

Declared in CFNetworkErrors.h.

Available in OS X v10.5 and later.

Discussion

To determine the source of an error, examine the userInfo dictionary included in the CFError object returned by a function call or call CFErrorGetDomain and pass in the CFError object and the domain whose value you want to read. These errors are all part of the kCFErrorDomainCFNetwork domain.

Availability
  • Available in OS X version 10.5 and later.
Declared In
CFNetwork/CFHost.h

Error Dictionary Keys

Networking-related keys that may be available in a CFErrorRef object’s userInfo dictionary.

extern const CFStringRef kCFURLErrorFailingURLErrorKey;
extern const CFStringRef kCFURLErrorFailingURLStringErrorKey;
extern const CFStringRef kCFGetAddrInfoFailureKey;
extern const CFStringRef kCFSOCKSStatusCodeKey;
extern const CFStringRef kCFSOCKSVersionKey;
extern const CFStringRef kCFSOCKSNegotiationMethodKey;
extern const CFStringRef kCFDNSServiceFailureKey;
extern const CFStringRef kCFFTPStatusCodeKey;
Constants
kCFURLErrorFailingURLErrorKey

The URL that caused the load to fail as a CFURLRef object.

Available in OS X v10.5 and later.

Declared in CFNetworkErrors.h.

kCFURLErrorFailingURLStringErrorKey

The URL that caused the load to fail as a CFStringRef object.

Available in OS X v10.5 and later.

Declared in CFNetworkErrors.h.

kCFGetAddrInfoFailureKey

If an error of type kCFHostErrorUnknown is returned, this key returns the last error code returned by getaddrinfo in response to a DNS lookup. To interpret the results, look up the error code in /usr/include/netdb.h.

Available in OS X v10.5 and later.

Declared in CFNetworkErrors.h.

kCFSOCKSStatusCodeKey

When a SOCKS error occurs, querying this key returns the last status code sent by the SOCKS server in response to the previous operation.

Available in OS X v10.5 and later.

Declared in CFNetworkErrors.h.

kCFSOCKSVersionKey

If an error of type kCFSOCKSErrorUnsupportedServerVersion is returned, querying this key returns the SOCKS version in use by the current connection.

Available in OS X v10.5 and later.

Declared in CFNetworkErrors.h.

kCFSOCKSNegotiationMethodKey

If an error of type kCFSOCKS5ErrorUnsupportedNegotiationMethod is returned, querying this key returns the negotiation method requested by the SOCKS server.

Available in OS X v10.5 and later.

Declared in CFNetworkErrors.h.

kCFDNSServiceFailureKey

If an error of type kCFNetServicesErrorDNSServiceFailure is returned, querying this key returns the last error returned by the DNS resolver libraries in response to the previous operation. To interpret the results, look up the error codes in /usr/include/dns_sd.h or DNS Service Discovery C Reference.

Available in OS X v10.5 and later.

Declared in CFNetworkErrors.h.

kCFFTPStatusCodeKey

If an error of type kCFFTPErrorUnexpectedStatusCode is returned, querying this key returns the last status code sent by the FTP server in response to the previous operation.

Available in OS X v10.5 and later.

Declared in CFNetworkErrors.h.

Discussion

Many network functions return CFErrorRef objects. When the error object's domain is kCFErrorDomainCFNetwork, you can query the object for additional information.

For example:

if (CFEqual(CFErrorGetDomain(err), kCFErrorDomainCFNetwork) && CFErrorGetCode(err) == kCFHostErrorUnknown) {
 
    CFDictionaryRef userInfo = CFErrorCopyUserInfo(err);
 
    CFNumberRef number = (CFNumberRef) CFDictionaryGetValue(userInfo, kCFGetAddrInfoFailureKey);
 
    ...
 
    CFRelease(userInfo);
}

Error Domains

High-level error domains.

extern const CFStringRef kCFErrorDomainCFNetwork;
extern const CFStringRef kCFErrorDomainWinSock;
Constants
kCFErrorDomainCFNetwork

Error domain that returns error codes specific to the CFNetwork stack.

Declared in CFNetworkErrors.h.

Available in OS X version 10.5 and later.

kCFErrorDomainWinSock

Error domain that returns error codes specific to the underlying network layer when running CFNetwork code on Windows.

Declared in CFNetworkErrors.h.

Available in OS X version 10.5 and later.

Discussion

To determine the source of an error, examine the userInfo dictionary included in the CFError object returned by a function call or call CFErrorGetDomain and pass in the CFError object and the domain whose value you want to read.