… | |
… | |
5 | * All portions of code are copyright by their respective author/s. |
5 | * All portions of code are copyright by their respective author/s. |
6 | * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk> |
6 | * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk> |
7 | * - original version |
7 | * - original version |
8 | * Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com> |
8 | * Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com> |
9 | * - extensive modifications |
9 | * - extensive modifications |
|
|
10 | * Copyright (c) 1996 Chuck Blake <cblake@BBN.COM> |
|
|
11 | * Copyright (c) 1997 mj olesen <olesen@me.queensu.ca> |
|
|
12 | * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> |
10 | * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com> |
13 | * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com> |
11 | * - extensive modifications |
14 | * - extensive modifications |
12 | * Copyright (c) 1999 D J Hawkey Jr <hawkeyd@visi.com> |
15 | * Copyright (c) 1999 D J Hawkey Jr <hawkeyd@visi.com> |
13 | * - QNX support |
16 | * - QNX support |
14 | * Copyright (c) 2003-2006 Marc Lehmann <pcg@goof.com> |
17 | * Copyright (c) 2003-2006 Marc Lehmann <pcg@goof.com> |
… | |
… | |
37 | #include "init.h" |
40 | #include "init.h" |
38 | |
41 | |
39 | #include <limits> |
42 | #include <limits> |
40 | |
43 | |
41 | #include <csignal> |
44 | #include <csignal> |
|
|
45 | |
|
|
46 | #ifdef DISPLAY_IS_IP |
|
|
47 | /* On Solaris link with -lsocket and -lnsl */ |
|
|
48 | #include <sys/types.h> |
|
|
49 | #include <sys/socket.h> |
|
|
50 | |
|
|
51 | /* these next two are probably only on Sun (not Solaris) */ |
|
|
52 | #ifdef HAVE_SYS_SOCKIO_H |
|
|
53 | #include <sys/sockio.h> |
|
|
54 | #endif |
|
|
55 | #ifdef HAVE_SYS_BYTEORDER_H |
|
|
56 | #include <sys/byteorder.h> |
|
|
57 | #endif |
|
|
58 | |
|
|
59 | #include <netinet/in.h> |
|
|
60 | #include <arpa/inet.h> |
|
|
61 | #include <net/if.h> |
|
|
62 | #include <net/if_arp.h> |
|
|
63 | |
|
|
64 | static char * |
|
|
65 | rxvt_network_display (const char *display) |
|
|
66 | { |
|
|
67 | char buffer[1024], *rval = NULL; |
|
|
68 | struct ifconf ifc; |
|
|
69 | struct ifreq *ifr; |
|
|
70 | int i, skfd; |
|
|
71 | |
|
|
72 | if (display[0] != ':' && strncmp (display, "unix:", 5)) |
|
|
73 | return (char *) display; /* nothing to do */ |
|
|
74 | |
|
|
75 | ifc.ifc_len = sizeof (buffer); /* Get names of all ifaces */ |
|
|
76 | ifc.ifc_buf = buffer; |
|
|
77 | |
|
|
78 | if ((skfd = socket (AF_INET, SOCK_DGRAM, 0)) < 0) |
|
|
79 | { |
|
|
80 | perror ("socket"); |
|
|
81 | return NULL; |
|
|
82 | } |
|
|
83 | |
|
|
84 | if (ioctl (skfd, SIOCGIFCONF, &ifc) < 0) |
|
|
85 | { |
|
|
86 | perror ("SIOCGIFCONF"); |
|
|
87 | close (skfd); |
|
|
88 | return NULL; |
|
|
89 | } |
|
|
90 | |
|
|
91 | for (i = 0, ifr = ifc.ifc_req; |
|
|
92 | i < (ifc.ifc_len / sizeof (struct ifreq)); |
|
|
93 | i++, ifr++) |
|
|
94 | { |
|
|
95 | struct ifreq ifr2; |
|
|
96 | |
|
|
97 | strcpy (ifr2.ifr_name, ifr->ifr_name); |
|
|
98 | |
|
|
99 | if (ioctl (skfd, SIOCGIFADDR, &ifr2) >= 0) |
|
|
100 | { |
|
|
101 | unsigned long addr; |
|
|
102 | struct sockaddr_in *p_addr; |
|
|
103 | |
|
|
104 | p_addr = (struct sockaddr_in *) &ifr2.ifr_addr; |
|
|
105 | addr = htonl ((unsigned long)p_addr->sin_addr.s_addr); |
|
|
106 | |
|
|
107 | /* |
|
|
108 | * not "0.0.0.0" or "127.0.0.1" - so format the address |
|
|
109 | */ |
|
|
110 | if (addr && addr != 0x7F000001) |
|
|
111 | { |
|
|
112 | char *colon = strchr (display, ':'); |
|
|
113 | |
|
|
114 | if (colon == NULL) |
|
|
115 | colon = ":0.0"; |
|
|
116 | |
|
|
117 | rval = rxvt_malloc (strlen (colon) + 16); |
|
|
118 | sprintf (rval, "%d.%d.%d.%d%s", |
|
|
119 | (int) ((addr >> 030) & 0xFF), |
|
|
120 | (int) ((addr >> 020) & 0xFF), |
|
|
121 | (int) ((addr >> 010) & 0xFF), |
|
|
122 | (int) (addr & 0xFF), colon); |
|
|
123 | break; |
|
|
124 | } |
|
|
125 | } |
|
|
126 | } |
|
|
127 | |
|
|
128 | close (skfd); |
|
|
129 | |
|
|
130 | return rval; |
|
|
131 | } |
|
|
132 | #endif |
42 | |
133 | |
43 | const char *const def_colorName[] = |
134 | const char *const def_colorName[] = |
44 | { |
135 | { |
45 | COLOR_FOREGROUND, |
136 | COLOR_FOREGROUND, |
46 | COLOR_BACKGROUND, |
137 | COLOR_BACKGROUND, |