[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: get ip from server
Peter Zelezny wrote:
>On Sat, 19 Apr 2003 23:07:07 -0400
>"James LiGate" <Escape@usa.net> wrote:
>
>
>
>>For example, if I were +x under Unreal, for myself I would see:
>>
>>James is ~escape@ascends-250B54E4.tnt1.richmond.va.da.uu.net * James LiGate
>>James is connecting from *@1Cust236.tnt1.richmond.va.da.uu.net
>>
>>
>
>
>We can't just flip 'Get hostname from server' ON as it stands, because:
>
>* xchat doesn't support this "connecting from xxxx" line. Is that a new
> non-rfc numeric?
>* The current implementation uses a blocking DNS lookup. It was assumed
> most people wouldn't use it, so the few who do have to put up with the
> pain of a quick lockup.
>* I think most people have a "proper" routable IP address and don't want
> this ON.
>
>Turning it ON in the case of a 192.168.*.* or 10.*.*.* primary address is
>reasonable, if someone wants to whip up a patch to do that.
>
>
>
>
here is a patch that turns it on ip's that sleibt had mentioned:
10.x
172.16.x to 172.31.x
192.168.x
it doesn't take ipv6 into consideration
it may be doing more than it has to...(eg may be a better
way to do what im doing)
Nehal
? getip-nehal.diff
Index: inbound.c
===================================================================
RCS file: /cvsroot/xchat/xchat2/src/common/inbound.c,v
retrieving revision 1.14
diff -u -r1.14 inbound.c
--- inbound.c 17 Mar 2003 03:54:23 -0000 1.14
+++ inbound.c 20 Apr 2003 19:25:07 -0000
@@ -1060,9 +1060,30 @@
{
server *serv = sess->server;
+ char buf[128];
+ struct hostent *he;
+ unsigned long addr = 0;
+ int internal_ip;
+ int first_quad;
+ int second_quad;
+
if (!serv->end_of_motd)
{
- if (prefs.ip_from_server)
+ gethostname(buf, sizeof(buf));
+ he = gethostbyname(buf);
+ memcpy(&addr,he->h_addr,he->h_length);
+
+ first_quad = ((int)(((addr)) & 0xff));
+ second_quad = ((int)(((addr) >> 8) & 0xff));
+ if ( (first_quad == 192 && second_quad == 168) ||
+ (first_quad == 172 && second_quad >= 16 && second_quad <= 31) ||
+ (first_quad == 10) ) {
+ internal_ip = 1;
+ } else {
+ internal_ip = 0;
+ }
+
+ if (prefs.ip_from_server || internal_ip)
{
serv->skip_next_who = TRUE;
serv->p_get_ip (serv, serv->nick); /* sends WHO mynick */