A raw socket is a network socket (
AF_INET6 usually). It can be used to create raw IP packages which can be used for troubleshooting or to implement your own TCP implementation without using
Raw sockets allow new IPv4 protocols to be implemented in user space. A raw socket receives or sends the raw datagram not including link level headers. [
nmap use raw sockets in order to stop the TCP handshake after the initial
SYN-ACK, as the TCP connection never completely established. As a network socket, it uses
sockaddr_in for addresses.
However, the creation of raw sockets is usually restricted. Only privileged processes can create them.
A unix socket on the other hand is not a network socket (
AF_UNIX). It's a local socket:
AF_UNIX (also known as
AF_LOCAL) socket family is used to communicate between processes on the same machine efficiently. [
It uses another address structure (
sockaddr_un). It's a common way to implement two-way communication on a single system for inter-process communication without going through the network layer.
And packet sockets are raw packets at the driver level:
Packet sockets are used to receive or send raw packets at the device driver (OSI Layer 2) level. They allow the user to implement protocol modules in user space on top of the physical layer. [
The other sockets act on the network layer (OSI Layer 3) or higher. At that point, you're talking directly to your network interface's driver.
For more information see