raw-sockets

Packet socket in promiscuous mode only receiving local traffic

孤人 提交于 2019-11-30 18:49:59
问题 I have a socket created with socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)) , and I've set it into promiscuous mode using: struct ifreq ifr; strncpy((char*)ifr.ifr_name, interface, IF_NAMESIZE); if(ioctl(sock, SIOCGIFINDEX, &ifr)<0) fail(2); struct packet_mreq mr; memset(&mr, 0, sizeof(mr)); mr.mr_ifindex = ifr.ifr_ifindex; mr.mr_type = PACKET_MR_PROMISC; if(setsockopt(sock, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mr, sizeof(mr)) < 0) fail(2); The problem is that when I do a read() from the socket

Raw Socket Help: Why UDP packets created by raw sockets are not being received by kernel UDP?

老子叫甜甜 提交于 2019-11-30 14:45:59
I am studying raw sockets. I used the IP_HDRINCL option to build my own IP headers. After the IP header, I am building a UDP header. Then I am sending the packet to my system's loopback address. I have another program running which will catch the UDP packets as they come. To check whether the packets are being correctly formed and received, I have another process running which is reading raw IP datagrams. My problem is that although the second process(reading raw datagrams) is working well(all the IP and UDP fields seem to be okay), but the first process(receiving UDP) is not receiving any of

Use raw sockets in Go

試著忘記壹切 提交于 2019-11-30 10:01:27
I'm trying to write a program that receives DHCP discoveries (UDP) and forwards them on to a given IP address using a different source IP address depending on the content of a specific field (GIADDR) in the DHCP packet. I could get working the receiving and sending bit but I'm having an issue with using as IP source address anything that is not a configured IP address on the local machine. I believe that this can only be done using Raw sockets; is that true ? Are there any examples out there on how to do that in Go ? I've spent a couple of days looking around but could not find much. Cheers,

Timestamp outgoing packets

心不动则不痛 提交于 2019-11-30 02:25:06
I'm trying to get accurate timestamps for outgoing packets (sent using raw sockets). According to Linux/Documentation/networking/timestamping.txt , "For send time stamps the outgoing packet is looped back to the socket's error queue with the send time stamp(s) attached. It can be received with recvmsg(flags=MSG_ERRQUEUE).". Unfortunately, recvmsg is always returning -1 when called on a raw socket (created with socket(PF_INET, SOCK_RAW, IPPROTO_RAW) and with SO_TIMESTAMP set to 1 with setsockopt ). What am I doing wrong? Is there a better way of getting an accurate timestamp for an outgoing

Raw socket with device bind using setsockopt() system is not working in Fedora core 6(2.6.18-1.2798.fc6)

て烟熏妆下的殇ゞ 提交于 2019-11-29 08:04:54
Please any one could help on this issue. Please In the below sample code,we had bind raw sock with eth0. but while running the program the recvfrom of raw sock is receiving packets from eth0 & eth1 on same machine(xx_86). It is not clear to me why,could help one on this issue. I hope the setsockopt is not working properly OS: Fedora core 6(2.6.18-1.2798.fc6) Sampe code: #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <unistd.h> #include <sys/socket.h> #include <netinet/in.h> #include <linux/if_ether.h> #include <net/if.h> #include <linux/filter.h> #include <sys/ioctl.h>

C Programming TCP Checksum

試著忘記壹切 提交于 2019-11-28 11:25:20
I have been having trouble doing the checksum for TCP for several days now. I have looked at many sources on the Internet but none of the examples that I have seen show you how to do the TCP checksum. I have also looked at the RFC document and still I am having trouble: Below is the code I am using to generate the checksum: unsigned short checksum(unsigned short * buffer, int bytes) { unsigned long sum = 0; unsigned short answer = 0; int i = bytes; while(i>0) { sum+=*buffer; buffer+=1; i-=2; } sum = (sum >> 16) + (sum & htonl(0x0000ffff)); sum += (sum >> 16); return ~sum; } This function works

Extract received data in a tcp socket in Python

女生的网名这么多〃 提交于 2019-11-28 07:11:54
问题 I have a client sending a packet with a custom layer "Reservation" created with Scapy Client.py #!/usr/bin/env python import socket from scapy.all import * class Reservation(Packet): name = "ReservationPacket" fields_desc=[ ShortField("id", 0), BitField("type",None, 0), X3BytesField("update", 0), ByteField("rssiap", 0)] pkt = IP(len=16384, src='192.168.240.5', dst='192.168.240.198', id=RandShort(), ttl=2)/TCP(sport=5005, dport=5005, flags="S", window=200, options=[('MSS', 1460), ('WScale', 2)

Using raw sockets with C#

拜拜、爱过 提交于 2019-11-27 16:16:20
问题 I want to write a port scanner in C# and I can't use SocketType.Raw as raw sockets were taken out from desktop versions of windows. I can't use SharpPcap either or other wrapper for Winpcap as I use PPPoE for internet connection and Winpcap doesn't support PPP devices. I need to use a library which implements raw sockets and doesn't rely on winpcap. Any ideas? Basically I need to send SYN, receive SYN/ACK or RST but don't send ACK back. edit: For people who doesn't believe RAW sockets are

how to bind raw socket to specific interface

做~自己de王妃 提交于 2019-11-27 06:45:15
My application is running on CentOS 5.5. I'm using raw socket to send data: sd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW); if (sd < 0) { // Error } const int opt_on = 1; rc = setsockopt(m_SocketDescriptor, IPPROTO_IP, IP_HDRINCL, &opt_on, sizeof(opt_on)); if (rc < 0) { close(sd); // Error } struct sockaddr_in sin; memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; sin.sin_addr.s_addr = my_ip_address; if (sendto(m_SocketDescriptor, DataBuffer, (size_t)TotalSize, 0, (struct sockaddr *)&sin, sizeof(struct sockaddr)) < 0) { close(sd); // Error } How can I bind this socket to specific network

C Programming TCP Checksum

和自甴很熟 提交于 2019-11-27 06:20:29
问题 I have been having trouble doing the checksum for TCP for several days now. I have looked at many sources on the Internet but none of the examples that I have seen show you how to do the TCP checksum. I have also looked at the RFC document and still I am having trouble: Below is the code I am using to generate the checksum: unsigned short checksum(unsigned short * buffer, int bytes) { unsigned long sum = 0; unsigned short answer = 0; int i = bytes; while(i>0) { sum+=*buffer; buffer+=1; i-=2;