diff options
| author | stkhan <personal@slickd.xyz> | 2022-03-18 08:09:07 -0800 |
|---|---|---|
| committer | stkhan <personal@slickd.xyz> | 2022-03-18 08:09:07 -0800 |
| commit | e20a439f0de08052fad50669fd005dee14d40cae (patch) | |
| tree | 8ffed60a1dce40ae64fd8f336a4d1b5d103683f1 /scripts/ip.c | |
| parent | a33351c3345f7b8657e6415878a73b5fedb09d72 (diff) | |
Update dwm, added farbfeld, sent, and wmname plus more
Diffstat (limited to 'scripts/ip.c')
| -rw-r--r-- | scripts/ip.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/scripts/ip.c b/scripts/ip.c new file mode 100644 index 0000000..3276696 --- /dev/null +++ b/scripts/ip.c @@ -0,0 +1,32 @@ +#include <stdio.h> +#include <unistd.h> +#include <string.h> /* for strncpy */ + +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/ioctl.h> +#include <netinet/in.h> +#include <net/if.h> +#include <arpa/inet.h> + +int +main() +{ + int fd; + struct ifreq ifr; + + fd = socket(AF_INET, SOCK_DGRAM, 0); + + /* I want to get an IPv4 IP address */ + ifr.ifr_addr.sa_family = AF_INET; + strncpy(ifr.ifr_name, "wlan0", IFNAMSIZ-1); + + ioctl(fd, SIOCGIFADDR, &ifr); + + close(fd); + + /* display result */ + printf("%s\n", inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr)); + + return 0; +} |