ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/netdisp.C
Revision: 1.11
Committed: Fri Sep 14 17:10:34 2007 UTC (16 years, 8 months ago) by ayin
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.10: +0 -0 lines
State: FILE REMOVED
Log Message:
Move rxvt_network_display to init.C and remove netdisp.{C,h}.

File Contents

# Content
1 /*----------------------------------------------------------------------*
2 * File: netdisp.C
3 *----------------------------------------------------------------------*
4 *
5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 1996 Chuck Blake <cblake@BBN.COM>
7 * - original version
8 * Copyright (c) 1997 mj olesen <olesen@me.queensu.ca>
9 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *----------------------------------------------------------------------*/
25 /*----------------------------------------------------------------------*
26 * support for resolving the actual IP number of the host for remote
27 * DISPLAYs. When the display is local (i.e. :0), we add support for
28 * sending the first non-loopback interface IP number as the DISPLAY
29 * instead of just sending the incorrect ":0". This way telnet/rlogin
30 * shells can actually get the correct information into DISPLAY for
31 * xclients.
32 *----------------------------------------------------------------------*/
33
34 #include "../config.h" /* NECESSARY */
35 #include "rxvt.h" /* NECESSARY */
36
37 #ifdef DISPLAY_IS_IP
38 #include "netdisp.h"
39
40 /*----------------------------------------------------------------------*/
41 /* return NULL a pointer to buffer which may be freed */
42 char *
43 rxvt_network_display (const char *display)
44 {
45 char buffer[1024], *rval = NULL;
46 struct ifconf ifc;
47 struct ifreq *ifr;
48 int i, skfd;
49
50 if (display[0] != ':' && strncmp (display, "unix:", 5))
51 return (char *) display; /* nothing to do */
52
53 ifc.ifc_len = sizeof (buffer); /* Get names of all ifaces */
54 ifc.ifc_buf = buffer;
55
56 if ((skfd = socket (AF_INET, SOCK_DGRAM, 0)) < 0)
57 {
58 perror ("socket");
59 return NULL;
60 }
61
62 if (ioctl (skfd, SIOCGIFCONF, &ifc) < 0)
63 {
64 perror ("SIOCGIFCONF");
65 close (skfd);
66 return NULL;
67 }
68
69 for (i = 0, ifr = ifc.ifc_req;
70 i < (ifc.ifc_len / sizeof (struct ifreq));
71 i++, ifr++)
72 {
73 struct ifreq ifr2;
74
75 strcpy (ifr2.ifr_name, ifr->ifr_name);
76
77 if (ioctl (skfd, SIOCGIFADDR, &ifr2) >= 0)
78 {
79 unsigned long addr;
80 struct sockaddr_in *p_addr;
81
82 p_addr = (struct sockaddr_in *) &ifr2.ifr_addr;
83 addr = htonl ((unsigned long)p_addr->sin_addr.s_addr);
84
85 /*
86 * not "0.0.0.0" or "127.0.0.1" - so format the address
87 */
88 if (addr && addr != 0x7F000001)
89 {
90 char *colon = strchr (display, ':');
91
92 if (colon == NULL)
93 colon = ":0.0";
94
95 rval = rxvt_malloc (strlen (colon) + 16);
96 sprintf (rval, "%d.%d.%d.%d%s",
97 (int) ((addr >> 030) & 0xFF),
98 (int) ((addr >> 020) & 0xFF),
99 (int) ((addr >> 010) & 0xFF),
100 (int) (addr & 0xFF), colon);
101 break;
102 }
103 }
104 }
105
106 close (skfd);
107
108 return rval;
109 }
110 #endif /* DISPLAY_IS_IP */
111 /*----------------------- end-of-file (C source) -----------------------*/