Mercurial > pidgin
comparison src/network.c @ 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 | be0cd152691d |
children | 95cc25e78ef6 |
comparison
equal
deleted
inserted
replaced
13344:1c2f284986b7 | 13345:d7b6e358493d |
---|---|
90 } | 90 } |
91 | 91 |
92 const char * | 92 const char * |
93 gaim_network_get_local_system_ip(int fd) | 93 gaim_network_get_local_system_ip(int fd) |
94 { | 94 { |
95 char buffer[1024]; | 95 char buffer[1024]; |
96 static char ip[16]; | 96 static char ip[16]; |
97 char *tmp; | 97 char *tmp; |
98 struct ifconf ifc; | 98 struct ifconf ifc; |
99 struct ifreq *ifr; | 99 struct ifreq *ifr; |
100 struct sockaddr_in *sinptr; | 100 struct sockaddr_in *sinptr; |
101 guint32 lhost = htonl(127*256*256*256+1); | 101 guint32 lhost = htonl(127 * 256 * 256 * 256 + 1); |
102 long unsigned int add; | 102 long unsigned int add; |
103 int source = fd; | 103 int source = fd; |
104 | 104 |
105 if(source <= 0) | 105 if (fd < 0) |
106 source = socket(PF_INET,SOCK_STREAM,0); | 106 source = socket(PF_INET,SOCK_STREAM, 0); |
107 | 107 |
108 ifc.ifc_len = sizeof(buffer); | 108 ifc.ifc_len = sizeof(buffer); |
109 ifc.ifc_req = (struct ifreq*) buffer; | 109 ifc.ifc_req = (struct ifreq *)buffer; |
110 ioctl(source, SIOCGIFCONF, &ifc); | 110 ioctl(source, SIOCGIFCONF, &ifc); |
111 | 111 |
112 if(fd <= 0) | 112 if (fd < 0) |
113 close(source); | 113 close(source); |
114 | 114 |
115 tmp = buffer; | 115 tmp = buffer; |
116 while(tmp < buffer + ifc.ifc_len) { | 116 while (tmp < buffer + ifc.ifc_len) |
117 ifr = (struct ifreq *) tmp; | 117 { |
118 tmp += sizeof(struct ifreq); | 118 ifr = (struct ifreq *)tmp; |
119 | 119 tmp += sizeof(struct ifreq); |
120 if(ifr->ifr_addr.sa_family == AF_INET) { | 120 |
121 sinptr = (struct sockaddr_in *) &ifr->ifr_addr; | 121 if (ifr->ifr_addr.sa_family == AF_INET) |
122 if(sinptr->sin_addr.s_addr != lhost) { | 122 { |
123 add = ntohl(sinptr->sin_addr.s_addr); | 123 sinptr = (struct sockaddr_in *)&ifr->ifr_addr; |
124 g_snprintf(ip, 16, "%lu.%lu.%lu.%lu", | 124 if (sinptr->sin_addr.s_addr != lhost) |
125 ((add >> 24) & 255), | 125 { |
126 ((add >> 16) & 255), | 126 add = ntohl(sinptr->sin_addr.s_addr); |
127 ((add >> 8) & 255), | 127 g_snprintf(ip, 16, "%lu.%lu.%lu.%lu", |
128 add & 255); | 128 ((add >> 24) & 255), |
129 | 129 ((add >> 16) & 255), |
130 return ip; | 130 ((add >> 8) & 255), |
131 } | 131 add & 255); |
132 } | 132 |
133 } | 133 return ip; |
134 return "0.0.0.0"; | 134 } |
135 } | |
136 } | |
137 | |
138 return "0.0.0.0"; | |
135 } | 139 } |
136 | 140 |
137 const char * | 141 const char * |
138 gaim_network_get_my_ip(int fd) | 142 gaim_network_get_my_ip(int fd) |
139 { | 143 { |