<p>What would be the easiest way to be able to send and receive raw network packets. Do I have to write my own JNI wrapping of some c API, and in that case what API am I looking for?</p>

<p>EDIT: I want to be able to do what wireshark does, i.e. record all incomming packets on an interface, and in addition be able to send back my own created packets. And I want to do it on a mac.</p>

[{'answer_id': 40081, 'author': 'Adam Davis', 'author_id': 2915, 'author_profile': 'https://Stackoverflow.com/users/2915', 'pm_score': 0, 'selected': False, 'text': '<p><a href="http://www.maxim-ic.com/products/microcontrollers/tini/" rel="nofollow noreferrer">TINI</a> is a java ethernet controller, which may have libraries and classes for directly accessing data from ethernet frames to TCP streams. You may be able to find something in there that implements your needed classes. If not, there should be pointers or user groups that will give you a head start.</p>\n'}, {'answer_id': 46480, 'author': 'Joe Liversedge', 'author_id': 4552, 'author_profile': 'https://Stackoverflow.com/users/4552', 'pm_score': 2, 'selected': True, 'text': '<p>If you start with the idea that you need something <em>like</em> a packet sniffer, you\'ll want to look at <a href="http://netresearch.ics.uci.edu/kfujii/jpcap/doc/" rel="nofollow noreferrer">http://netresearch.ics.uci.edu/kfujii/jpcap/doc/</a>.</p>\n'}, {'answer_id': 46538, 'author': 'Marcio Aguiar', 'author_id': 4213, 'author_profile': 'https://Stackoverflow.com/users/4213', 'pm_score': 1, 'selected': False, 'text': '<p>Raw Socket for Java is a request for JDK for a looong long time. See the request <a href="https://bugs.java.com/bugdatabase/view_bug.do?bug_id=4727550" rel="nofollow noreferrer">here</a>. There\'s a long discussion there where you can look for workarounds and solutions. I once needed this for a simple PING operation, but I can\'t remember how I resolved this. Sorry :)</p>\n'}, {'answer_id': 46864, 'author': 'Johan Lübcke', 'author_id': 4220, 'author_profile': 'https://Stackoverflow.com/users/4220', 'pm_score': 1, 'selected': False, 'text': '<p>My best bet so far seems to be the <a href="http://canmore.annwfn.net/freebsd/bpf.html" rel="nofollow noreferrer">BPF</a> api and to write a thin JNI wrapper</p>\n'}, {'answer_id': 114666, 'author': 'Alnitak', 'author_id': 6782, 'author_profile': 'https://Stackoverflow.com/users/6782', 'pm_score': 0, 'selected': False, 'text': '<p>You can\'t access raw sockets from pure Java, so you will need some sort of layer between your Java code and the network interfaces.</p>\n\n<p>Also note that access to raw sockets is normally only available to "root" processes, since otherwise any user could both a) sniff all traffic, and b) generate spoofed packets.</p>\n\n<p>Rather than write your whole program so that it needs to run as "root", you might consider having the packet capture and generation done in a standalone program with some sort of IPC (RMI, named pipe, TCP socket, etc) to exchange the data with your Java app.</p>\n'}]
['https://Stackoverflow.com/questions/40039', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4220/']