### ms-tsts_TSVIPRpc.idl
"""
RPC definitions for the following interfaces:
- TSVIPPublic (v1.0): 53b46b02-c73b-4a3e-8dee-b16b80672fc0
This file is auto-generated by midl-to-scapy, do not modify.
"""

import uuid

from scapy.fields import StrFixedLenField, StrFixedLenFieldUtf16
from scapy.layers.dcerpc import (
    NDRPacket,
    DceRpcOp,
    NDRIntField,
    NDRPacketField,
    NDRShortField,
    NDRUnionField,
    NDRVarStrLenField,
    register_dcerpc_interface,
)


class ipv4_sub0(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRShortField("sin_port", 0),
        NDRIntField("in_addr", 0),
        StrFixedLenField("sin_zero", "", length=8),
    ]


class ipv6_sub1(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRShortField("sin6_port", 0),
        NDRIntField("sin6_flowinfo", 0),
        StrFixedLenFieldUtf16("sin6_addr", "", length=8 * 2),
        NDRIntField("sin6_scope_id", 0),
    ]


class TSVIP_SOCKADDR(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRUnionField(
            [
                (
                    NDRPacketField("u", ipv4_sub0(), ipv4_sub0),
                    ((lambda pkt: None == 2), (lambda _, val: val.tag == 2)),
                ),
                (
                    NDRPacketField("u", ipv6_sub1(), ipv6_sub1),
                    ((lambda pkt: None == 23), (lambda _, val: val.tag == 23)),
                ),
            ],
            StrFixedLenField("u", "", length=0),
            align=(4, 4),
            switch_fmt=("I", "I"),
        )
    ]


class TSVIPAddress(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("dwVersion", 0),
        NDRPacketField("IPAddress", TSVIP_SOCKADDR(), TSVIP_SOCKADDR),
        NDRIntField("PrefixOrSubnetMask", 0),
        NDRIntField("PhysicalAddressLength", None, size_of="PhysicalAddress"),
        NDRVarStrLenField(
            "PhysicalAddress", "", length_is=lambda pkt: pkt.PhysicalAddressLength
        ),
        NDRIntField("LeaseExpires", 0),
        NDRIntField("T1", 0),
        NDRIntField("T2", 0),
    ]


class TSVIPSession(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("dwVersion", 0),
        NDRIntField("SessionId", 0),
        NDRPacketField("SessionIP", TSVIPAddress(), TSVIPAddress),
    ]


class RpcGetSessionIP_Request(NDRPacket):
    fields_desc = [NDRShortField("Family", 0), NDRIntField("SessionId", 0)]


class RpcGetSessionIP_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("ppVIPSession", TSVIPSession(), TSVIPSession),
        NDRIntField("status", 0),
    ]


TSVIPPUBLIC_OPNUMS = {0: DceRpcOp(RpcGetSessionIP_Request, RpcGetSessionIP_Response)}
register_dcerpc_interface(
    name="TSVIPPublic",
    uuid=uuid.UUID("53b46b02-c73b-4a3e-8dee-b16b80672fc0"),
    version="1.0",
    opnums=TSVIPPUBLIC_OPNUMS,
)
