ホーム › Networking.WinSock › getservbyport
getservbyport
関数ポート番号に対応するサービス情報を取得する。
シグネチャ
// WS2_32.dll
#include <windows.h>
SERVENT* getservbyport(
INT port,
LPCSTR proto // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| port | INT | in |
| proto | LPCSTR | inoptional |
戻り値の型: SERVENT*
各言語での呼び出し定義
// WS2_32.dll
#include <windows.h>
SERVENT* getservbyport(
INT port,
LPCSTR proto // optional
);[DllImport("WS2_32.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr getservbyport(
int port, // INT
[MarshalAs(UnmanagedType.LPStr)] string proto // LPCSTR optional
);<DllImport("WS2_32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function getservbyport(
port As Integer, ' INT
<MarshalAs(UnmanagedType.LPStr)> proto As String ' LPCSTR optional
) As IntPtr
End Function' port : INT
' proto : LPCSTR optional
Declare PtrSafe Function getservbyport Lib "ws2_32" ( _
ByVal port As Long, _
ByVal proto As String) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
getservbyport = ctypes.windll.ws2_32.getservbyport
getservbyport.restype = ctypes.c_void_p
getservbyport.argtypes = [
ctypes.c_int, # port : INT
wintypes.LPCSTR, # proto : LPCSTR optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WS2_32.dll')
getservbyport = Fiddle::Function.new(
lib['getservbyport'],
[
Fiddle::TYPE_INT, # port : INT
Fiddle::TYPE_VOIDP, # proto : LPCSTR optional
],
Fiddle::TYPE_VOIDP)#[link(name = "ws2_32")]
extern "system" {
fn getservbyport(
port: i32, // INT
proto: *const u8 // LPCSTR optional
) -> *mut SERVENT;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("WS2_32.dll", SetLastError = true)]
public static extern IntPtr getservbyport(int port, [MarshalAs(UnmanagedType.LPStr)] string proto);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WS2_32_getservbyport' -Namespace Win32 -PassThru
# $api::getservbyport(port, proto)#uselib "WS2_32.dll"
#func global getservbyport "getservbyport" sptr, sptr
; getservbyport port, proto ; 戻り値は stat
; port : INT -> "sptr"
; proto : LPCSTR optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "WS2_32.dll"
#cfunc global getservbyport "getservbyport" int, str
; res = getservbyport(port, proto)
; port : INT -> "int"
; proto : LPCSTR optional -> "str"; SERVENT* getservbyport(INT port, LPCSTR proto)
#uselib "WS2_32.dll"
#cfunc global getservbyport "getservbyport" int, str
; res = getservbyport(port, proto)
; port : INT -> "int"
; proto : LPCSTR optional -> "str"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
ws2_32 = windows.NewLazySystemDLL("WS2_32.dll")
procgetservbyport = ws2_32.NewProc("getservbyport")
)
// port (INT), proto (LPCSTR optional)
r1, _, err := procgetservbyport.Call(
uintptr(port),
uintptr(unsafe.Pointer(windows.BytePtrFromString(proto))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // SERVENT*function getservbyport(
port: Integer; // INT
proto: PAnsiChar // LPCSTR optional
): Pointer; stdcall;
external 'WS2_32.dll' name 'getservbyport';result := DllCall("WS2_32\getservbyport"
, "Int", port ; INT
, "AStr", proto ; LPCSTR optional
, "Ptr") ; return: SERVENT*●getservbyport(port, proto) = DLL("WS2_32.dll", "void* getservbyport(int, char*)")
# 呼び出し: getservbyport(port, proto)
# port : INT -> "int"
# proto : LPCSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。