小编Kev*_*Kev的帖子

C拼图:printf的输出应始终为"5"

我在C aptitude论文中发现了这个难题.

void change()
{
    //write something in this function so that output of printf in main function
    //should always give 5.you can't change the main function
}

int main()
{
    int i = 5;
    change();
    i = 10;
    printf("%d", i);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

任何解决方案.?

c puzzle

18
推荐指数
9
解决办法
3087
查看次数

Android:使用SimpleCursorAdapter将数据从数据库获取到ListView

我正在编写一个Android应用程序,应该使用数据库来存储数据并从中读取数据.使用本教程(在archive.org上)我得到了创建数据库的应用程序,我可以创建新条目,但是,我不知道,如何读取数据库以获取ListView中存储的数据.我知道这个网站上有很多类似的问题,但似乎没有一个适用于这种方式,教程中的数据库也适用.

码:

import java.util.Calendar;

import maturarbeit.nicola_pfister.studenttools.database.DBAdapter;
import android.app.AlertDialog.Builder;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.ListView;


public class Marks extends ListActivity {

DBAdapter db = new DBAdapter(this);

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.marks);
}

@Override
protected void onPause() {
    super.onPause();
    db.close();
}

@Override
protected void onResume() {
    super.onResume();
    db.open();

    getData();
}

