Skip to content

Instantly share code, notes, and snippets.

@RicardoLara
Last active March 1, 2016 17:49
Show Gist options
  • Save RicardoLara/0a83455dbe37cc934113 to your computer and use it in GitHub Desktop.
Save RicardoLara/0a83455dbe37cc934113 to your computer and use it in GitHub Desktop.
/*
struct sockaddr_ll {
unsigned short sll_family; /* Always AF_PACKET */
//unsigned short sll_protocol; /* Physical layer protocol */
//int sll_ifindex; /* Interface number */
//unsigned short sll_hatype; /* ARP hardware type */
//unsigned char sll_pkttype; /* Packet type */
//unsigned char sll_halen; /* Length of address */
//unsigned char sll_addr[8]; /* Physical layer address */
//}; */
/*
#include <sys/types.h>
#include <sys/socket.h>
int socket(int domain, int type, int protocol);
*/
/*
LO IMPORTANTE Y QUE LEIMOS
SOCK_STREAM(TCP)
AF_INET { }
SOCK_DGRAM(UDP)
SOCK_RAW(Enlace)
AF_PACKET{ }
SOCK_DGRAM(Red)
*/
#include <sys/socket.h>
#include <linux/if_packet.h>
#include <net/ethernet.h>
#include <stdio.h>
//Para Htons
#include <arpa/inet.h>
//Para close
#include <unistd.h>
int main(){
int packet_socket;
packet_socket = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
if(packet_socket == -1) perror("Error en Socket\n");
else perror("Exito al abrirlo, paps\n");
close(packet_socket);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment