블로그 이미지
안녕1999

카테고리

전체 (3067)
자바스크립트 (20)
안드로이드 (14)
WebGL (4)
변비 (17)
정치,경제 (35)
C언어,ARM (162)
컴퓨터(PC, Note Book, 윈.. (41)
전자회로, PCB (27)
유머,안웃긴,GIF,동영상 (118)
국부론60 (71)
모듈(PCB) (3)
건강 (2)
FreeCAD (25)
PADS (43)
퇴직,퇴사,구직,취업 활동 (3)
C# (86)
엑셀 (8)
워드 (0)
LabView (6)
레고 (30)
FPGA (0)
Total
Today
Yesterday

PC의 ip얻기

C언어,ARM / 2020. 3. 21. 23:00

 

char *GetMyIPstr(int i,char *buf)
{
	char name[128];struct hostent *phe;

	*buf=0;
	if(gethostname(name,sizeof(name))==0)
	{
		phe=gethostbyname(name);
		if(phe!=NULL)
		{
			struct in_addr *pin;int j;
			for(j=0;j<=i;j++)
			{
				pin=(struct in_addr *)phe->h_addr_list[j];
				if(pin==0)break;
				if(i==j)
				{
					strcpy(buf,inet_ntoa(*pin));
					return buf;
				}
			}
		}
	}
	else
	{
		int err=GetLastError();//10093 WSANOTINITIALISED
		if(err==10093)
		{
			WSAStartup();
			return GetMyIPstr(i,buf);
		}
	}
	return 0;
}
wchar_t *GetMyIPstr(int i,wchar_t *buf)
{
	char b[32];
	GetMyIPstr(i,b);
	strcpy(buf,b);
	return buf;
}
Posted by 안녕1999
, |

최근에 달린 댓글

글 보관함