Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7829579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:50:05+00:00 2026-06-02T10:50:05+00:00

There is a raw socket type provided in Network.Socket, but near binding sockets there

  • 0

There is a raw socket type provided in Network.Socket, but near binding sockets there is a comment “Currently only Unix domain sockets and the Internet families are supported”. How can I use raw sockets in haskell?

What I am trying to achieve, as working Python code:

import binascii
import socket

# Create raw socket.
ethType = b'FFFF' # 2 bytes, has to be >= 0x0600. FFFF is "unavailable" by IEEE.
sock = socket.socket(socket.AF_PACKET, socket.SOCK_RAW)
sock.bind( ('lo', int(ethType,16)) )

# Create packet.
srcMac  = b'000000000000' # 6 bytes
destMac = b'000000000000' # 6 bytes
header = binascii.a2b_hex( destMac + srcMac + ethType ) # 14 bytes
message = b'Hello, World!'
sock.send(header + message)

# Receive such packets
while True: print (sock.recv(65535))

EDIT1:
In Haskell, I use sock <- socket AF_PACKET Raw 0xFFFF to create a socket, but bindSocket requires a SockAddr as an argument, for which available constructors are

SockAddrInet PortNumber HostAddress  
SockAddrInet6 PortNumber FlowInfo HostAddress6 ScopeID   
SockAddrUnix String

but none of these seems right.

EDIT2:
Thanks to a comment by Yuras I got receiving packets to work:

import Network.Socket
sock <- socket AF_PACKET Raw 0xFFFF
recv sock 0xFFFF

EDIT3:
Trying to send a packet from a socket without binding it results in an exception:

sock <- socket AF_PACKET Raw 0xFFFF
send sock "\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\255\255"
*** Exception: send: does not exist (No such device or address)

This makes sense, because the kernel would not have any clue on which interface to actually transmit the packet. Is there any way to bind a (raw) socket to an interface in Haskell?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T10:50:08+00:00Added an answer on June 2, 2026 at 10:50 am

    Network.Pcap can be used to send and receive raw data.

    import qualified Data.ByteString.Char8 as B
    import Network.Pcap
    
    main = do
        -- open device
        dev <- openLive "lo" 65535 False 0
        setFilter dev "ether proto 0xFFFF" True 0
    
        -- send
        sendPacketBS dev (B.pack "\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\255\255Hello, World!")
    
        -- receive
        loopBS dev (-1) (\_ packet -> putStrLn (show packet))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are currently testing a Telecom application over IP. We open a Raw Socket
Is there any silverlight or wpf grid type(ish) controls that take raw xml as
Is there a way to restore an Oracle 11g instance from raw data files
Is there a way/tool to auto convert Java source code from using raw types
I'm investigating encodings in PHP5. Is there some way to get a raw hex
On a Windows PC, is there a way to read the raw bytes from
There seems to be a similar question to this on here but with the
I'm including the netinet headers and doing some raw socket programming on the iPhone,
I setup a raw Packet socket using the following: sockFd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)
Is there a way to locate a TCP Server running under local network using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.