WSAStringToAdress & WSAAddressToString

  • inet_ntoa, inet_addr와 같은 기능
  • 다양한 프로토콜에 적용 가능
  • 윈도우에 종속적인 코드가 만들어져 타 운영체제로의 이식성 감소

 

WSAStringToAdress

#include <winsock2.h>
INT WSAStringToAddress(
	LPTSTR AddressString, INT AddressFamily, LPWSAPROTOCOL_INFO lpProtocolInfo,
    LPSOCKADDR lpAddress, LPINT lpAddressLength
);	// 성공 시 0, 실패 시 SOCKER_ERROR 리턴
  • AddressString: IP와 PORT번호를 담고 있는 문자열의 주소 값 전달
  • AddressFamily: 첫 번째 인자로 전달된 주소정보가 속하는 주소체계 정보 전달
  • lpProtocolInfo 프로토콜 프로바이더(Provider) 설정, 일반적으로 NULL 전달
  • lpAddress 주소정보를 담을 구조체 변수의 주소 값 전달
  • lpAddressLength 네 번째 인자로 전달된 주소 값의 변수 크기를 담고 있는 변수의 주소 값 전달

 

WSAAddressToString

#include <winsock2.h>
INT WSAAddressToString(
	LPSOCKADDR lpsaAddress, DWORD dwAddressLength, LPWSAPROTOCOL_INFO lpProtocolInfo, 
    LPTSTR lpszAddressString, LPDWORD lpdwAddressStringLength
); //성공 시 0, 실패 시 SOCKET_ERROR 리턴
  • lpsaAddress: 문자열로 변환할 주소정보를 지니는 구조체 변수의 주소 값 전달
  • dwAddressLength: 첫 번째 인자로 전달된 구조체 변수의 크기 전달
  • lpProtocolInfo: 프로토콜 프로바이더(Provider) 설정, 일반적으로 NULL 전달
  • lpszAddressString: 문자열로 변환된 결과를 저장할 배열의 주소 값 전달
  • lpdwAddressStringLength: 네 번째 인자로 전달된 주소 값의 배열 크기를 담고 있는 변수의 주소 값 전달

 

+ Recent posts