title: AttributeError: module 'socket' has no attribute 'AF_PACKET'
body: <p>I am working on building a packet sniffing program using Python, however I have hit a speed bump. For some reason I think socket has not imported properly, because I am getting the following message when my program is run: <code>AttributeError: module 'socket' has no attribute 'AF_PACKET'</code></p>
  
  <p>I am using OS X and Pycharm is my IDE and I am running the latest version of Python if that helps.</p>
  
  <p>Anyways here is my complete program so far:</p>
  
  <pre><code>import struct
  import textwrap
  import socket
  
  def main():
      connection = socket.socket(socket.AF_PACKET, socket.SOCKET_RAW, socket.ntohs(3))
  
      while True:
          rawData, address = connection.recvfrom(65535)
          reciever_mac, sender_mac, ethernetProtocol, data = ethernet_frame(rawData)
          print('\nEthernet Frame: ')
          print('Destination: {}, Source: {}, Protocol: {}'.format(reciever_mac, sender_mac, ethernetProtocol))
  
  # Unpack ethernet frame
  def ethernet_frame(data):
      reciever_mac, sender_mac, protocol = struct.unpack('! 6s 6s H', data[:14])
      return getMacAddress(reciever_mac), getMacAddress(sender_mac), socket.htons(socket), data[14:]
  
  # Convert the Mac address from the jumbled up form from above into human readable format
  def getMacAddress(bytesAddress):
      bytesString = map('{:02x}'.format, bytesAddress)
      macAddress = ':'.join(bytesString).upper()
      return macAddress
  
  main()
  </code></pre>
  
  <p>Thanks for any help in advance!</p>