raw-sockets

Mac + Ruby: Can't access ioctl of Socket? How to fix?

荒凉一梦 提交于 2019-12-05 23:10:29
Good time of day. Ruby Code: def hw_address(iface) sock = Socket.new(Socket::AF_INET, Socket::SOCK_DGRAM,0) buf = [iface,""].pack('a16h16') sock.ioctl(SIOCGIFHWADDR, buf); sock.close return buf[18..24].to_etheraddr end puts hw_address('lo0') What it do: gets mac-address of interface. Works on Debian as expected. But on Mac OS X, im getting error: ``ioctl': Operation not supported on socket (Errno::EOPNOTSUPP)` Is there anyway to fix/pass this error message & get working ioctl on Sockets? http://hintsforums.macworld.com/showthread.php?t=97909 "Following function[s] are not available at Mac OS X

rawsocket sendto() some of the packet are dropped and not seen in the network

▼魔方 西西 提交于 2019-12-05 19:28:31
socketFd_ = socket(AF_INET, SOCK_RAW, protoType); sentBytes = sendto(socketFd_, buf, len, 0, (struct sockaddr *)&sa,sizeof(structsockaddr_in)); protoType = GRE I am sending the 1000 packets in the network. If my tx packet rate is 40, i am able to see all the packet in wireshark. however when i will try to send at the rate of 100 some of the packet(3-4) will not reach in the network however sendto did not return any error. i know sendto will just put the txpacket into the queue and will not guarantee the delivery of packet in the network however from where i can get the drop packet statistics

Unable to read incoming responses using raw sockets

て烟熏妆下的殇ゞ 提交于 2019-12-05 19:11:43
I am trying to read a response from a website via code by listening to a raw socket, though so far I've only been able to read the outgoing requests sent by my computer rather than the incoming responses that I'm actually interested in. How might I go about reading the incoming responses? EDIT: Using Wireshark I've come to find that the data I'm looking for is being sent via TCP, I believe. Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.Unspecified); IPAddress localIP = Dns.GetHostByName(Dns.GetHostName()).AddressList[0]; listener.Bind(new IPEndPoint

How to add a new custom layer 4 protocol (a new Raw socket) in linux kernel?

*爱你&永不变心* 提交于 2019-12-05 13:12:18
i am trying adding my own customized layer 4 protocol in linux (ubuntu 14.04) - IPPROTO_MYPROTO as a loadable kernel module. I have done all necessary steps to register the protocol. Here i am sharing my code. When i am trying to send a mesage from user space program using sendmsg() , i expect the corresponding fn myproto_sendmsg() registered via struct proto structure should be called in kernel space. But what i am observing is that though the myproto_sendmsg() in kernel space is not being called, yet destination machine is receiving the correct data. surprise ! surprise ! . Is the default

How to reproduce TCP protocol 3-way handshake with raw sockets correctly?

房东的猫 提交于 2019-12-04 15:49:50
问题 Im simulating tcp protocol's 3-way handshake in c++, along with wireshark as my code runs. My code crafts the headers at ip and tcp layers, packs them, then send it to an http server with tcp header's SYN flag set to 1. I can see on wireshark the full datagram with both ip and tcp headers ok. Seems to be no errors. My process bind a socket with the same address and port as contained in the already sent packet's header. Wireshark shows packet successfully sent but there isn't any income packet

How to bind a Raw Socket to a specific port?

余生颓废 提交于 2019-12-04 12:53:28
问题 I am currently working on a programming assignment. The assignment is to implement a client,network emulator, and server. The client passes packets to a network emulator, and the network emulator passes to the server. Vice-versa applies as well. The prerequisite for the assignment is that I may only use raw sockets. So I will create my own IP and UDP headers. I have tested my packets with wireshark. They are all correct and in the proper format(it reads them properly). Another requirement is

Connecting a Docker container to a network interface / device instead of an IP address

别等时光非礼了梦想. 提交于 2019-12-04 04:14:35
After careful research, testing, and fiddling, I've only been able to find away to connect a Docker container to a given interface by forwarding from an IP/port. This can be accomplished by adding -p Host-IP:Host-Port:Container-Port to a docker run command. I have an app that listens for UDP broadcasts (255.255.255.255), and have been unable to configure forwarding in such a way that my container will receive those broadcasts without forwarding all network traffic on the port I care about (no matter through which interface it comes in), ie: -p Host-Port:Container-Port . It's possible to

Send a raw ethernet packet from inside a kernel module

穿精又带淫゛_ 提交于 2019-12-03 09:36:46
问题 I found out that I need to build a new sk_buff struct in the kernel module and pass it to my network device, but what I can't figure out is how to set the struct variables for a simple raw ethernet packet. This has to be easy, but I would really appreciate it, if someone could give me a sample code of how to put the sk_buff together. 回答1: Take a look at the function packet_sendmsg_spkt in net/packet/af_packet.c for inspiration. The hard part is getting a struct sock if you don't have a socket

Python TCP stack implementation

a 夏天 提交于 2019-12-03 07:42:19
问题 Is there a python library which implements a standalone TCP stack? I can't use the usual python socket library because I'm receiving a stream of packets over a socket (they are being tunneled to me over this socket). When I receive a TCP SYN packet addressed to a particular port, I'd like to accept the connection (send a syn-ack) and then get the data sent by the other end (ack'ing appropriately). I was hoping there was some sort of TCP stack already written which I could utilize. Any ideas?

Does libpcap use raw sockets underneath them?

痞子三分冷 提交于 2019-12-03 06:47:43
I was getting a bit confused on using of raw sockets and libcap. Can, anyone in simple point out advantages of using both. I read few links, but, its making me confused. "libpcap" and "raw sockets" are different topics. Libpcap is a packet capture library for linux which is used to capture the traffic/packets that pass through a network interface like eth0. On windows the Winpcap library does the same thing. Raw sockets are a feature of the socket api provided by the OS that can be used to send packets with headers defined by the application and not the OS. So using raw sockets we can specify