X-Git-Url: http://git.grml.org/?p=grml-scripts.git;a=blobdiff_plain;f=compile%2Fip-screen.c;fp=compile%2Fip-screen.c;h=0000000000000000000000000000000000000000;hp=7c46a47cb1d325ca242328197c93a511393195f5;hb=68552116672d8462fb256c0771888a4654c3687d;hpb=80e422b789147a8706e450722c6e45bd42b3a5d1 diff --git a/compile/ip-screen.c b/compile/ip-screen.c deleted file mode 100644 index 7c46a47..0000000 --- a/compile/ip-screen.c +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Filename: ip-screen.c - * Purpose: print ip address of configured network interfaces - * Authors: grml-team (grml.org), (c) Michael Gebetsroither - * Bug-Reports: see http://grml.org/bugs/ - * License: This file is licensed under the GPL v2. - *********************************************************************************/ - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#define MAX_IFS 32 -#define WRITE(x) write(1, x, strlen(x)) - -// USER CONFIG -#define ERR_MSG "[running ip-screen failed]\n" -#define NO_IFACE_MSG "[ network n/a ]\n" - -void die(int errcode) -{ - WRITE(ERR_MSG); - exit(errcode); -} - -int main() -{ - int sockfd; - int total, remaining, current; - struct ifconf ifc; - struct ifreq *ifrp; - struct sockaddr_in *addr; - struct in_addr *tmp = NULL; - char buf[sizeof(struct ifreq)*MAX_IFS]; - char *ctmp = NULL; - - sockfd = socket(PF_INET,SOCK_DGRAM,0); - if(-1 == sockfd) - die(1); - - ifc.ifc_buf = buf; - ifc.ifc_len = sizeof(buf); - if (-1 == ioctl(sockfd, SIOCGIFCONF, &ifc)) - die(2); - - remaining = total = ifc.ifc_len; - ifrp = ifc.ifc_req; - while(remaining) { - if( ifrp->ifr_addr.sa_family == AF_INET ) { - if (-1 == ioctl(sockfd, SIOCGIFFLAGS, ifrp)) { - die(3); - } - addr = (struct sockaddr_in *)&(ifrp->ifr_addr); - if(!(ifrp->ifr_flags & IFF_LOOPBACK)) { - if(tmp) { - ctmp = inet_ntoa(*tmp); - WRITE(ctmp); - WRITE(" | "); - } - tmp = &addr->sin_addr; - } - } - - current = sizeof(struct ifreq); - ifrp = (struct ifreq *)( ((char *)ifrp)+current ); - remaining -= current; - } - - if(tmp){ - ctmp = inet_ntoa(*tmp); - WRITE(ctmp); - WRITE("\n"); - } else { - WRITE(NO_IFACE_MSG); - } - - return 0; -} - -/** END OF FILE *****************************************************************/