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 * Latest change: Thu Mar 30 23:09:28 CEST 2006 [mika]
8 *********************************************************************************/
14 #include <sys/types.h>
15 #include <sys/ioctl.h>
16 #include <sys/socket.h>
18 #include <netinet/in.h>
19 #include <arpa/inet.h>
22 #define WRITE(x) write(1, x, strlen(x))
25 #define ERR_MSG "[running ip-screen failed]\n"
26 #define NO_IFACE_MSG "[ network n/a ]\n"
37 int total, remaining, current;
40 struct sockaddr_in *addr;
41 struct in_addr *tmp = NULL;
42 char buf[sizeof(struct ifreq)*MAX_IFS];
45 sockfd = socket(PF_INET,SOCK_DGRAM,0);
50 ifc.ifc_len = sizeof(buf);
51 if (-1 == ioctl(sockfd, SIOCGIFCONF, &ifc))
54 remaining = total = ifc.ifc_len;
57 if( ifrp->ifr_addr.sa_family == AF_INET ) {
58 if (-1 == ioctl(sockfd, SIOCGIFFLAGS, ifrp)) {
61 addr = (struct sockaddr_in *)&(ifrp->ifr_addr);
62 if(!(ifrp->ifr_flags & IFF_LOOPBACK)) {
64 ctmp = inet_ntoa(*tmp);
68 tmp = &addr->sin_addr;
72 current = sizeof(struct ifreq);
73 ifrp = (struct ifreq *)( ((char *)ifrp)+current );
78 ctmp = inet_ntoa(*tmp);
88 /** END OF FILE *****************************************************************/