2 * Filename: ip-screen.c
3 * Purpose: print ip address of configured network interfaces
4 * Authors: grml-team (grml.org), (c) Michael Gebetsroither <gebi@grml.org>
5 * Bug-Reports: see http://grml.org/bugs/
6 * License: This file is licensed under the GPL v2.
7 *********************************************************************************/
13 #include <sys/types.h>
14 #include <sys/ioctl.h>
15 #include <sys/socket.h>
17 #include <netinet/in.h>
18 #include <arpa/inet.h>
21 #define WRITE(x) write(1, x, strlen(x))
24 #define ERR_MSG "[running ip-screen failed]\n"
25 #define NO_IFACE_MSG "[ network n/a ]\n"
36 int total, remaining, current;
39 struct sockaddr_in *addr;
40 struct in_addr *tmp = NULL;
41 char buf[sizeof(struct ifreq)*MAX_IFS];
44 sockfd = socket(PF_INET,SOCK_DGRAM,0);
49 ifc.ifc_len = sizeof(buf);
50 if (-1 == ioctl(sockfd, SIOCGIFCONF, &ifc))
53 remaining = total = ifc.ifc_len;
56 if( ifrp->ifr_addr.sa_family == AF_INET ) {
57 if (-1 == ioctl(sockfd, SIOCGIFFLAGS, ifrp)) {
60 addr = (struct sockaddr_in *)&(ifrp->ifr_addr);
61 if(!(ifrp->ifr_flags & IFF_LOOPBACK)) {
63 ctmp = inet_ntoa(*tmp);
67 tmp = &addr->sin_addr;
71 current = sizeof(struct ifreq);
72 ifrp = (struct ifreq *)( ((char *)ifrp)+current );
77 ctmp = inet_ntoa(*tmp);
87 /** END OF FILE *****************************************************************/