コード例 #1
0
ファイル: ether.py プロジェクト: superbobry/cxnet
ETH_P_SNAP      = 0x0005    # Internal only
ETH_P_DDCMP     = 0x0006    # DEC DDCMP: Internal only
ETH_P_WAN_PPP   = 0x0007    # Dummy type for WAN PPP frames
ETH_P_PPP_MP    = 0x0008    # Dummy type for PPP MP frames
ETH_P_LOCALTALK = 0x0009    # Localtalk pseudo type
ETH_P_PPPTALK   = 0x0010    # Dummy type for Atalk over PPP
ETH_P_TR_802_2  = 0x0011    # 802.2 frames
ETH_P_MOBITEX   = 0x0015    # Mobitex ([email protected])
ETH_P_CONTROL   = 0x0016    # Card specific control frames
ETH_P_IRDA      = 0x0017    # Linux-IrDA
ETH_P_ECONET    = 0x0018    # Acorn Econet
ETH_P_HDLC      = 0x0019    # HDLC frames
ETH_P_ARCNET    = 0x001A    # 1A for ArcNet :-)

##
#    This is an Ethernet frame header.
##
 
class ethhdr (BigEndianStructure):
    _pack_ = 1
    _fields_ = [
        ("dest",    c_uint8 * ETH_ALEN),    # destination eth addr
        ("source",  c_uint8 * ETH_ALEN),    # source ether addr
        ("proto",   c_uint16),              # packet type ID field 
    ]


__all__ = [
    "ethhdr",
] + export_by_prefix("ETH",globals())
コード例 #2
0
ファイル: arp.py プロジェクト: superbobry/cxnet
ARPOP_InREPLY        = 9    # InARP reply
ARPOP_NAK            = 10    # (ATM)ARP NAK


## ARP Flag values.
ATF_COM         = 0x02    # completed entry (ha valid)
ATF_PERM        = 0x04    # permanent entry
ATF_PUBL        = 0x08    # publish entry
ATF_USETRAILERS = 0x10    # has requested trailers
ATF_NETMASK     = 0x20    # want to use a netmask (only for proxy entries)
ATF_DONTPUB     = 0x40    # don't answer this addresses

##
#    This structure defines an ethernet arp header.
##

class arphdr (BigEndianStructure):
    _fields_ = [
        ("hrd",    c_uint16),    # format of hardware address
        ("pro",    c_uint16),    # format of protocol address
        ("hln",    c_uint8),     # length of hardware address
        ("pln",    c_uint8),     # length of protocol address
        ("op",     c_uint16),    # ARP opcode (command)
    ]

__all__ = [
    "arphdr",
] + export_by_prefix("ARP",globals()) +\
    export_by_prefix("ATF",globals()) +\
    export_by_prefix("M_",globals())
コード例 #3
0
ファイル: rtnl.py プロジェクト: superbobry/cxnet
iff["LOOPBACK"]     = 0x8    # is a loopback net
iff["POINTOPOINT"]  = 0x10    # interface is has p-p link
iff["NOTRAILERS"]   = 0x20    # avoid use of trailers
iff["RUNNING"]      = 0x40    # resources allocated
iff["NOARP"]        = 0x80    # no ARP protocol
iff["PROMISC"]      = 0x100    # receive all packets
iff["ALLMULTI"]     = 0x200    # receive all multicast packets
iff["MASTER"]       = 0x400    # master of a load balancer
iff["SLAVE"]        = 0x800    # slave of a load balancer
iff["MULTICAST"]    = 0x1000# supports multicast
iff["PORTSEL"]      = 0x2000# can set media type
iff["AUTOMEDIA"]    = 0x4000# auto media select active
iff["DYNAMIC"]      = 0x8000# dialup device with changing addresses

export = [ "SIOCGIWNAME" ]
export += export_by_prefix("NDA",globals())
export += export_by_prefix("IF",globals())
export += export_by_prefix("RT",globals())
export += export_by_prefix("M_",globals())


class rtnl_msg_parser(object):
    """
    Generic RT Netlink attribute parser
    """
    inet = socket(AF_INET,SOCK_DGRAM,0)
    tmap = {
        "add":  {
            "address":  RTM_NEWADDR,
            },
        "remove":  {
コード例 #4
0
ファイル: ip4.py プロジェクト: superbobry/cxnet
        ("hdrlen",      c_uint8),
        ("padlen",      c_uint8),
        ("reserved",    c_uint8),
    ]

class IPv4Protocol(GenericProtocol):

    def post(self,msg):
        msg.hdr.ihl = sizeof(msg.hdr) // 4
        msg.hdr.tot_len = sizeof(msg.payload) + sizeof(msg.hdr)
        msg.hdr.check = 0
        msg.hdr.check = csum(msg.hdr,sizeof(msg.hdr))
        return msg


__all__ = [
    "IPv4Protocol",
    "iphdr",
    "ip_beet_phdr",
    "ip_comp_hdr",
    "ip_esp_hdr",
    "ip_auth_hdr",
    "iptos_tos",
    "iptos_prec",
    "ipopt_copied",
    "ipopt_class",
    "ipopt_number",
    "MAXTTL",
    "MAX_IPOPTLEN",
] + export_by_prefix("IP",globals())
コード例 #5
0
ファイル: core.py プロジェクト: superbobry/cxnet
        if not size:
            size = sizeof(msg)

        sa = sockaddr()
        sa.family = AF_NETLINK
        sa.pid = 0

        self.prepare(msg, size)

        l = libc.sendto(self.fd, byref(msg), size, 0, byref(sa), sizeof(sa))
        return l

    def prepare(self, msg, size=0):
        """
        Adjust message header fields before sending
        """

        if not size:
            size = sizeof(msg)

        msg.hdr.length = size
        msg.hdr.pid = getpid()

__all__ = [
    "nlmsghdr",
    "nlmsg",
    "attr_msg",
    "nl_socket",
    "nlattr",
] + export_by_prefix("NL",globals()) + export_by_prefix("NETLINK",globals())