小编Mor*_*sen的帖子

使用ioctl分配ipv6地址

我正在尝试使用ioctl为接口分配IPv6地址,但是徒劳无功.这是我使用的代码:

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>             
#include <net/if.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/sockios.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>

#define IFNAME "eth1"
#define HOST "fec2::22"
#define ifreq_offsetof(x)  offsetof(struct ifreq, x)

int main(int argc, char **argv) {
  struct ifreq ifr;
  struct sockaddr_in6 sai;
  int sockfd;                     /* socket fd we use to manipulate stuff with */
  int selector;
  unsigned char mask;

  char *p;

  /* Create a channel to the NET kernel. */
  sockfd = socket(AF_INET6, SOCK_DGRAM, …
Run Code Online (Sandbox Code Playgroud)

networking ipv6

5
推荐指数
1
解决办法
6077
查看次数

这些代码有什么作用?

我在一本书上看到这个源代码:

#include <stdio.h>
#include <unistd.h>


int main(int argc, char *argv[])
{
    char *delivery = "";
    int thick = 0;
    int count = 0;
    char ch;

    while ((ch = getopt(argc, argv, "d: t")) != EOF)
        switch(ch)
        {
            case 'd':
                delivery = optarg;
                break;

            case 't':
                thick = 1;
                break;

            default:
                fprintf(stderr, "Unknown option: '%s'\n", optarg);
                return 1;
        }

        argc -= optind;
        argv += optind;

        if (thick)
            puts("Thick Crust.");

        if (delivery[0])
            printf("To be deliverd %s\n", delivery);

        puts("Ingredients: ");

        for (count = 0; …
Run Code Online (Sandbox Code Playgroud)

c

5
推荐指数
1
解决办法
5716
查看次数

使用ContentValues将以零开头的字符串编号插入到字符串列中,但始终会删除前导零

我的桌子是用.创建的

db.execSQL(
    "CREATE TABLE periods (" +
    "  vehicle_id INTEGER KEY," +
    "  line_id INTEGER KEY," +
    "  period_id INTEGER PRIMARY KEY AUTOINCREMENT," +
    "  line_code STRING," +
    "  sup_code STRING," +
    "  start_date INTEGER," +
    "  end_date INTEGER" +
    ")"
);
Run Code Online (Sandbox Code Playgroud)

插入数据

ContentValues values = new ContentValues();
values.put("vehicle_id", 1);
values.put("line_id", 2);
values.put("line_code", "0406");
values.put("sup_code", " ");
values.put("start_date", 1);
values.put("end_date", 24);
db.insert("periods", null, values);
Run Code Online (Sandbox Code Playgroud)

但是当我用数据检索数据时

Cursor cPeriods = db.rawQuery("SELECT * FROM periods WHERE vehicle_id=" + vehicleId, null);
System.err.printf("SQLite: ### Get …
Run Code Online (Sandbox Code Playgroud)

java sqlite android

5
推荐指数
1
解决办法
1044
查看次数

无法将图像插入数据库

我在使用基本表单在数据库中插入图像时遇到问题.有两种形式,一种是插入类别(图像和名称),另一种是插入位置(名称,地址,图像等).add_category函数工作正常,它是add_location,没有并且专门插入图像.而且我相信它会插入有问题的图像.

问题是插入图像中的if语句永远不会被执行,我不知道为什么.它位于add_location(..)检查图像if语句下的函数中.

if ($result = $this->mysqli->query($query)) {
    $error['result'] = $this->succAddLoc;
}
Run Code Online (Sandbox Code Playgroud)

我删除了文件中不必要的函数:

<?php 
    class pongodev {
        var $mysqli;

        // Error handling variables
        var $errCatName;
        var $errLatitude;
        var $errLongitude;
        var $errImage;
        var $errPhone;
        var $errWebsite;
        var $succAddLoc;
        var $succAddCat;
        var $errEmail;
        var $errPass;
        var $succPass;
        var $succEmail;
        var $succEmailPass;
        var $succResetPass;
        var $errResetPass;
        var $errUsername;

        // Email configuration variables
        var $emailSubject;
        var $resetMessage;
        var $from;
        var $adminEmail;


        // Connect to database
        function __construct($host, $user, $pass, $database){
            // Connect to …
Run Code Online (Sandbox Code Playgroud)

php mysql database-connection

5
推荐指数
1
解决办法
280
查看次数

指向成员变量的指针

以下程序输出始终为1 1 1.在"C++对象模型内部"一书中,提到它将给出偏移量.目的还在于找出对象布局.但是,我对输出感到困惑.使用g ++ 4.5.2

class Test
{
    public:
        float a;
        float b;
        float c;
};

int main()
{
    float Test::*ptr = &Test::a;
    float Test::*ptr1 = &Test::b;
    float Test::*ptr2 = &Test::c;
    cout<<ptr<<endl;
    cout<<ptr1<<endl;
    cout<<ptr2<<endl;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出:

1
1
1
Run Code Online (Sandbox Code Playgroud)

编辑(跟进问题):在书中提到origin.y = 0可以转换为&origin + (Point3d::y-1)原点是Point3d的对象,y是Point3d类的成员变量.虽然当我编译它时给了我编译错误.

c++

4
推荐指数
2
解决办法
4616
查看次数

pythonic方法按内部列表的最后一项对列表进行排序

我有这样的清单

[[x,y,1],[w,u,4],[m,n,3] ... [p,q,5]]
Run Code Online (Sandbox Code Playgroud)

我需要按内部列表的第三个(最后一个)元素对外部列表进行排序,所需的结果是:

[[x,y,1],[m,n,3],[w,u,4] ... [p,q,5]]
Run Code Online (Sandbox Code Playgroud)

实现这一目标的最佳方法是什么?

python sorting algorithm

3
推荐指数
1
解决办法
126
查看次数

用静态图像替换MKMapView

是否可以显示静态图像而不是默认的MapView,其中当前位置始终是图像的中心?

我想显示中心为当前位置的图像,并根据坐标(距离和方向)在其上添加引脚.我想计算它之间的距离,也许根据手机指向的方向旋转图像/引脚.

我认为MKMapView使用静态图像替换它可能是最容易的,因为我可以使用所有内置功能,但是现在似乎无法将地图更改为静态图像?

我也可以直接在图像上绘画,但是如何工作,我应该这样做吗?我想这将是极坐标的东西.

mkmapview ios ios7

3
推荐指数
2
解决办法
2653
查看次数

双指针问题

我正在尝试制作一个树模板,每个节点上可以有任意数量的子节点.这是我在节点类中的addChild函数的代码 -

template<typename T>
void Tree<T>::Node::addChild(T& value) {
    Node* temp = new Node(value, this); //second parameter is for parent
    numOfChildren++;
    children*[numOfChildren] = temp;
}
Run Code Online (Sandbox Code Playgroud)

而不是有一个左右孩子的指针,我想我应该做一个双指针(指向Node*数组的指针).

节点**儿童;

我不断收到"''令牌"错误之前的"预期主要表达式".我猜我正在错误地访问2D数组?或许我应该以不同的方式去做?如果我只是生孩子,你认为它会起作用吗?

节点*孩子?

如果我只有一个Node*并且每个元素都是不同的节点,我觉得它可能会起作用.

任何帮助表示赞赏.

c++ tree pointers data-structures

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

XML解析器示例

我试图解析以下XML:

<?xml version="1.0" encoding="UTF-8"?>
<!-- _tag -->
<tag value="0" actions_tagged="0" name="adjust temperature">
  <link type="application/xml" rel="list" href="/api/v1/tags.xml"/>
  <link type="application/xml" rel="self" href="/api/v1/tags/adjust%20temperature.xml"/>
  <actions>
    <action id="105">
      <link type="application/xml" rel="tagged_action" href="/api/v1/actions/105.xml"/>
      <short_name>Set thermostat to 68F in the winter and 74F in the summer</short_name>
    </action>
    <action id="106">
      <link type="application/xml" rel="tagged_action" href="/api/v1/actions/106.xml"/>
      <short_name>Close windows and blinds</short_name>
    </action>
  </actions>
</tag>
Run Code Online (Sandbox Code Playgroud)

我想捕获每个"动作ID"和每个"短名称".我可以使用以下代码捕获短名称.但是,您如何获得相应的动作ID?

String action = null;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Actions myActions  = new Actions();
InputSource inStream = new InputSource();
inStream.setCharacterStream(new StringReader(xml));

Document doc …
Run Code Online (Sandbox Code Playgroud)

java xml parsing

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

将MongoDb与Java Servlet一起使用

我在Java servlet上使用Mongo DB时遇到了问题.

我的servlet有很多方法(~20)访问数据库以检索和添加数据.一个非常简短的例子:

public static String getSomething(String s) {
  String json = "[]";
  JSONArray jsonArray = new JSONArray();
  DBCollection table;

  try {
    Mongo mongo = new Mongo("localhost", 27017);
    DB db = mongo.getDB( "myDb" );  
        BasicDBObject quoteQuery = new BasicDBObject("abc", abc);
    DBCursor cursor = table.find(quoteQuery);

    try {
      while(cursor.hasNext()) {
        jsonArray.put(cursor.next());
      }
    } finally {
      cursor.close();
    }

// ...
Run Code Online (Sandbox Code Playgroud)

现在问题是当这个Java servlet部署在linux服务器上时,它可以正常工作10天左右.

之后它崩溃了.

当我去我的var/log目录中的mongodb.log时,我得到以下重复输出:

"因为太多的开放连接而拒绝连接"

我不确定现在在哪里编辑或如何处理这个问题.我试图增加服务器中打开连接的限制,但仍然有相同的结果.

有什么建议?

java servlets mongodb

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