sending ethernet data along with ARP protocol to automobile gateway in Python
Question: I have programmed in python, where an Array of Bytes will be send to activate
a a protocol feature in the automobile Gateway. Basically I am building a
lower Level ISO-OSI structure which sends a packet of Ethernet layer along
with the ARP protocol structure. I have connected the Raspberry pi 2 to a
Gateway via an Ethernet LAN cable. I am using an API in Raspberry to run the
code. I am using python 3 to compile.

    
    
    #start of program
    
    from socket import *
    
     def sendeth(ethernet_packet,payload,interface = "eth0"):
        """Sending RAW Ethernet packets with ARP protocol."""
    
        s= socket(AF_PACKET, SOCK_RAW)
    
        s.bind((interface,0))
        return s.send(ethernet_packet + payload)
    
    def pack(byte_sequence):
        """convert list of bytes to byte string"""
        return b"".join(map(chr, byte_sequence))
    
    
    if __name__ == "__main__":
    #desadd,srcadd,ethtype    
           ethernet_packet= [0x00, 0x36, 0xf8, 0x00, 0x5b, 0xed, 0xb8, 0x27,   0xcb, 0x8c, 0x1c, 0xf9, 0x08, 0x06]  
    
    #arpprotocol
           arp_packet = [0x00, 0x01, 0x08, 0x00, 0x06, 0x04, 0x00, 0x01, 0xf0, 0x1f, 0xaf, 0x57, 0x33, 0xb1, 0xa9, 0xfe, 0x00, 0x14, 0x00, 0x36, 0xf8, 0x00, 0x5b, 0xed, 0xa9, 0xfe, 0x3f, 0x29] 
    
       payload = "".join(map(chr, arp_packet))
    
    r = sendeth(pack(ethernet_packet),
                pack(arp_packet))
    printf("sent Etherent with ARP_Paket payload length is %d bytes" % r)
    

When I run the program in my raspberry PI

    
    
    $sudo python3 APR.py    
    

it throws an error,

    
    
    Traceback (most recent call test):  
    File"APR.py", line 24,in <module>  
    r = sendeth(pack(ethernet_packet),  
    File"APR.py", line 13,in pack  
    return b"".join(map(chr, byte_sequence))  
    TypeError: sequence intem 0: expected Bytes, bytearray, or an object with   the buffer Interface, str found.
    

I have tried my Level best in Google and Wikipedia for this plausible error,
but wasn't able to find any. I am just a month old in Python. So any leads or
help on this issue would be helpful and handy.

_Probable solution_

Since I am using python 3, it throws up an error. Where as in Python 2 its
perfectlf fine. May be in python 3 I am not able to send the hexa decimal as
strings!! If if this is the Problem can someone help me how to overcome the
error.


Answer: Your pack() function does not work, as the `chr` function return `str` but not
a byte string. See [chr() equivalent returning a bytes object, in
py3k](http://stackoverflow.com/questions/4523505/chr-equivalent-returning-a-
bytes-object-in-py3k) for possible solutions.

In your case, the easiest solution is to use `bytearray` directly:

    
    
    r = sendeth(bytearray(ethernet_packet),
            bytearrayarp_packet))
    

