Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
话题锁定
该话题已被锁定 - littledeer1974 , 2005-11-21 08:10
如果您尚不清楚该话题被锁定的原因,请参考论坛规则以及本版公告或者联系本版版主。
作者 Re:java如何伪造ip发出去? [Re:snooopy]
anatoranato





发贴: 16
积分: 2
于 2005-11-19 05:26 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
以前上大学学上计算机网络客时,老师就给出过这么一个编程题.因为我对JAVA比较熟,所以首先想到的就是用JAVA来实现IP期骗.但是我在JDK的文档中找到这样的话:
Duke icon
Socket Options in Java
The C way
Programming in C, one sets options by using a system call along the lines of:

  setsockopt(int fd, int level, int optval, void *optdata,
     int optdatalen);

  fd = already opened (possibly connected) socket fd;
  level = level in the protocol stack (IP, UDP, TCP) where
   the option applies;
  optval = the option, a CONSTANT;
  optdata = ptr to option dependent struct of parameters relevant
   only to a particular option;

In java
The C way of setting options lacks the type-safety of object-oriented programming. The option one wishes to set/get is identified by an int, and the value to set/get into is an opaque void*. It is all too easy to pass the wrong option identifier, the wrong type object in the void* parameter, or the wrong for that parameter. Worse still, the code for these errors will typically compile, and the error will only be manifested at runtime.

Java now provides a type-safe way to set options. Each socket class has a get/set method for each option it supports, taking and returning the appropriate type. The options supported, for which socket classes and their meaning in brief:

* TCP_NODELAY
o Disable Nagle's algorithm.
o Valid for (client) Sockets.
* SO_LINGER
o Specify a linger-on-close timeout.
o Valid for (client) Sockets.
* SO_TIMEOUT
o Specify a timeout on blocking socket operations. (Don't block forever!
o Valid for all sockets: Socket, ServerSocket, DatagramSocket.
* SO_BINDADDR
o Fetch the local address binding of a socket.
o Valid for Socket, ServerSocket, DatagramSocket.
* SO_REUSEADDR
o Enable reuse address for a socket.
o Valid for Socket, ServerSocket, DatagramSocket.
* SO_BROADCAST
o Enables a socket to send broadcast messages.
o Valid for DatagramSocket.
* SO_SNDBUF
o Set a hint the size of the underlying buffers for outgoing network I/O.
o Valid for all sockets: Socket, ServerSocket, DatagramSocket.
* SO_RCVBUF
o Get the size of the buffer actually used by the platform when receiving in data on this socket.
o Valid for all sockets: Socket, ServerSocket, DatagramSocket.
* SO_KEEPALIVE
o Turn on socket keepalive.
o Valid for Socket.
* SO_OOBINLINE
o Enable inline reception of TCP urgent data.
o Valid for Socket.
* IP_MULTICAST_IF
o Specify the outgoing interface for multicast packets (on multihomed hosts).
o Valid for MulticastSockets.
* IP_MULTICAST_LOOP
o Enables or disables local loopback of multicast datagrams.
o Valid for MulticastSocket.
* IP_TOS
o Sets the type-of-service or traffic class field in the IP header for a TCP or UDP socket.
o Valid for Socket, DatagramSocket

Fell by the wayside...
Some possible BSD options that are not supported in java:

* RAW/ICMP SOCKETS:
The main argument in favor of this one seemed to be so people could write "ping" in java. Security nightmare. Must be root on UNIX machines.


The implementation details...
...that you don't need to know, unless you subclass SocketImpl/DatagramSocketImpl. Every *Socket object has an underlying SocketImpl/DatagramSocketImpl that interfaces to native code. The Impl classes implement two methods to support options:

  void setOption(int optID, Object val) throws SocketException;
  Object getOption(int optID) throws SocketException;

that look much like C. These methods act as glue to the native methods, and ensure type safety before native methods are invoked.
而RAWSOCKET正是我们想要的.通过它我们可以截获所有的IP包,并且可以定制IP包,当然就可定制一个发送方地址非本地址的IP包了.JAVA出于安全考虑没有提供这个支持,但是如果非要做,你可以用JNI将对RAWSOCKET的支持封装成JAVA的类来用.不过那样也没多在意义了.




庆祝CJSDN成立7周年

话题树型展开
人气 标题 作者 字数 发贴时间
10037 java如何伪造ip发出去? snooopy 194 2005-11-16 00:16
8385 Re:java如何伪造ip发出去? ranchgirl 580 2005-11-16 02:37
8288 Re:java如何伪造ip发出去? ranchgirl 276 2005-11-16 02:48
8261 Re:java如何伪造ip发出去? snooopy 200 2005-11-16 14:04
9739 Re:java如何伪造ip发出去? bluecrystal 112 2005-11-17 09:22
8211 Re:java如何伪造ip发出去? snooopy 107 2005-11-18 22:52
8200 Re:java如何伪造ip发出去? ranchgirl 222 2005-11-19 02:37
11633 Re:java如何伪造ip发出去? anatoranato 4015 2005-11-19 05:26

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923