changeset 13345:d7b6e358493d

[gaim-migrate @ 15715] Change spaces to tabs, and 0 is a valid file descriptor, although I think it is almost always set to one of stdout, stderr or stdin. In Linux, anyway. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Tue, 28 Feb 2006 05:50:42 +0000
parents 1c2f284986b7
children e614c46936ba
files src/network.c
diffstat 1 files changed, 38 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/src/network.c	Tue Feb 28 02:00:15 2006 +0000
+++ b/src/network.c	Tue Feb 28 05:50:42 2006 +0000
@@ -92,46 +92,50 @@
 const char *
 gaim_network_get_local_system_ip(int fd)
 {
-       char buffer[1024];
-       static char ip[16];
-       char *tmp;
-       struct ifconf ifc;
-       struct ifreq *ifr;
-       struct sockaddr_in *sinptr;
-       guint32 lhost = htonl(127*256*256*256+1);
-       long unsigned int add;
-       int source = fd;
+	char buffer[1024];
+	static char ip[16];
+	char *tmp;
+	struct ifconf ifc;
+	struct ifreq *ifr;
+	struct sockaddr_in *sinptr;
+	guint32 lhost = htonl(127 * 256 * 256 * 256 + 1);
+	long unsigned int add;
+	int source = fd;
 
-       if(source <= 0)
-           source = socket(PF_INET,SOCK_STREAM,0);
+	if (fd < 0)
+		source = socket(PF_INET,SOCK_STREAM, 0);
 
-       ifc.ifc_len = sizeof(buffer);
-       ifc.ifc_req = (struct ifreq*) buffer;
-       ioctl(source, SIOCGIFCONF, &ifc);
+	ifc.ifc_len = sizeof(buffer);
+	ifc.ifc_req = (struct ifreq *)buffer;
+	ioctl(source, SIOCGIFCONF, &ifc);
 
-       if(fd <= 0)
-               close(source);
+	if (fd < 0)
+		close(source);
 
-       tmp = buffer;
-       while(tmp < buffer + ifc.ifc_len) {
-               ifr = (struct ifreq *) tmp;
-               tmp += sizeof(struct ifreq);
+	tmp = buffer;
+	while (tmp < buffer + ifc.ifc_len)
+	{
+		ifr = (struct ifreq *)tmp;
+		tmp += sizeof(struct ifreq);
 
-               if(ifr->ifr_addr.sa_family == AF_INET) {
-                       sinptr = (struct sockaddr_in *) &ifr->ifr_addr;
-                       if(sinptr->sin_addr.s_addr != lhost) {
-                               add = ntohl(sinptr->sin_addr.s_addr);
-                               g_snprintf(ip, 16, "%lu.%lu.%lu.%lu",
-                                          ((add >> 24) & 255),
-                                          ((add >> 16) & 255),
-                                          ((add >> 8) & 255),
-                                          add & 255);
+		if (ifr->ifr_addr.sa_family == AF_INET)
+		{
+			sinptr = (struct sockaddr_in *)&ifr->ifr_addr;
+			if (sinptr->sin_addr.s_addr != lhost)
+			{
+				add = ntohl(sinptr->sin_addr.s_addr);
+				g_snprintf(ip, 16, "%lu.%lu.%lu.%lu",
+					((add >> 24) & 255),
+					((add >> 16) & 255),
+					((add >> 8) & 255),
+					add & 255);
 
-                               return ip;
-                       }
-               }
-       }
-       return "0.0.0.0";
+				return ip;
+			}
+		}
+	}
+
+	return "0.0.0.0";
 }
 
 const char *