--- rxvt-unicode/src/netdisp.C 2003/11/24 17:31:27 1.2 +++ rxvt-unicode/src/netdisp.C 2004/02/01 01:34:41 1.5 @@ -1,7 +1,6 @@ /*--------------------------------*-C-*---------------------------------* * File: netdisp.c *----------------------------------------------------------------------* - * $Id: netdisp.C,v 1.2 2003/11/24 17:31:27 pcg Exp $ * * All portions of code are copyright by their respective author/s. * Copyright (c) 1996 Chuck Blake @@ -40,65 +39,69 @@ /*----------------------------------------------------------------------*/ /* return NULL a pointer to buffer which may be freed */ -/* EXTPROTO */ char * rxvt_network_display(const char *display) { - char buffer[1024], *rval = NULL; - struct ifconf ifc; - struct ifreq *ifr; - int i, skfd; - - if (display[0] != ':' && STRNCMP(display, "unix:", 5)) - return (char *) display; /* nothing to do */ - - ifc.ifc_len = sizeof(buffer); /* Get names of all ifaces */ - ifc.ifc_buf = buffer; - - if ((skfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { - perror("socket"); - return NULL; + char buffer[1024], *rval = NULL; + struct ifconf ifc; + struct ifreq *ifr; + int i, skfd; + + if (display[0] != ':' && STRNCMP(display, "unix:", 5)) + return (char *) display; /* nothing to do */ + + ifc.ifc_len = sizeof(buffer); /* Get names of all ifaces */ + ifc.ifc_buf = buffer; + + if ((skfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) + { + perror("socket"); + return NULL; } - if (ioctl(skfd, SIOCGIFCONF, &ifc) < 0) { - perror("SIOCGIFCONF"); - close(skfd); - return NULL; + if (ioctl(skfd, SIOCGIFCONF, &ifc) < 0) + { + perror("SIOCGIFCONF"); + close(skfd); + return NULL; } - for (i = 0, ifr = ifc.ifc_req; - i < (ifc.ifc_len / sizeof(struct ifreq)); - i++, ifr++) { - struct ifreq ifr2; - - STRCPY(ifr2.ifr_name, ifr->ifr_name); - if (ioctl(skfd, SIOCGIFADDR, &ifr2) >= 0) { - unsigned long addr; - struct sockaddr_in *p_addr; - - p_addr = (struct sockaddr_in *)&(ifr2.ifr_addr); - addr = htonl((unsigned long)p_addr->sin_addr.s_addr); - - /* - * not "0.0.0.0" or "127.0.0.1" - so format the address - */ - if (addr && addr != 0x7F000001) { - char *colon = STRCHR(display, ':'); - - if (colon == NULL) - colon = ":0.0"; - - rval = rxvt_malloc(STRLEN(colon) + 16); - sprintf(rval, "%d.%d.%d.%d%s", - (int)((addr >> 030) & 0xFF), - (int)((addr >> 020) & 0xFF), - (int)((addr >> 010) & 0xFF), - (int)(addr & 0xFF), colon); - break; - } - } + for (i = 0, ifr = ifc.ifc_req; + i < (ifc.ifc_len / sizeof(struct ifreq)); + i++, ifr++) + { + struct ifreq ifr2; + + STRCPY(ifr2.ifr_name, ifr->ifr_name); + if (ioctl(skfd, SIOCGIFADDR, &ifr2) >= 0) + { + unsigned long addr; + struct sockaddr_in *p_addr; + + p_addr = (struct sockaddr_in *)&(ifr2.ifr_addr); + addr = htonl((unsigned long)p_addr->sin_addr.s_addr); + + /* + * not "0.0.0.0" or "127.0.0.1" - so format the address + */ + if (addr && addr != 0x7F000001) + { + char *colon = STRCHR(display, ':'); + + if (colon == NULL) + colon = ":0.0"; + + rval = rxvt_malloc(STRLEN(colon) + 16); + sprintf(rval, "%d.%d.%d.%d%s", + (int)((addr >> 030) & 0xFF), + (int)((addr >> 020) & 0xFF), + (int)((addr >> 010) & 0xFF), + (int)(addr & 0xFF), colon); + break; + } + } } - close(skfd); - return rval; + close(skfd); + return rval; } #endif /* DISPLAY_IS_IP */ /*----------------------- end-of-file (C source) -----------------------*/