ObjFW  Diff

Differences From Artifact [5a537c9df8]:

To Artifact [65cb318889]:


119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
















































179
180
181
182
183
184
185
# if !defined(HAVE_THREADSAFE_GETADDRINFO) && defined(OF_HAVE_THREADS)
	} @finally {
		if (!of_mutex_unlock(&mutex))
			@throw [OFUnlockFailedException exception];
	}
# endif
#else
	struct hostent *he;
	in_addr_t s_addr;
	char **ip;
	struct sockaddr_in *addrs, *addrsIter;

	/*
	 * If the host is an IP address, don't try resolving it.
	 * On the Wii for example, the resolver will return an error if you
	 * specify an IP address.
	 */
	if ((s_addr = inet_addr([host UTF8String])) != INADDR_NONE) {
		of_resolver_result_t *tmp;
		struct sockaddr_in *addr;

		if ((ret = calloc(2, sizeof(*ret))) == NULL)
			@throw [OFOutOfMemoryException
			    exceptionWithRequestedSize: 2 * sizeof(*ret)];

		if ((tmp = malloc(sizeof(*tmp))) == NULL) {
			free(ret);
			@throw [OFOutOfMemoryException
			    exceptionWithRequestedSize: sizeof(*tmp)];
		}

		if ((addr = calloc(1, sizeof(*addr))) == NULL) {
			free(ret);
			free(tmp);
			@throw [OFOutOfMemoryException
			    exceptionWithRequestedSize: sizeof(*addr)];
		}

		addr->sin_family = AF_INET;
		addr->sin_port = OF_BSWAP16_IF_LE(port);
		addr->sin_addr.s_addr = s_addr;

		tmp->family = AF_INET;
		tmp->type = type;
		tmp->protocol = 0;
		tmp->address = (struct sockaddr*)addr;
		tmp->addressLength = sizeof(*addr);

		ret[0] = tmp;
		ret[1] = NULL;

		return ret;
	}

# ifdef OF_HAVE_THREADS
	if (!of_mutex_lock(&mutex))
		@throw [OFLockFailedException exception];

	@try {
# endif
















































		if ((he = gethostbyname([host UTF8String])) == NULL ||
		    he->h_addrtype != AF_INET)
			@throw [OFAddressTranslationFailedException
			    exceptionWithHost: host];

		count = 0;
		for (ip = he->h_addr_list; *ip != NULL; ip++)







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<






>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







119
120
121
122
123
124
125















































126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# if !defined(HAVE_THREADSAFE_GETADDRINFO) && defined(OF_HAVE_THREADS)
	} @finally {
		if (!of_mutex_unlock(&mutex))
			@throw [OFUnlockFailedException exception];
	}
# endif
#else















































# ifdef OF_HAVE_THREADS
	if (!of_mutex_lock(&mutex))
		@throw [OFLockFailedException exception];

	@try {
# endif
		in_addr_t s_addr;
		struct hostent *he;
		char **ip;
		struct sockaddr_in *addrs, *addrsIter;

		/*
		 * If the host is an IP address, don't try resolving it.  On
		 * the Wii for example, the resolver will return an error if
		 * you specify an IP address.
		 */
		if ((s_addr = inet_addr([host UTF8String])) != INADDR_NONE) {
			of_resolver_result_t *tmp;
			struct sockaddr_in *addr;

			if ((ret = calloc(2, sizeof(*ret))) == NULL)
				@throw [OFOutOfMemoryException
				    exceptionWithRequestedSize: 2 *
								sizeof(*ret)];

			if ((tmp = malloc(sizeof(*tmp))) == NULL) {
				free(ret);
				@throw [OFOutOfMemoryException
				    exceptionWithRequestedSize: sizeof(*tmp)];
			}

			if ((addr = calloc(1, sizeof(*addr))) == NULL) {
				free(ret);
				free(tmp);
				@throw [OFOutOfMemoryException
				    exceptionWithRequestedSize: sizeof(*addr)];
			}

			addr->sin_family = AF_INET;
			addr->sin_port = OF_BSWAP16_IF_LE(port);
			addr->sin_addr.s_addr = s_addr;

			tmp->family = AF_INET;
			tmp->type = type;
			tmp->protocol = 0;
			tmp->address = (struct sockaddr*)addr;
			tmp->addressLength = sizeof(*addr);

			ret[0] = tmp;
			ret[1] = NULL;

			return ret;
		}

		if ((he = gethostbyname([host UTF8String])) == NULL ||
		    he->h_addrtype != AF_INET)
			@throw [OFAddressTranslationFailedException
			    exceptionWithHost: host];

		count = 0;
		for (ip = he->h_addr_list; *ip != NULL; ip++)