All pastes #743724 Raw Edit

Someone

public c v1 · immutable
·published 2007-10-20 18:19 UTC
rendered paste body
#include <stdio.h>#include <sys/types.h>#include <fcntl.h>#include <netinet/in.h>#include <unistd.h>#include <sys/socket.h>#include <arpa/inet.h>#include <netdb.h>#include <sys/ioctl.h>#include <net/if.h>#include <errno.h>int main(void) {        static struct ifreq ifr;        static char *ip;        static char *ifname = "eth0";        int sock;        //create our sock        sock = socket(AF_INET,SOCK_DGRAM,0);        strcpy( ifr.ifr_name, ifname );        ifr.ifr_addr.sa_family = AF_INET;        // w00p get the iface addr ;>        if (ioctl( sock, SIOCGIFADDR, &ifr ) < 0)        perror("ioctl:");        ip = inet_ntoa( ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr );        printf("%s\n",ip);        return 0;}