@SuppressWarnings("deprecation")
private void getData() {
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, 
            android.R.layout.simple_list_item_1, 
            db.getAllMarks(), 
            new …
Run Code Online (Sandbox Code Playgroud)

database android listview simplecursoradapter

18
推荐指数
1
解决办法
7万
查看次数

与SOCK_RAW套接字进行TCP握手

好吧,我意识到这种情况有点不寻常,但我需要建立一个TCP连接(3次握手)只使用原始套接字(在C中,在linux中) - 即我需要自己构建IP头和TCP头.我正在写一个服务器(所以我必须先响应传入的SYN数据包),无论出于什么原因我似乎无法正确使用它.是的,我意识到SOCK_STREAM会为我处理这个,但由于我不想进入的原因,这不是一个选择.

我在网上找到的使用原始套接字的教程都描述了如何构建SYN flooder,但这比实际建立TCP连接要容易一些,因为您不必根据原始数据包构建响应.我已经让SYN flooder示例工作了,我可以从原始套接字读取传入的SYN数据包,但是我仍然无法从客户端创建对传入SYN的有效SYN/ACK响应.

那么,有没有人知道使用原始套接字的好教程不仅仅是创建SYN flooder,还是有人有一些代码可以做到这一点(使用SOCK_RAW,而不是SOCK_STREAM)?我会很感激.


MarkR是绝对正确的 - 问题是内核正在发送重置数据包以响应初始数据包,因为它认为端口已关闭.内核正在击败我的响应并且连接终止.我正在使用tcpdump监视连接 - 我本来应该更加敏锐,并注意到有两个回复,其中一个是重置,搞砸了事情,以及我的程序创建的响应.D'OH!

似乎最有效的解决方案是使用MarkR建议的iptables规则来阻止出站数据包.但是,正如建议的那样,使用标记选项比使用标记选项更容易.我只是匹配是否设置了重置TCP标志.在正常连接过程中,这不太可能是需要的,如果我阻止来自正在使用的端口的所有出站重置数据包,对我的应用程序来说并不重要.这有效地阻止了内核的不需要的响应,但不是我自己的数据包.如果我的程序正在侦听的端口是9999,那么iptables规则如下所示:

iptables -t filter -I OUTPUT -p tcp --sport 9999 --tcp-flags RST RST -j DROP
Run Code Online (Sandbox Code Playgroud)

linux network-programming

17
推荐指数
2
解决办法
1万
查看次数

我正确使用PHP的crypt()函数吗?

我一直在使用PHP crypt()作为在我的数据库中存储和验证密码的方法.我对其他东西使用散列,但是crypt()对于密码.文档不是很好,似乎有很多争论.我正在使用河豚和两种盐来加密密码并将其存储在数据库中.在我存储salt和加密密码之前(如盐腌哈希)但实现了它的冗余,因为salt是加密密码字符串的一部分.

我对彩虹表攻击如何工作有点困惑crypt(),无论如何从安全的角度来看这看起来是正确的.我使用第二个盐来附加密码以增加短密码的熵,可能是矫枉过正,但为什么不呢?

function crypt_password($password) {
if ($password) {
    //find the longest valid salt allowed by server
    $max_salt = CRYPT_SALT_LENGTH;

    //blowfish hashing with a salt as follows: "$2a$", a two digit cost parameter, "$", and 22 base 64
    $blowfish = '$2a$10$';

    //get the longest salt, could set to 22 crypt ignores extra data
    $salt = get_salt ( $max_salt );

    //get a second salt to strengthen password
    $salt2 = get_salt ( 30 ); //set to whatever …
Run Code Online (Sandbox Code Playgroud)

php security encryption hash salt

17
推荐指数
2
解决办法
2万
查看次数

为什么谷歌Chrome的脚本调试器不允许我设置断点?

我在Windows 7 x64 Ultimate上运行Google Chrome 8.0.552.215.我有一个简单的jQuery内联脚本,就像我过去成功调试的那样:

<script type="text/javascript">
  $(document).ready(function () {
    // do stuff here
    // but reduced to a simple
    alert('here!');
  });
</script>
Run Code Online (Sandbox Code Playgroud)

我正在浏览我正在处理的网站的安全(https)部分.

没有脚本错误,脚本都运行得很好,但我不能设置断点.

我尝试在Firefox的Firebug中调试它,并且可以设置和命中断点.

为什么会这样?

javascript debugging scripting jquery google-chrome

17
推荐指数
2
解决办法
1万
查看次数

如何在python中使用str.format()和字典?

这段代码有什么问题?

dic = { 'fruit': 'apple', 'place':'table' }
test = "I have one {fruit} on the {place}.".format(dic)
print(test)

>>> KeyError: 'fruit'
Run Code Online (Sandbox Code Playgroud)

python dictionary

17
推荐指数
2
解决办法
9304
查看次数

如何在没有错误的情况下退出X11程序

在问题结束时,我在X11中有一个相当简单的"Hello World".但是当它退出时,我得到下面的运行时错误消息:

$ ./xtest
XIO:  fatal IO error 11 (Resource temporarily unavailable) on X server ":0"
      after 9 requests (7 known processed) with 0 events remaining.
Run Code Online (Sandbox Code Playgroud)

所以我试着处理wmDeleteMessage自己,我能够阻止窗口关闭,所以我知道我正确地得到了这个事件.比我添加了一个XDestroyWindow()事件处理,我得到了新的错误.

X Error of failed request:  BadWindow (invalid Window parameter)
  Major opcode of failed request:  4 (X_DestroyWindow)
  Resource id in failed request:  0x130
  Serial number of failed request:  12
  Current serial number in output stream:  12
Run Code Online (Sandbox Code Playgroud)

听起来我正试图摧毁已经被摧毁的窗口,但是如果我把XDestroyWindow()它取出它在我的屏幕上保持活着.

下面是我的代码,试图破坏窗口处理程序.如何在没有任何错误的情况下退出?

#include<X11/Xlib.h>
#include <iostream>

int main()
{
  Display *display;
    if(!(display=XOpenDisplay(NULL))) 
    { …
Run Code Online (Sandbox Code Playgroud)

c++ linux x11 xlib

17
推荐指数
1
解决办法
7336
查看次数

如何使用命令提示符运行现有的Windows 7任务

我在Windows 7任务调度程序中创建了一个任务.

如何使用命令提示符运行它?

command-line scheduled-tasks windows-7

17
推荐指数
1
解决办法
4万
查看次数

如何为JAX-WS WebService调用设置超时

我正在使用WebService Client,我想为我的WebService调用设置一个Timeout.我尝试了不同的方法,但我仍然无法做到这一点.我正在使用JAX-WS从WSDL生成代码.我使用JBoss-eap-5.1作为App Server和JDK1.6.0_27.我发现这些差异方法用于设置超时,但它们都不适用于我.

URL mbr_service_url = new URL(null,GlobalVars.MemberService_WSDL, new URLStreamHandler() {

            @Override
            protected URLConnection openConnection(URL url) throws IOException {
                URL clone_url = new URL(url.toString());
                HttpURLConnection clone_urlconnection = (HttpURLConnection) clone_url.openConnection();
                // TimeOut settings
                clone_urlconnection.setConnectTimeout(10000);
                clone_urlconnection.setReadTimeout(10000);
                return (clone_urlconnection);
            }
        });
        MemberService service = new MemberService(mbr_service_url);
        MemberPortType soap = service.getMemberPort();
        ObjectFactory factory = new ObjectFactory();
        MemberEligibilityWithEnrollmentSourceRequest request = factory.createMemberEligibilityWithEnrollmentSourceRequest();

        request.setMemberId(GlobalVars.MemberId);
        request.setEligibilityDate(value);

        ((BindingProvider) soap).getRequestContext().put(com.sun.xml.ws.client.BindingProviderProperties.REQUEST_TIMEOUT, 10000);
        ((BindingProvider) soap).getRequestContext().put(com.sun.xml.ws.client.BindingProviderProperties.CONNECT_TIMEOUT, 10000);
        ((BindingProvider) soap).getRequestContext().put(com.sun.xml.internal.ws.client.BindingProviderProperties.REQUEST_TIMEOUT, 10000);
        ((BindingProvider) soap).getRequestContext().put(com.sun.xml.internal.ws.client.BindingProviderProperties.CONNECT_TIMEOUT, 10000);
        ((BindingProvider) soap).getRequestContext().put(com.sun.xml.ws.developer.JAXWSProperties.REQUEST_TIMEOUT, 10000);
        ((BindingProvider) soap).getRequestContext().put(com.sun.xml.ws.developer.JAXWSProperties.CONNECT_TIMEOUT, 10000);
        ((BindingProvider) soap).getRequestContext().put(com.sun.xml.internal.ws.developer.JAXWSProperties.REQUEST_TIMEOUT, 10000);
        ((BindingProvider) …
Run Code Online (Sandbox Code Playgroud)

java jboss web-services jax-ws java-ee

17
推荐指数
3
解决办法
7万
查看次数

IIS上的MSSQL和PHP 5.3.5之间的连接不起作用

我最近安装了IIS,PHP 5.3.5和MySQL,并且一切正常.

然后我也要求MS SQL,我认为这将是一件容易的事,现在让我发疯,我无法弄清楚如何使它工作.

根据php_info()MS SQL驱动程序未加载.

我下载php_mssql.dll并启用了它,php.ini但它没有用.我发现新版本的PHP使用了不同的dll.所以我下载了新的,把它放在ext文件夹中,并更新了php.ini,但仍然没有运气.

php_info() 仍然没有显示驱动程序已加载.

我即将卸载IIS和PHP,并安装我之前安装过的Apache.

这个问题是我的最后一次尝试,有人可以帮忙吗?

php sql-server iis dll

16
推荐指数
1
解决办法
4万
查看次数