All pastes #515979 Raw Edit

codaine

public c v1 · immutable
#515979 ·published 2007-05-28 13:35 UTC
rendered paste body
   #include <stdio.h>   #include <string.h>   #include <sys/ioctl.h>   #include <sys/socket.h>   #include <sys/types.h>   #include <net/if.h>   #include <netdb.h>   #include <netinet/in.h>   #include <arpa/inet.h>   int main(void)   {     int                sfd, i;     struct ifreq       ifr;     struct sockaddr_in *sin = (struct sockaddr_in *) &ifr.ifr_addr;     memset(&ifr, 0, sizeof ifr);     if (0 > (sfd = socket(AF_INET, SOCK_STREAM, 0))) {       perror("socket()");       exit(1);     }     strcpy(ifr.ifr_name, "eth0");     sin->sin_family = AF_INET;     if (0 == ioctl(sfd, SIOCGIFADDR, &ifr)) {       printf("%s: %s\n", ifr.ifr_name, inet_ntoa(sin->sin_addr));     }     return 0;   }