comparison libpurple/network.c @ 21121:35b4f1dc4c8d

replace most calls to strerror with calls to g_strerror. strerror will return a locale-specific string in the locale-specific encoding, which isn't guaranteed to be UTF-8. g_strerror will always return a UTF-8 string. I left gg and zephyr untouched, since gg doesn't include glib headers yet, and zephyr does something weird with a #define for strerror. Someone more familliar with those should take a look. And the win32 guys should check and see if I screwed something up, since they had strerror #defined to something else. This should fix #2247 (and maybe some mystery crashes)
author Nathan Walp <nwalp@pidgin.im>
date Sat, 03 Nov 2007 17:52:28 +0000
parents 04fe5601fedb
children 7a05b6f84545
comparison
equal deleted inserted replaced
21120:0cc12e6909e2 21121:35b4f1dc4c8d
283 errnum = getaddrinfo(NULL /* any IP */, serv, &hints, &res); 283 errnum = getaddrinfo(NULL /* any IP */, serv, &hints, &res);
284 if (errnum != 0) { 284 if (errnum != 0) {
285 #ifndef _WIN32 285 #ifndef _WIN32
286 purple_debug_warning("network", "getaddrinfo: %s\n", gai_strerror(errnum)); 286 purple_debug_warning("network", "getaddrinfo: %s\n", gai_strerror(errnum));
287 if (errnum == EAI_SYSTEM) 287 if (errnum == EAI_SYSTEM)
288 purple_debug_warning("network", "getaddrinfo: system error: %s\n", strerror(errno)); 288 purple_debug_warning("network", "getaddrinfo: system error: %s\n", g_strerror(errno));
289 #else 289 #else
290 purple_debug_warning("network", "getaddrinfo: Error Code = %d\n", errnum); 290 purple_debug_warning("network", "getaddrinfo: Error Code = %d\n", errnum);
291 #endif 291 #endif
292 return NULL; 292 return NULL;
293 } 293 }
300 for (next = res; next != NULL; next = next->ai_next) { 300 for (next = res; next != NULL; next = next->ai_next) {
301 listenfd = socket(next->ai_family, next->ai_socktype, next->ai_protocol); 301 listenfd = socket(next->ai_family, next->ai_socktype, next->ai_protocol);
302 if (listenfd < 0) 302 if (listenfd < 0)
303 continue; 303 continue;
304 if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) != 0) 304 if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) != 0)
305 purple_debug_warning("network", "setsockopt: %s\n", strerror(errno)); 305 purple_debug_warning("network", "setsockopt: %s\n", g_strerror(errno));
306 if (bind(listenfd, next->ai_addr, next->ai_addrlen) == 0) 306 if (bind(listenfd, next->ai_addr, next->ai_addrlen) == 0)
307 break; /* success */ 307 break; /* success */
308 /* XXX - It is unclear to me (datallah) whether we need to be 308 /* XXX - It is unclear to me (datallah) whether we need to be
309 using a new socket each time */ 309 using a new socket each time */
310 close(listenfd); 310 close(listenfd);
316 return NULL; 316 return NULL;
317 #else 317 #else
318 struct sockaddr_in sockin; 318 struct sockaddr_in sockin;
319 319
320 if ((listenfd = socket(AF_INET, socket_type, 0)) < 0) { 320 if ((listenfd = socket(AF_INET, socket_type, 0)) < 0) {
321 purple_debug_warning("network", "socket: %s\n", strerror(errno)); 321 purple_debug_warning("network", "socket: %s\n", g_strerror(errno));
322 return NULL; 322 return NULL;
323 } 323 }
324 324
325 if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) != 0) 325 if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) != 0)
326 purple_debug_warning("network", "setsockopt: %s\n", strerror(errno)); 326 purple_debug_warning("network", "setsockopt: %s\n", g_strerror(errno));
327 327
328 memset(&sockin, 0, sizeof(struct sockaddr_in)); 328 memset(&sockin, 0, sizeof(struct sockaddr_in));
329 sockin.sin_family = PF_INET; 329 sockin.sin_family = PF_INET;
330 sockin.sin_port = htons(port); 330 sockin.sin_port = htons(port);
331 331
332 if (bind(listenfd, (struct sockaddr *)&sockin, sizeof(struct sockaddr_in)) != 0) { 332 if (bind(listenfd, (struct sockaddr *)&sockin, sizeof(struct sockaddr_in)) != 0) {
333 purple_debug_warning("network", "bind: %s\n", strerror(errno)); 333 purple_debug_warning("network", "bind: %s\n", g_strerror(errno));
334 close(listenfd); 334 close(listenfd);
335 return NULL; 335 return NULL;
336 } 336 }
337 #endif 337 #endif
338 338
339 if (socket_type == SOCK_STREAM && listen(listenfd, 4) != 0) { 339 if (socket_type == SOCK_STREAM && listen(listenfd, 4) != 0) {
340 purple_debug_warning("network", "listen: %s\n", strerror(errno)); 340 purple_debug_warning("network", "listen: %s\n", g_strerror(errno));
341 close(listenfd); 341 close(listenfd);
342 return NULL; 342 return NULL;
343 } 343 }
344 flags = fcntl(listenfd, F_GETFL); 344 flags = fcntl(listenfd, F_GETFL);
345 fcntl(listenfd, F_SETFL, flags | O_NONBLOCK); 345 fcntl(listenfd, F_SETFL, flags | O_NONBLOCK);
424 424
425 g_return_val_if_fail(fd >= 0, 0); 425 g_return_val_if_fail(fd >= 0, 0);
426 426
427 len = sizeof(addr); 427 len = sizeof(addr);
428 if (getsockname(fd, (struct sockaddr *) &addr, &len) == -1) { 428 if (getsockname(fd, (struct sockaddr *) &addr, &len) == -1) {
429 purple_debug_warning("network", "getsockname: %s\n", strerror(errno)); 429 purple_debug_warning("network", "getsockname: %s\n", g_strerror(errno));
430 return 0; 430 return 0;
431 } 431 }
432 432
433 return ntohs(addr.sin_port); 433 return ntohs(addr.sin_port);
434 } 434 }