ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/netdisp.C
(Generate patch)

Comparing rxvt-unicode/src/netdisp.C (file contents):
Revision 1.4 by pcg, Sat Jan 31 03:27:45 2004 UTC vs.
Revision 1.5 by pcg, Sun Feb 1 01:34:41 2004 UTC

40/*----------------------------------------------------------------------*/ 40/*----------------------------------------------------------------------*/
41/* return NULL a pointer to buffer which may be freed */ 41/* return NULL a pointer to buffer which may be freed */
42char * 42char *
43rxvt_network_display(const char *display) 43rxvt_network_display(const char *display)
44{ 44{
45 char buffer[1024], *rval = NULL; 45 char buffer[1024], *rval = NULL;
46 struct ifconf ifc; 46 struct ifconf ifc;
47 struct ifreq *ifr; 47 struct ifreq *ifr;
48 int i, skfd; 48 int i, skfd;
49 49
50 if (display[0] != ':' && STRNCMP(display, "unix:", 5)) 50 if (display[0] != ':' && STRNCMP(display, "unix:", 5))
51 return (char *) display; /* nothing to do */ 51 return (char *) display; /* nothing to do */
52 52
53 ifc.ifc_len = sizeof(buffer); /* Get names of all ifaces */ 53 ifc.ifc_len = sizeof(buffer); /* Get names of all ifaces */
54 ifc.ifc_buf = buffer; 54 ifc.ifc_buf = buffer;
55 55
56 if ((skfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { 56 if ((skfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
57 {
57 perror("socket"); 58 perror("socket");
58 return NULL; 59 return NULL;
59 } 60 }
60 if (ioctl(skfd, SIOCGIFCONF, &ifc) < 0) { 61 if (ioctl(skfd, SIOCGIFCONF, &ifc) < 0)
62 {
61 perror("SIOCGIFCONF"); 63 perror("SIOCGIFCONF");
62 close(skfd); 64 close(skfd);
63 return NULL; 65 return NULL;
64 } 66 }
65 for (i = 0, ifr = ifc.ifc_req; 67 for (i = 0, ifr = ifc.ifc_req;
66 i < (ifc.ifc_len / sizeof(struct ifreq)); 68 i < (ifc.ifc_len / sizeof(struct ifreq));
67 i++, ifr++) { 69 i++, ifr++)
70 {
68 struct ifreq ifr2; 71 struct ifreq ifr2;
69 72
70 STRCPY(ifr2.ifr_name, ifr->ifr_name); 73 STRCPY(ifr2.ifr_name, ifr->ifr_name);
71 if (ioctl(skfd, SIOCGIFADDR, &ifr2) >= 0) { 74 if (ioctl(skfd, SIOCGIFADDR, &ifr2) >= 0)
75 {
72 unsigned long addr; 76 unsigned long addr;
73 struct sockaddr_in *p_addr; 77 struct sockaddr_in *p_addr;
74 78
75 p_addr = (struct sockaddr_in *)&(ifr2.ifr_addr); 79 p_addr = (struct sockaddr_in *)&(ifr2.ifr_addr);
76 addr = htonl((unsigned long)p_addr->sin_addr.s_addr); 80 addr = htonl((unsigned long)p_addr->sin_addr.s_addr);
77 81
78 /* 82 /*
79 * not "0.0.0.0" or "127.0.0.1" - so format the address 83 * not "0.0.0.0" or "127.0.0.1" - so format the address
80 */ 84 */
81 if (addr && addr != 0x7F000001) { 85 if (addr && addr != 0x7F000001)
86 {
82 char *colon = STRCHR(display, ':'); 87 char *colon = STRCHR(display, ':');
83 88
84 if (colon == NULL) 89 if (colon == NULL)
85 colon = ":0.0"; 90 colon = ":0.0";
86 91
87 rval = rxvt_malloc(STRLEN(colon) + 16); 92 rval = rxvt_malloc(STRLEN(colon) + 16);
88 sprintf(rval, "%d.%d.%d.%d%s", 93 sprintf(rval, "%d.%d.%d.%d%s",
89 (int)((addr >> 030) & 0xFF), 94 (int)((addr >> 030) & 0xFF),
90 (int)((addr >> 020) & 0xFF), 95 (int)((addr >> 020) & 0xFF),
91 (int)((addr >> 010) & 0xFF), 96 (int)((addr >> 010) & 0xFF),
92 (int)(addr & 0xFF), colon); 97 (int)(addr & 0xFF), colon);
93 break; 98 break;
94 } 99 }
95 } 100 }
96 } 101 }
97 102
98 close(skfd); 103 close(skfd);
99 return rval; 104 return rval;
100} 105}
101#endif /* DISPLAY_IS_IP */ 106#endif /* DISPLAY_IS_IP */
102/*----------------------- end-of-file (C source) -----------------------*/ 107/*----------------------- end-of-file (C source) -----------------------*/

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines