Pack the data for the SCP packet.
185144
def packed_data(self):
        """"""
        # Pack the header
        scp_header = struct.pack("<2H", self.cmd_rc, self.seq)

        # Potential loop intentionally unrolled
        if self.arg1 is not None:
            scp_header += struct.pack('<I', self.arg1)
        if self.arg2 is not None:
            scp_header += struct.pack('<I', self.arg2)
        if self.arg3 is not None:
            scp_header += struct.pack('<I', self.arg3)

        # Return the SCP header and the rest of the data
        return scp_header + self.data
918830
def _pack(self, msg):
        
        n = len(msg) 
        a = array.array('c')
        a.append(chr((n >> 24) & 0xFF))
        a.append(chr((n >> 16) & 0xFF))
        a.append(chr((n >>  8) & 0xFF))
        a.append(chr(n & 0xFF))
        return a.tostring() + msg
172678
def pack(cls, data):
        ''''''
        return struct.pack('>ll', len(data) + 4, cls.FRAME_TYPE) + data
295942
def pull(self):
        """"""

        # For each packet in the pcap process the contents
        for item in self.input_stream:

            # Print out the timestamp in UTC
            print('Timestamp: %s' % item['timestamp'])

            # Unpack the Ethernet frame (mac src/dst, ethertype)
            print('Ethernet Frame: %s --> %s  (type: %d)' % \
                  (net_utils.mac_to_str(item['eth']['src']), net_utils.mac_to_str(item['eth']['dst']), item['eth']['type']))

            # Print out the Packet info
            packet_type = item['packet']['type']
            print('Packet: %s ' % packet_type, end='')
            packet = item['packet']
            if packet_type in ['IP', 'IP6']:
                print('%s --> %s (len:%d ttl:%d)' % (net_utils.inet_to_str(packet['src']), net_utils.inet_to_str(packet['dst']),
                                                     packet['len'], packet['ttl']), end='')
                if packet_type == 'IP':
                    print('-- Frag(df:%d mf:%d offset:%d)' % (packet['df'], packet['mf'], packet['offset']))
                else:
                    print()
            else:
                print(str(packet))

            # Print out transport and application layers
            if item['transport']:
                transport_info = item['transport']
                print('Transport: %s ' % transport_info['type'], end='')
                for key, value in compat.iteritems(transport_info):
                    if key != 'data':
                        print(key+':'+repr(value), end=' ')

                # Give summary info about data
                data = transport_info['data']
                print('\nData: %d bytes' % len(data), end='')
                if data:
                    print('(%s...)' % repr(data)[:30])
                else:
                    print()

            # Application data
            if item['application']:
                print('Application: %s' % item['application']['type'], end='')
                print(str(item['application']))

            # Is there domain info?
            if 'src_domain' in packet:
                print('Domains: %s --> %s' % (packet['src_domain'], packet['dst_domain']))

            # Tags
            if 'tags' in item:
                print(list(item['tags']))
            print()
313975
def __pack_message(operation, data):
    
    request_id = _randint()
    message = struct.pack("<i", 16 + len(data))
    message += struct.pack("<i", request_id)
    message += _ZERO_32  # responseTo
    message += struct.pack("<i", operation)
    return (request_id, message + data)
504718
private void fillPacket() throws IOException
    {
        if (_closed)
            return;

        if (_gotFirst||_in.available()==0)
            _getBodyChunk.write(_out);
        _gotFirst=true;

        // read packet
        if (!_packet.read(_in))
            throw new IOException("EOF");

        if (_packet.unconsumedData()<=0)
            _closed=true;
        else if (_packet.getInt()>_packet.getBufferSize())
            throw new IOException("AJP Protocol error");
    }
1058950
def pull(self):
        """"""

        # For each packet in the pcap process the contents
        for item in self.input_stream:

            # Print out the timestamp in UTC
            print('%s -' % item['timestamp'], end='')

            # Transport info
            if item['transport']:
                print(item['transport']['type'], end='')

            # Print out the Packet info
            packet_type = item['packet']['type']
            print(packet_type, end='')
            packet = item['packet']
            if packet_type in ['IP', 'IP6']:
                # Is there domain info?
                if 'src_domain' in packet:
                    print('%s(%s) --> %s(%s)' % (net_utils.inet_to_str(packet['src']), packet['src_domain'],
                                                 net_utils.inet_to_str(packet['dst']), packet['dst_domain']), end='')
                else:
                    print('%s --> %s' % (net_utils.inet_to_str(packet['src']), net_utils.inet_to_str(packet['dst'])), end='')
            else:
                print(str(packet))

            # Only include application if we have it
            if item['application']:
                print('Application: %s' % item['application']['type'], end='')
                print(str(item['application']), end='')

            # Just for newline
            print()
491104
def write(self, data):
        """"""

        report_size = self.packet_size
        if self.ep_out:
            report_size = self.ep_out.wMaxPacketSize

        for _ in range(report_size - len(data)):
            data.append(0)

        self.read_sem.release()

        self.ep_out.write(data)
257201
def _pack(self, content):
        """"""
        if self.serializer:
            content = self.serializer.serialize(content)
        if self.compressor:
            content = self.compressor.compress(content)
        return content
1020421
def set_data(self, data):
        ''' 
        '''
        data = array.array('B', struct.unpack("{}B".format(len(data) * 4), struct.pack("{}I".format(len(data)), *data)))
        self._intf._send_tcp_data(data)
48729
def send_packet(self, packet):
        """"""
        data = json.dumps(packet)
        byte = data.encode('utf-8')
        self.udp_socket.sendto(byte, (self._host, self._udp_port))
158979
def pack(self, value=None):
        
        # Set the correct IHL based on options size
        if self.options:
            self.ihl += int(len(self.options) / 4)

        # Set the correct packet length based on header length and data
        self.length = int(self.ihl * 4 + len(self.data))

        self._version_ihl = self.version << 4 | self.ihl
        self._dscp_ecn = self.dscp << 2 | self.ecn
        self._flags_offset = self.flags << 13 | self.offset

        # Set the checksum field before packing
        self._update_checksum()

        return super().pack()
1050705
def __pack_message(operation, data):
    
    rid = _randint()
    message = _pack_header(16 + len(data), rid, 0, operation)
    return rid, message + data
1199197
def encode(self):
        """"""
        if len(self.data) == 0:
            log.debug("Encoding an empty DAT packet")
        data = self.data
        if not isinstance(self.data, bytes):
            data = self.data.encode('ascii')
        fmt = b"!HH%ds" % len(data)
        self.buffer = struct.pack(fmt,
                                  self.opcode,
                                  self.blocknumber,
                                  data)
        return self
1220544
def packet(self):
        """"""
        if not self.finished:
            self.finished = 1
            for question in self.questions:
                self.write_question(question)
            for answer, time in self.answers:
                self.write_record(answer, time)
            for authority in self.authorities:
                self.write_record(authority, 0)
            for additional in self.additionals:
                self.write_record(additional, 0)

            self.insert_short(0, len(self.additionals))
            self.insert_short(0, len(self.authorities))
            self.insert_short(0, len(self.answers))
            self.insert_short(0, len(self.questions))
            self.insert_short(0, self.flags)
            if self.multicast:
                self.insert_short(0, 0)
            else:
                self.insert_short(0, self.id)
        return b''.join(self.data)
404849
def send_raw_packet(self, packet: str):
        """"""
        data = packet + '\r\n'
        log.debug('writing data: %s', repr(data))
        self.transport.write(data.encode())
556273
def scp(self, local_file, remote_path=''):
        """"""
        if self.args.user:
            upload_spec = '{0}@{1}:{2}'.format(self.args.user,
                                               self.args.server,
                                               remote_path)
        else:
            upload_spec = '{0}:{1}'.format(self.args.server, remote_path)

        return self.sh('scp', local_file, upload_spec)