Win32 API 日本語リファレンス
ホームNetworking.WinSock › inet_ntoa

inet_ntoa

関数
IPアドレスをドット区切りの文字列へ変換する。
DLLWS2_32.dll呼出規約winapiSetLastErrorあり対応OSWindows 8.1 以降

シグネチャ

// WS2_32.dll
#include <windows.h>

LPSTR inet_ntoa(
    IN_ADDR in
);

パラメーター

名前方向
inIN_ADDRin

戻り値の型: LPSTR

各言語での呼び出し定義

// WS2_32.dll
#include <windows.h>

LPSTR inet_ntoa(
    IN_ADDR in
);
[DllImport("WS2_32.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr inet_ntoa(
    IN_ADDR in   // IN_ADDR
);
<DllImport("WS2_32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function inet_ntoa(
    [in] As IN_ADDR   ' IN_ADDR
) As IntPtr
End Function
' in : IN_ADDR
Declare PtrSafe Function inet_ntoa Lib "ws2_32" ( _
    ByVal in As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

inet_ntoa = ctypes.windll.ws2_32.inet_ntoa
inet_ntoa.restype = wintypes.LPSTR
inet_ntoa.argtypes = [
    IN_ADDR,  # in : IN_ADDR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WS2_32.dll')
inet_ntoa = Fiddle::Function.new(
  lib['inet_ntoa'],
  [
    Fiddle::TYPE_VOIDP,  # in : IN_ADDR
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "ws2_32")]
extern "system" {
    fn inet_ntoa(
        in: IN_ADDR  // IN_ADDR
    ) -> *mut u8;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("WS2_32.dll", SetLastError = true)]
public static extern IntPtr inet_ntoa(IN_ADDR in);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WS2_32_inet_ntoa' -Namespace Win32 -PassThru
# $api::inet_ntoa(in)
#uselib "WS2_32.dll"
#func global inet_ntoa "inet_ntoa" sptr
; inet_ntoa in   ; 戻り値は stat
; in : IN_ADDR -> "sptr"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "WS2_32.dll"
#cfunc global inet_ntoa "inet_ntoa" int
; res = inet_ntoa(in)
; in : IN_ADDR -> "int"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。
; LPSTR inet_ntoa(IN_ADDR in)
#uselib "WS2_32.dll"
#cfunc global inet_ntoa "inet_ntoa" int
; res = inet_ntoa(in)
; in : IN_ADDR -> "int"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	ws2_32 = windows.NewLazySystemDLL("WS2_32.dll")
	procinet_ntoa = ws2_32.NewProc("inet_ntoa")
)

// in (IN_ADDR)
r1, _, err := procinet_ntoa.Call(
	uintptr(in),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // LPSTR
function inet_ntoa(
  in: IN_ADDR   // IN_ADDR
): PAnsiChar; stdcall;
  external 'WS2_32.dll' name 'inet_ntoa';
result := DllCall("WS2_32\inet_ntoa"
    , "Ptr", in   ; IN_ADDR
    , "Ptr")   ; return: LPSTR
●inet_ntoa(in) = DLL("WS2_32.dll", "char* inet_ntoa(void*)")
# 呼び出し: inet_ntoa(in)
# in : IN_ADDR -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。