Linux?????????c??????????IP
???????????? ???????[ 2014/4/17 9:44:37 ] ????????Linux ???? ????
????????gethostname??gethostbyname???????IP?????????????????????????????????????????????????Щ????????ò????????????????????????SOCKET??????????????????????£?
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <linux/types.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <net/if.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
//??????
//????IP????????
//?????0=?????-1=???
int getlocalip(char* outip)
{
int i=0;
int sockfd;
struct ifconf ifconf;
char buf[512];
struct ifreq *ifreq;
char* ip;
//?????ifconf
ifconf.ifc_len = 512;
ifconf.ifc_buf = buf;
if((sockfd = socket(AF_INET?? SOCK_DGRAM?? 0))<0)
{
return -1;
}
ioctl(sockfd?? SIOCGIFCONF?? &ifconf); //??????н?????
close(sockfd);
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11