|
发表于 2004-8-6 08:22:19
|
显示全部楼层
从我的程序中拷出来的,那些头文件不一定都要
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <sys/ioctl.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <netinet/ip.h>
- #include <net/if.h>
- gboolean
- get_my_address (struct in_addr *addr)
- {
- struct ifreq req; /* current ifreq struct scaned */
- int sock;
- sock = socket(AF_INET, SOCK_DGRAM, 0);
- strncpy (req.ifr_name, "eth0", IFNAMSIZ);
- if ( ioctl(sock, SIOCGIFADDR, &req) < 0 )
- {
- DEBU(G "failed to ioctl: %s\n", strerror (errno));
- return FALSE;
- }
- memcpy (addr, &((struct sockaddr_in *) &req.ifr_addr)->sin_addr, sizeof (struct in_addr));
- return TRUE;
- }
复制代码 |
|